Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wermarter committed Dec 18, 2023
1 parent b841110 commit fa274ea
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions libs/nest-core/src/mongo/mongo.common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { SchemaOptions } from '@nestjs/mongoose'
import { Expose } from 'class-transformer'
import { Expose, Transform } from 'class-transformer'
import { ApiProperty } from '@nestjs/swagger'
import { BadRequestException, Injectable, PipeTransform } from '@nestjs/common'
import {
BadRequestException,
Injectable,
PipeTransform,
applyDecorators,
} from '@nestjs/common'
import { ObjectId, Types } from 'mongoose'
import {
registerDecorator,
Expand All @@ -19,7 +24,20 @@ export const exampleDate = {
example: '2018-03-20T09:12:28Z',
}

// https://github.com/typestack/class-transformer/issues/494
export const ExposeObjectId = () =>
applyDecorators(
Expose(),
Transform(
({ obj, key }) => {
return obj[key]
},
{ toClassOnly: true },
),
)

export class BaseResourceResponseDto {
@ExposeObjectId()
@ApiProperty(exampleMongoObjectId)
_id: string

Expand Down

0 comments on commit fa274ea

Please sign in to comment.