Created
May 15, 2024 19:30
-
-
Save kitihounel/caae2490c93260b4aeb25d5683a5f6ac 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 { isUUID } from 'class-validator' | |
@Injectable() | |
export class ParseUuidListPipe implements PipeTransform { | |
transform(value: any, metadata: ArgumentMetadata): string[] { | |
if (typeof value !== 'string') { | |
throw new BadRequestException() | |
} | |
const parts = value.split(',') | |
for (const id of parts) { | |
if (!isUUID(id, 4)) { | |
throw new BadRequestException() | |
} | |
} | |
return parts | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment