I think it s a typescript compilation problem but I m still learning typescript. Here is some context, I m using nestjs, prisma and vegardit/prisma-generator-nestjs-dto to create some rest cruds. I made a self relation of one to many but when I compile the project I get this error.
Cannot find module C:/sistema-gestion-riesgo/src/puesto/dto/connect-puesto.dto
Require stack:
- C:sistema-gestion-riesgodistpuestodtocreate-puesto.dto.js
- C:sistema-gestion-riesgodistpuestopuesto.controller.js
- C:sistema-gestion-riesgodistpuestopuesto.module.js
- C:sistema-gestion-riesgodistapp.module.js
- C:sistema-gestion-riesgodistmain.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.type (C:sistema-gestion-riesgodistpuestodtocreate-puesto.dto.js:15:57)
at SchemaObjectFactory.mergePropertyWithMetadata (C:sistema-gestion-riesgo
ode_modules@nestjsswaggerdistservicesschema-object-factory.js:116:38)
at C:sistema-gestion-riesgo
ode_modules@nestjsswaggerdistservicesschema-object-factory.js:79:35
at Array.map (<anonymous>)
at SchemaObjectFactory.extractPropertiesFromType (C:sistema-gestion-riesgo
ode_modules@nestjsswaggerdistservicesschema-object-factory.js:78:52)
at SchemaObjectFactory.exploreModelSchema (C:sistema-gestion-riesgo
ode_modules@nestjsswaggerdistservicesschema-object-factory.js:92:41)
这是schema.prisma。 I m使用并配置。
generator nestjsDto {
provider = "prisma-generator-nestjs-dto"
exportRelationModifierClasses = "true"
reExport = "true"
createDtoPrefix = "Create"
updateDtoPrefix = "Update"
dtoSuffix = "Dto"
entityPrefix = ""
entitySuffix = ""
fileNamingStyle = "kebab"
output = "../src"
outputToNestJsResourceStructure = "true"
}
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Puesto {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
nombre String
/// @DtoCreateOptional
/// @DtoUpdateOptional
/// @DtoRelationCanConnectOnCreate
/// @DtoRelationCanConnectOnUpdate
jefeInmediato Puesto? @relation("JefeEmpleados", fields: [jefeInmediatoId], references: [id])
jefeInmediatoId Int?
personalAcargo Puesto[] @relation("JefeEmpleados")
@@map("puestos")
}
归根结底,如何产生DTO。
-pruesto.dto.ts
export class ConnectPuestoDto {
id: number;
}
create-puesto.dto.ts
import {ApiExtraModels} from @nestjs/swagger
import {ConnectPuestoDto} from ./connect-puesto.dto
export class CreatePuestoJefeInmediatoRelationInputDto {
connect: ConnectPuestoDto;
}
@ApiExtraModels(ConnectPuestoDto,CreatePuestoJefeInmediatoRelationInputDto)
export class CreatePuestoDto {
nombre: string;
jefeInmediato?: CreatePuestoJefeInmediatoRelationInputDto;
}
And by last, index.ts
export * from ./connect-puesto.dto ;
export * from ./create-puesto.dto ;
export * from ./update-puesto.dto ;