relation-mock.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import {
  2. Column, CreateDateColumn, Entity, PrimaryGeneratedColumn, UpdateDateColumn, ManyToOne, Index,
  3. } from 'typeorm';
  4. import { differenceInMilliseconds } from 'date-fns';
  5. import { Installation } from './installation';
  6. interface PermissionSettingsInterface {
  7. [commandName: string]: boolean | string[],
  8. }
  9. @Entity()
  10. @Index(['installation', 'growiUri'], { unique: true })
  11. export class RelationMock {
  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. @CreateDateColumn()
  33. expiredAtCommands: Date;
  34. isExpiredCommands():boolean {
  35. const now = Date.now();
  36. return this.expiredAtCommands.getTime() < now;
  37. }
  38. getDistanceInMillisecondsToExpiredAt(baseDate:Date):number {
  39. return differenceInMilliseconds(this.expiredAtCommands, baseDate);
  40. }
  41. }