SavedItemHttpMapper.ts 1.2 KB

123456789101112131415161718192021222324252627
  1. import { MapperInterface } from '@standardnotes/domain-core'
  2. import { TimerInterface } from '@standardnotes/time'
  3. import { Item } from '../../Domain/Item/Item'
  4. import { SavedItemHttpRepresentation } from './SavedItemHttpRepresentation'
  5. export class SavedItemHttpMapper implements MapperInterface<Item, SavedItemHttpRepresentation> {
  6. constructor(private timer: TimerInterface) {}
  7. toDomain(_projection: SavedItemHttpRepresentation): Item {
  8. throw new Error('Mapping from http representation to domain is not implemented.')
  9. }
  10. toProjection(domain: Item): SavedItemHttpRepresentation {
  11. return {
  12. uuid: domain.id.toString(),
  13. duplicate_of: domain.props.duplicateOf ? domain.props.duplicateOf.value : null,
  14. content_type: domain.props.contentType.value as string,
  15. auth_hash: domain.props.authHash,
  16. deleted: !!domain.props.deleted,
  17. created_at: this.timer.convertMicrosecondsToStringDate(domain.props.timestamps.createdAt),
  18. created_at_timestamp: domain.props.timestamps.createdAt,
  19. updated_at: this.timer.convertMicrosecondsToStringDate(domain.props.timestamps.updatedAt),
  20. updated_at_timestamp: domain.props.timestamps.updatedAt,
  21. }
  22. }
  23. }