mirror of
https://github.com/n08i40k/schedule-parser-next.git
synced 2025-12-06 09:47:46 +03:00
1.0.0
This commit is contained in:
20
src/utility/parse-pipe/object-id.pipe.ts
Normal file
20
src/utility/parse-pipe/object-id.pipe.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user