This commit is contained in:
2024-09-06 23:13:44 +04:00
parent 2b2018c317
commit 31906fbbd1
29 changed files with 2061 additions and 90 deletions

View File

@@ -0,0 +1,20 @@
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 return_string = value.toLowerCase();
if (!/^[0-9a-f]{24}$/.test(return_string))
throw new BadRequestException("Invalid ObjectId");
return return_string;
}
}