relation-mock.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // expected data see below
  7. // commandToChannelMap: {
  8. // create: ['srv', 'admin'],
  9. // search: ['admin'],
  10. // }
  11. interface PermittedChannelsForEachCommand {
  12. channelsObject: { [command: string]: string[] }
  13. }
  14. @Entity()
  15. @Index(['installation', 'growiUri'], { unique: true })
  16. export class RelationMock {
  17. @PrimaryGeneratedColumn()
  18. readonly id: number;
  19. @CreateDateColumn()
  20. readonly createdAt: Date;
  21. @UpdateDateColumn()
  22. readonly updatedAt: Date;
  23. @ManyToOne(() => Installation)
  24. readonly installation: Installation;
  25. @Column()
  26. @Index({ unique: true })
  27. tokenGtoP: string;
  28. @Column()
  29. @Index()
  30. tokenPtoG: string;
  31. @Column()
  32. growiUri: string;
  33. @Column('simple-array')
  34. supportedCommandsForBroadcastUse: string[];
  35. @Column('simple-array')
  36. supportedCommandsForSingleUse: string[];
  37. @Column({ type: 'json' })
  38. permittedChannelsForEachCommand : PermittedChannelsForEachCommand
  39. @CreateDateColumn()
  40. expiredAtCommands: Date;
  41. isExpiredCommands():boolean {
  42. const now = Date.now();
  43. return this.expiredAtCommands.getTime() < now;
  44. }
  45. getDistanceInMillisecondsToExpiredAt(baseDate:Date):number {
  46. return differenceInMilliseconds(this.expiredAtCommands, baseDate);
  47. }
  48. }