#Nest js + Prisma

4 messages · Page 1 of 1 (latest)

static nimbus
#

I'm just starting with nest js and i have a question with prisma and DTO i don't know what is the best practice.

I have see in a tutorial that they use :

    return this.databaseService.employee.create({
      data: createEmployeeDto,
    });
  }

He doesn't use the create-employee.dto.ts. It's good ?

And can you have some advance example with prisma and RESTapi ? I don't find any ..

Thanks in advance !

lavish gorge
#

Prisma has decent doc on that, https://www.prisma.io/blog/nestjs-prisma-rest-api-7D056s1BmOL0

Just went over it even though its from 2022 it still applies to new versions.

He doesn't do validation in this one but he does use Dto, I suggest you read about validation in nestjs to add it to this project

Prisma

Learn how to build a backend REST API with NestJS, Prisma, PostgreSQL and Swagger. In this article, you will learn how to set up the project, build the API and document it with Swagger.

#

I'd say use Dto and not Prisma types for this kind of usage because :

  • you can't do validation on thoses types
  • no automated swagger
  • they are hard to read tbh
  • sometimes you might want to switch up the way you fill your data with other parameters, or conditionals, etc.
static nimbus
#

Thanks for your response, i'm gonna check the blog.

Yes it's seems better to use Dto over Prisma types