ItemProjector.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { TimerInterface } from '@standardnotes/time'
  2. import { ProjectorInterface } from './ProjectorInterface'
  3. import { Item } from '../Domain/Item/Item'
  4. import { ItemProjection } from './ItemProjection'
  5. import { ItemProjectionWithUser } from './ItemProjectionWithUser'
  6. export class ItemProjector implements ProjectorInterface<Item, ItemProjection> {
  7. constructor(private timer: TimerInterface) {}
  8. async projectSimple(_item: Item): Promise<ItemProjection> {
  9. throw Error('not implemented')
  10. }
  11. async projectCustom(_projectionType: string, item: Item): Promise<ItemProjectionWithUser> {
  12. const fullProjection = await this.projectFull(item)
  13. return {
  14. ...fullProjection,
  15. user_uuid: item.userUuid,
  16. }
  17. }
  18. async projectFull(item: Item): Promise<ItemProjection> {
  19. return {
  20. uuid: item.uuid,
  21. items_key_id: item.itemsKeyId,
  22. duplicate_of: item.duplicateOf,
  23. enc_item_key: item.encItemKey,
  24. content: item.content,
  25. content_type: item.contentType as string,
  26. auth_hash: item.authHash,
  27. deleted: !!item.deleted,
  28. created_at: this.timer.convertMicrosecondsToStringDate(item.createdAtTimestamp),
  29. created_at_timestamp: item.createdAtTimestamp,
  30. updated_at: this.timer.convertMicrosecondsToStringDate(item.updatedAtTimestamp),
  31. updated_at_timestamp: item.updatedAtTimestamp,
  32. updated_with_session: item.updatedWithSession,
  33. }
  34. }
  35. }