I've been working on creating a table answer with Prisma, but I'm facing challenges in defining an update function due to the ID being composed of two foreign keys from the user and question tables.
This is my current progress:
- schema.prisma
model Answer{
id_question Int
id_user String
content String @db.VarChar(250)
updated_at DateTime @updatedAt
user User @relation(fields: [id_user], references: [id])
question Question @relation(fields: [id_question], references: [id])
@@id([id_question, id_user], name:"question_user")
}
- answers.service.ts
async updateAnswer(params: {
where: Prisma.AnswerWhereUniqueInput;
data: Prisma.AnswerUpdateInput;
}): Promise<Answer> {
const { where, data } = params;
return this.prisma.answer.update({
data,
where,
});
}
- answers.controller.ts
I am uncertain about how to define the route and specify the ID parameter in this section:
@Patch('answer/:id')
async updateAnswer(@Param('id') id: string): Promise<answerModel> {
return this.postService.updateAnswer({
where: { id: Number(id) },
data: { content: true },
});
}