#Can a `@Query` param Pipe be optional ?
1 messages · Page 1 of 1 (latest)
made a custom pipe ```ts
import { PipeTransform, Injectable, BadRequestException } from "@nestjs/common"
@Injectable()
export class ParseOptionalIntPipe
implements PipeTransform<string, number | undefined>
{
transform(value: string): number | undefined {
if (!value) return undefined
const val = Number.parseInt(value, 10)
if (Number.isNaN(val)) {
throw new BadRequestException(
"Validation failed (numeric string is expected)",
)
}
return val
}
}