fix: revise dashboardError for updateAnswer on Assessments

This commit is contained in:
falendikategar 2024-08-20 17:25:58 +07:00
parent 2fab856cdb
commit c0e28b1019

View File

@ -383,9 +383,7 @@ const assessmentsRoute = new Hono<HonoEnv>()
async (c) => { async (c) => {
const answerId = c.req.param("id"); const answerId = c.req.param("id");
const answerData = c.req.valid("json"); const answerData = c.req.valid("json");
let response;
let statusCode;
const updatedAnswer = await db const updatedAnswer = await db
.update(answers) .update(answers)
.set({ .set({
@ -395,24 +393,15 @@ const assessmentsRoute = new Hono<HonoEnv>()
.returning(); .returning();
if (!updatedAnswer.length) { if (!updatedAnswer.length) {
response = { throw notFound({
message: "Answer not found or update failed", message: "Answer not found or update failed"
}; })
statusCode = 404;
} else {
response = {
message: "Answer updated successfully",
answer: updatedAnswer[0],
};
statusCode = 200;
} }
return c.json( return c.json({
response, message: "Answer updated successfully",
{ answer: updatedAnswer[0],
status: statusCode });
}
);
} }
) )