import { Attribute , AutoGenerateAttribute , AUTO_GENERATE_ATTRIBUTE_STRATEGY , Entity , INDEX_TYPE , TransformFromDynamo , TransformToDynamo , } from '@typedorm/common' ; import { table } from './table' ; import moment from 'moment' ; import { Moment } from 'moment' ; export enum CATEGORY { PETS = 'PETS' , KIDS = 'KIDS' } export interface PhotoPrimaryKey { category : CATEGORY ; id : number ; } @ Entity ( { table , name : 'photo' , primaryKey : { partitionKey : 'PHOTO#{{category}}' , sortKey : 'PHOTO#{{id}}' , } , indexes : { GSI1 : { partitionKey : 'PHOTO#{{id}}' , sortKey : 'PHOTO#{{category}}' , type : INDEX_TYPE . GSI , } , } , } ) export class Photo implements PhotoPrimaryKey { @ AutoGenerateAttribute ( { strategy : AUTO_GENERATE_ATTRIBUTE_STRATEGY . UUID4 , } ) id : number ; @ Attribute ( ) @ TransformToDynamo ( ( { value } ) => { if ( value === CATEGORY . KIDS ) { return 'kids-new' ; } else { return value ; } } ) category : CATEGORY ; @ Attribute ( ) name : string ; @ Attribute ( { default : ( ) => new Date ( ) . toISOString ( ) , } ) @ TransformToDynamo ( ( { value } ) => moment ( value , moment . ISO_8601 ) . utc ( ) . format ( 'yyyy-MM-DD' ) ) @ TransformFromDynamo ( ( { value } ) => moment ( value , 'yyyy-MM-DD' ) ) createdAt : Moment ; constructor ( category , name ) { this . name = name ; this . category = category ; } @ AutoGenerateAttribute ( { strategy : AUTO_GENERATE_ATTRIBUTE_STRATEGY . EPOCH_DATE , autoUpdate : true , } ) @ TransformToDynamo ( ( { value } ) => { return value . toString ( ) ; } ) updatedAt : Date ; createdDate ( ) { return this . createdAt . format ( 'MM-DD-YYYY' ) ; } }