Closed ChristopherCapito closed 1 year ago
In my project, I don't really use the connect DTOs. But yes, it would be possible. However, id: string;
should also be optional id?: string;
, because you could either connect by id
or vendor_chassis_number
.
I also just realize that it doesn't generate any ApiProperty or class validation decorators yet. Hence, for vendor_chassis_number
an additional class would be needed. So the output would look something like this:
export class VendorChassisNumber {
@ApiProperty()
@IsNotEmpty()
@IsString()
vendor: string;
@ApiProperty()
@IsNotEmpty()
@IsString()
chassis_number: string;
}
export class ConnectBikeDto {
@ApiProperty({
required: false,
nullable: true,
})
@IsOptional()
@IsString()
id?: string;
@ApiProperty({
required: false,
nullable: true,
type: VendorChassisNumber,
})
@IsOptional()
@ValidateNested()
@Type(() => VendorChassisNumber)
vendor_chassis_number?: VendorChassisNumber;
}
So, it seems a bit more complex at second glance.
Well. For now I just keep in mind to always edit the connect DTO to fit my purpose. It would be a great help to have the generator do this, even if it does not include the API documentation right away. I really need to get more into your generator to understand how its working. Maybe I can implement it myself. :D
I finally found some time to implement it. Can you please test it? https://www.npmjs.com/package/@brakebein/prisma-generator-nestjs-dto/v/1.17.0-beta0
With Prisma, for example if using postgres, you can use a compound of unique fields.
This schema:
produces the following connect-dto:
wheras it should be this, as it is in Prisma:
For now I am editing the DTO after the fact, although using prisma generate obviously overrides the field.