nestjs-api-tools
Version:
Wrappers for convenient API development including validation, logging and i18n wrappers
15 lines (12 loc) • 523 B
text/typescript
import {DateTime} from 'luxon';
import {Transform} from 'class-transformer';
import {TransformDecoratorType} from '../../types';
import {parseDateTime} from '../../utils';
export const transformAsDate = (v: DateTime | unknown): string | null => {
const parsed = parseDateTime((v as any)?.value ?? v);
return typeof parsed?.toISODate === 'function' ? parsed.toISODate() : null;
};
/**
* Transforms luxon.DateTime to ISO date string.
*/
export const AsDate = (): TransformDecoratorType => Transform(transformAsDate);