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)
}
So let's say I have two Prisma Models like this. Case is the bigger one, so that one can be created with just the title. Now, I want it so that for someone to create a status, it needs to come with the caseId. So the post body is like this
{
"caseId": 1,
"title": "string"
}
As such, right now my create code is 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
}
}
}
})
}
And it's not exactly pretty, so I'm looking for a better way to write it. Any suggestions?