How to map to timestamp when return data from database using nestjs and graphql

How to map to timestamp when return data from database using nestjs and graphql


0

I use nestjs and graphql save data into postgres.
When i save data it save success on my database. Here dto input

@InputType()
export class CreateShop {
  //some field


  @Field(() => String, { name: 'opening_time' })
  openingTime?: Timestamp;

  @Field(() => String, { name: 'closing_time' })
  closingTime?: Timestamp;

}

My data save success on database but when i get data with openingTime field and closingTime field it cannot parse to timestamp.

Here my response dto

@ObjectType()
export class CreateShopResponse {
  @Field(() => GraphQLISODateTime)
  opening_time: Date;
  @Field( () => GraphQLISODateTime)
  closing_time: Date;
}

When i get data it throw me error :

"Error: Expected `DateTime.serialize("2023-10-10 10:10:10")` to return non-nullable value, returned: null",

When i change opening_time and closing_time to String on CreateShopResponse it return success.
I have a question : How to convert. timestamp from database to nestjs + graphql using type timestamp.
Note : openingTime and closingTime on database when save success have type look like :
2023-10-10 17:30:30.000 +0700

Share


Load 5 more related questions


Show fewer related questions

0

Reset to default



Leave a Reply

Your email address will not be published. Required fields are marked *