Skip to content

Commit 55c4404

Browse files
committed
feat: Add _decorators module for exporting decorators
1 parent 41f2591 commit 55c4404

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/_decorators/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './real-ip.decorator'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ArgumentMetadata, BadRequestException, Injectable, PipeTransform } from '@nestjs/common'
2+
import { Types } from 'mongoose'
3+
4+
@Injectable()
5+
export class ObjectIdValidationPipe implements PipeTransform<string, Types.ObjectId> {
6+
public transform(value: string | Types.ObjectId, _metadata: ArgumentMetadata): Types.ObjectId {
7+
if (!Types.ObjectId.isValid(value)) {
8+
throw new BadRequestException(`Invalid ObjectId <${value}>`)
9+
}
10+
return new Types.ObjectId(value)
11+
}
12+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './_abstracts'
2+
export * from './_decorators'
23
export * from './_filters'
34
export * from './_pipes'
45
export * from './auth'

0 commit comments

Comments
 (0)