feat(api): add global infrastructure modules
This commit is contained in:
1 parent
7c625ae97a
commit
e4aa9e6f35
15 files changed
+2004
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
ArgumentMetadata,
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
PipeTransform,
|
||||
} from '@nestjs/common';
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
@Injectable()
|
||||
export class ParseObjectIdPipe
|
||||
implements PipeTransform<string, mongoose.Types.ObjectId>
|
||||
{
|
||||
public transform(
|
||||
value: string,
|
||||
metadata: ArgumentMetadata,
|
||||
): mongoose.Types.ObjectId {
|
||||
if (!mongoose.isValidObjectId(value)) {
|
||||
throw new BadRequestException(
|
||||
`Invalid ObjectId for ${metadata.data ?? 'param'}.`,
|
||||
);
|
||||
}
|
||||
return new mongoose.Types.ObjectId(value);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user