ydhn / prisma-generator-nestjs-dto

Generates NestJS DTO classes from Prisma Schema
Apache License 2.0
5 stars 3 forks source link

Specifying "entitySuffix" breaks dto generation #3

Open InnoredFR opened 1 year ago

InnoredFR commented 1 year ago

Expected Behavior

EntitySuffix should just append a suffix to generated entities

Actual Behavior

When specifying an entity suffix, like "Dto" for example, the subsequent generated Dto for this entity are broken. Indeed, for exemple, the createDto looks like this


import {ApiExtraModels} from '@nestjs/swagger'
import {ConnectSiteDto} from '../../site/dto/connect-site.dto'
import {CreateUserSettingDto} from '../../userSetting/dto/create-userSetting.dto'

export class CreateUserSiteRelationInputDto {
    connect: ConnectSiteDto;
  }
export class CreateUserUserSettingRelationInputDto {
    create: CreateUserSettingDto;
  }

@ApiExtraModels(ConnectSiteDtoDto,CreateUserSiteRelationInputDtoDto,CreateUserSettingDtoDto,CreateUserUserSettingRelationInputDtoDto)
export class CreateUserDto {
  username: string;
email: string;
password: string;
created_at?: Date;
site: CreateUserSiteRelationInputDtoDto;
User_Setting?: CreateUserUserSettingRelationInputDtoDto;
}

As you can see, the relations dto name are messed up adding the Dto suffix and entity sufix concatenated at the end.

The actual ConnectSiteDto looks like this, for example :

  export class ConnectSiteDto {
    id?: number;
name?: string;
  }

they do have the expected name

Steps to Reproduce the Problem

  1. create a schema prisma file
  2. specify an EntitySuffix
  3. generate the dtos

Specifications

Prisma file

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["extendedWhereUnique"]
}

generator nestjsDto {
  provider                        = "prisma-generator-nestjs-dto"
  output                          = "../src/generated"
  outputToNestJsResourceStructure = "true"
  exportRelationModifierClasses   = "true"
  reExport                        = "true"
  createDtoPrefix                 = "Create"
  updateDtoPrefix                 = "Update"
  dtoSuffix                       = "Dto"
  entityPrefix                    = ""
  entitySuffix                    = "Dto"
  fileNamingStyle                 = "camel"
  enumAsSchema                    = "false"
  prismaClientPath                = "@prisma/client"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  /// @DtoReadOnly
  id           Int           @id @unique @default(autoincrement())
  username     String
  email        String        @unique
  /// @DtoEntityHidden
  password     String
  is_archived  Boolean       @default(false)
  role         ROLE          @default(USER)
  /// @NoSet
  created_at   DateTime?     @default(now())
  /// @NoSet
  updated_at   DateTime?     @default(now()) @updatedAt
  /// @NoSet
  /// @DtoRelationRequired
  /// @DtoRelationCanConnectOnCreate
  site         Site?         @relation(name: "siteUsers", fields: [siteId], references: [id])
  siteId       Int
  Project      Project[]
  /// @DtoRelationCanCreateOnCreate
  /// @DtoRelationCanConnectOnUpdate
  User_Setting User_Setting?
}
ydhn commented 1 year ago

@InnoredFR Could you give me a full schema file? I'll try to reproduce this issue there are some missing ROLE, Site, Project etc...