Home > Back-end >  nestjs dtop to concrearte model transformaton
nestjs dtop to concrearte model transformaton

Time:08-18

I have been studying through the next js documentation, and I am having difficult time wrapping my head around the following code

@Post()
  @Roles('admin')
  async create(@Body() createCatDto: CreateCatDto) {
    this.catsService.create(createCatDto);
  }

the snippet of the above controller passes CreateCatDto to the underlying service

however if you look at the underlying service the signature is as follows

  create(cat: Cat) {
    this.cats.push(cat);
  }

i am confused as to how a CreateCatDto becomes a Cat, because when i tried similar setup in another code i got a type error.

CodePudding user response:

That example from documentation makes very simple thing. the object structure from createCatDto has same structure as Cat (cats.entity.ts ).

  • Related