Move review to separate model
This commit is contained in:
@@ -45,23 +45,30 @@ export default defineEventHandler(async (event) => {
|
||||
if (!answer) {
|
||||
throw createError({ status: 404, statusText: 'Not found!' });
|
||||
}
|
||||
const { score, review } = await useValidatedBody(
|
||||
const data = await useValidatedBody(
|
||||
event,
|
||||
z.object({
|
||||
score: z.int().min(0).max(32767).nullable(),
|
||||
review: z.string().max(256).nullable()
|
||||
review: z.string().max(256).nullable(),
|
||||
showcase: z.boolean().nullable().default(false),
|
||||
internalNote: z.string().max(256).nullable(),
|
||||
rankingValue: z.int().nullable()
|
||||
})
|
||||
);
|
||||
|
||||
await prisma.questAnswer.update({
|
||||
await prisma.review.upsert({
|
||||
where: {
|
||||
id: answerId
|
||||
answerId
|
||||
},
|
||||
data: {
|
||||
score,
|
||||
review,
|
||||
update: {
|
||||
...data,
|
||||
reviewerId: userId
|
||||
},
|
||||
create: {
|
||||
...data,
|
||||
reviewerId: userId
|
||||
}
|
||||
});
|
||||
|
||||
return answer;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user