relation.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { differenceInMilliseconds } from 'date-fns/differenceInMilliseconds';
  2. import {
  3. Column,
  4. CreateDateColumn,
  5. Entity,
  6. Index,
  7. ManyToOne,
  8. PrimaryGeneratedColumn,
  9. UpdateDateColumn,
  10. } from 'typeorm';
  11. import { Installation } from './installation';
  12. export interface PermissionSettingsInterface {
  13. [commandName: string]: boolean | string[];
  14. }
  15. @Entity()
  16. @Index(['installation', 'growiUri'], { unique: true })
  17. export class Relation {
  18. @PrimaryGeneratedColumn()
  19. readonly id: number;
  20. @CreateDateColumn()
  21. readonly createdAt: Date;
  22. @UpdateDateColumn()
  23. readonly updatedAt: Date;
  24. @ManyToOne(() => Installation)
  25. readonly installation: Installation;
  26. @Column()
  27. @Index({ unique: true })
  28. tokenGtoP: string;
  29. @Column()
  30. @Index()
  31. tokenPtoG: string;
  32. @Column()
  33. growiUri: string;
  34. @Column({ type: 'json' })
  35. permissionsForBroadcastUseCommands: PermissionSettingsInterface;
  36. @Column({ type: 'json' })
  37. permissionsForSingleUseCommands: PermissionSettingsInterface;
  38. @Column({ type: 'timestamp' })
  39. expiredAtCommands: Date;
  40. getDistanceInMillisecondsToExpiredAt(baseDate: Date): number {
  41. return differenceInMilliseconds(this.expiredAtCommands, baseDate);
  42. }
  43. }