Brakebein / prisma-generator-nestjs-dto

Generates NestJS DTO classes from Prisma Schema
Apache License 2.0
48 stars 26 forks source link

Ignore a model for generation #45

Open clounarae opened 2 months ago

clounarae commented 2 months ago

Hello !

Is there a way to ignore one model during generation ?

For exemple, I'd like to add a field to an entity DTO without adding it in my prisma schema. However, when regenerating with prisma, my modification is overriden.

Is there a way to show that i'd like no regeneration for an entity ?

Thank you for your answer

Brakebein commented 2 months ago

No, currently there isn't any annotation or alike that can do that. I don't even think that it is good practice to edit those kind of auto-generated files.

In my own projects, if I want to add an additional field to the DTO without adding it to the prisma schema, I create an extra class file, which extends the original model. With this approach, the original ProductDto can be regenerated without losing (or forgetting to add) the extra value. It is also semantically cleaner, also with respect to code comprehension (in my opinion), because the prisma schema wouldn't be the ground of truth anymore otherwise.

// path/outside/of/generated/folder/product-with-extra-value.dto.ts

export class ProductWithExtraValueDto extends ProductDto {
  @ApiProperty({
    description: 'Some extra data', 
  ])
  extraValue: string;
}

Usually, I put those custom dtos near to where they are used, e.g.:

/images
  /dto
    get-images-query-params.ts
    image-with-extra-value.dto.ts
    upload-image.dto.ts
  images.controller.ts
  images.module.ts
  images.service.ts