Skip to content

Instantly share code, notes, and snippets.

@kitihounel
Created May 15, 2024 19:25
Show Gist options
  • Save kitihounel/4fdcef53d96cf5957d8c127a8228ece4 to your computer and use it in GitHub Desktop.
Save kitihounel/4fdcef53d96cf5957d8c127a8228ece4 to your computer and use it in GitHub Desktop.
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