import { Transform } from "class-transformer"; export const TransformDate = ()=> { const toPlain = Transform(({ value }) => (value == undefined || !(typeof value.toISOString === "function") ? undefined : (value as Date).toISOString()), { toPlainOnly: true, }); // TODO we should through errors when transforming unanticipated values const toClass = Transform(({value}) => value != undefined && typeof value === "string" ? new Date(value) : undefined, { toClassOnly: true, }); return function (target: any, key: string) { toPlain(target, key); toClass(target, key); }; }