feat(api): add service foundation
This commit is contained in:
1 parent
36823f6217
commit
105df69258
16 files changed
+509
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