Created
May 15, 2024 19:25
-
-
Save kitihounel/4fdcef53d96cf5957d8c127a8228ece4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ArgumentMetadata, BadRequestException, Injectable, PipeTransform } from '@nestjs/common'; | |
import { isISO8601 } from 'class-validator' | |
@Injectable() | |
export class ParseDatePipe implements PipeTransform { | |
transform(value: any, metadata: ArgumentMetadata): Date { | |
if (typeof value !== 'string' || !isISO8601(value, { strict: true })) { | |
throw new BadRequestException() | |
} | |
return new Date(value) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment