crud
crud copied to clipboard
[Question] How to use unix epoch as format for dates?
Hi,
I have a few entities with attributes of time Date(). I would like to handle all of my date objects on Unix epoch format, I was wondering what is the best way to do that.
For the output of the requests I have an interceptor on the output of controllers, which checks the type of every attribute, and if it detects a date converts to unix epoch.
But I am not sure on how to change the format for the input of the controllers (this is the body of a POST, PATCH, etc) Right now I am doing that conversion manually. Also I am not sure on how to convert the attributes passed to filters. I would like for filter=event.date::gt::1584018000000
to work.
So, what would be the best way to use unix epochs with the crud controllers?
Thanks for reading,
You can use TypeORM column transformer:
transformer: { from(value: DatabaseType): EntityType, to(value: EntityType): DatabaseType }
or maybe just timestamp
column type?
Thanks for answering, sorry for the delay,
I think that transformer and interceptors allow me to deal with most of the cases, but it does not seem to deal with the query parameters... It might be an issue with how typeorm applies the transformers before executing the query builder, I need to look into it a bit more...
The timestamp column type didn't seem to make a difference though...
I also met your problem ~ it seems that there is no good way at present.