From db71f1f95295f992b34440d6f58cb42797356efa Mon Sep 17 00:00:00 2001 From: adelbke Date: Mon, 29 Jul 2024 11:05:25 +0200 Subject: [PATCH 1/2] (fix) Handled the case of passing a function that returns a date to the MaxDate decorator --- src/defaultConverters.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/defaultConverters.ts b/src/defaultConverters.ts index 393fa9d..5e8294d 100644 --- a/src/defaultConverters.ts +++ b/src/defaultConverters.ts @@ -148,13 +148,16 @@ export const defaultConverters: ISchemaConverters = { { format: 'date-time', type: 'string' }, ], }), - [cv.MAX_DATE]: (meta) => ({ - description: `Before ${meta.constraints[0].toJSON()}`, - oneOf: [ - { format: 'date', type: 'string' }, - { format: 'date-time', type: 'string' }, - ], - }), + [cv.MAX_DATE]: (meta) => { + const description= typeof meta.constraints[0] === 'function' ? `Before a date computed dynamically` : `Before ${meta.constraints[0]}`; + return { + description, + oneOf: [ + { format: 'date', type: 'string' }, + { format: 'date-time', type: 'string' }, + ], + } + }, [cv.IS_BOOLEAN_STRING]: { enum: ['true', 'false'], type: 'string', From 8af16dfb831c80a32881d08fbba4b67b016cddd6 Mon Sep 17 00:00:00 2001 From: adelbke Date: Mon, 29 Jul 2024 11:12:46 +0200 Subject: [PATCH 2/2] (fix) Handled the case of passing a function that returns a date to the MinDate decorator --- src/defaultConverters.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/defaultConverters.ts b/src/defaultConverters.ts index 5e8294d..60d3d0e 100644 --- a/src/defaultConverters.ts +++ b/src/defaultConverters.ts @@ -26,9 +26,9 @@ export const defaultConverters: ISchemaConverters = { if (typeof meta.target === 'function') { const typeMeta = options.classTransformerMetadataStorage ? options.classTransformerMetadataStorage.findTypeMetadata( - meta.target, - meta.propertyName - ) + meta.target, + meta.propertyName + ) : null const childType = typeMeta ? typeMeta.typeFunction() @@ -141,15 +141,18 @@ export const defaultConverters: ISchemaConverters = { maximum: meta.constraints[0], type: 'number', }), - [cv.MIN_DATE]: (meta) => ({ - description: `After ${meta.constraints[0].toJSON()}`, - oneOf: [ - { format: 'date', type: 'string' }, - { format: 'date-time', type: 'string' }, - ], - }), + [cv.MIN_DATE]: (meta) => { + const description = typeof meta.constraints[0] === 'function' ? `After a date computed dynamically` : `After ${meta.constraints[0]}`; + return { + description, + oneOf: [ + { format: 'date', type: 'string' }, + { format: 'date-time', type: 'string' }, + ], + } + }, [cv.MAX_DATE]: (meta) => { - const description= typeof meta.constraints[0] === 'function' ? `Before a date computed dynamically` : `Before ${meta.constraints[0]}`; + const description = typeof meta.constraints[0] === 'function' ? `Before a date computed dynamically` : `Before ${meta.constraints[0]}`; return { description, oneOf: [