diff --git a/.vscode/settings.json b/.vscode/settings.json index daf0f03c..43ed1d2b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "casl", "CHECKINGS", "cloudinary", + "DDTHH", "decapitalize", "deserialization", "DOESNT", @@ -39,6 +40,7 @@ "rabbitmq", "Requote", "rubiin", + "SSSZ", "UNAUTHORISED" ] } diff --git a/src/common/decorators/validation/is-date-format.validator.ts b/src/common/decorators/validation/is-date-format.validator.ts index 930835f8..479a8b0a 100644 --- a/src/common/decorators/validation/is-date-format.validator.ts +++ b/src/common/decorators/validation/is-date-format.validator.ts @@ -12,6 +12,20 @@ import { isArray } from "helper-fns"; /* It validates that a date is in a given format */ + +export type DateFormats = +| "yyyy-MM-dd" // ISO 8601 Format +| "dd/MM/yyyy" +| "MM/dd/yyyy" +| "yyyy-MM-dd HH:mm:ss" // Full Date and Time (Timestamp) +| "yyyy-MM-dd" // Date Only +| "yyyy/MM/dd" // Alternate Date Format +| "yyyy.MM.dd" // Alternate Date Format +| "MM-dd-yyyy" // Alternate Date Format +| "dd MMM yyyy" // Alternate Date Format +| "yyyy-MM-ddTHH:mm:ss" // ISO Date-Time Format +| "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; // ISO Date-Time String Format + @ValidatorConstraint({ async: true }) class IsDateInFormatConstraint implements ValidatorConstraintInterface { async validate(value: string | string[], arguments_: ValidationArguments) { @@ -32,7 +46,7 @@ class IsDateInFormatConstraint implements ValidatorConstraintInterface { } export const IsDateInFormat = ( - format: string, + format: DateFormats, validationOptions?: ValidationOptions, ): PropertyDecorator => { return function (object: Record, propertyName: string | symbol) {