Files
schedule-parser-next/src/utility/parse-pipe/object-id.pipe.ts
n08i40k 6b07bd89b8 Чистка.
Удалены неиспользуемые функции.
Были исправлены несоблюдения стиля кода.
2024-09-06 23:32:16 +04:00

21 lines
534 B
TypeScript

import { PipeTransform, Injectable, BadRequestException } from "@nestjs/common";
@Injectable()
export class ObjectIdPipe implements PipeTransform<any, string> {
transform(value: any): string {
if (
value === null ||
value === undefined ||
typeof value !== "string" ||
value.length !== 24
)
throw new BadRequestException("Invalid ObjectId");
const returnString = value.toLowerCase();
if (!/^[0-9a-f]{24}$/.test(returnString))
throw new BadRequestException("Invalid ObjectId");
return returnString;
}
}