model Case{
id String @id @default(uuid())
caseId Int @unique @default(autoincrement())
title String
status Status[]
}
model Status{
id String @id @default(uuid())
statusId Int @unique @default(autoincrement())
title String
caseId Int
story Story[]
case Case? @relation(fields: [caseId],references: [caseId], onDelete: Cascade)
}
Consider the following scenario where we have two Prisma models. The "Case" model is considered the main one and can be created with just a title. However, in order to create a "Status", it must be associated with a specific case through its caseId field. This means that when creating a new Status, the request body should look like this:
{
"caseId": 1,
"title": "string"
}
Currently, the create code for the Status entity looks like this:
async create(status: CreateStatusDto) {
const {caseId, ... rest} = status
if(!caseId){
throw new BadRequestException('Please Input Case Id')
}
return await this.prismaService.status.create({
data: {
...rest,
case: {
connect: {
caseId: caseId
}
}
}
})
}
This implementation may not be optimal in terms of readability and efficiency. Are there any suggestions on how to improve it?