relation.ts 1.2 KB

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