16 lines
528 B
TypeScript
16 lines
528 B
TypeScript
import { ArgumentMetadata, HttpStatus, Injectable, PipeTransform } from "@nestjs/common";
|
|
import { ApiError } from "src/utilities/api-error";
|
|
import { CustomUuid } from "src/utilities/uuid";
|
|
|
|
@Injectable()
|
|
export class IsUuidPipe implements PipeTransform<string> {
|
|
constructor(private readonly message = "id is not valid") {}
|
|
|
|
transform(value: string, metadata: ArgumentMetadata) {
|
|
if (!CustomUuid.validate(value)) {
|
|
throw new ApiError(this.message, HttpStatus.UNPROCESSABLE_ENTITY);
|
|
}
|
|
return value;
|
|
}
|
|
}
|