Update : added conditions for create assReq
This commit is contained in:
parent
f2ec598e02
commit
a80e55d9d7
|
|
@ -130,6 +130,20 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
||||||
throw new HTTPException(404, { message: "Respondent not found or unauthorized." });
|
throw new HTTPException(404, { message: "Respondent not found or unauthorized." });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cek jika ada permohonan dengan status "dalam pengerjaan"
|
||||||
|
const existingAssessment = await db
|
||||||
|
.select()
|
||||||
|
.from(assessments)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(assessments.respondentId, respondentId),
|
||||||
|
eq(assessments.status, "dalam pengerjaan")
|
||||||
|
)
|
||||||
|
);console.log(existingAssessment);
|
||||||
|
|
||||||
|
if (existingAssessment.length) {
|
||||||
|
return c.json({ message: "Asesmen sedang dalam pengerjaan, tidak bisa membuat permohonan baru." }, 400);
|
||||||
|
}else{
|
||||||
// Membuat permohonan asesmen baru
|
// Membuat permohonan asesmen baru
|
||||||
const newAssessment = await db
|
const newAssessment = await db
|
||||||
.insert(assessments)
|
.insert(assessments)
|
||||||
|
|
@ -137,6 +151,8 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
||||||
id: createId(),
|
id: createId(),
|
||||||
respondentId,
|
respondentId,
|
||||||
status: "menunggu konfirmasi", // Status awal permohonan
|
status: "menunggu konfirmasi", // Status awal permohonan
|
||||||
|
reviewedAt: null,
|
||||||
|
reviewedBy: null,
|
||||||
verifiedBy: null,
|
verifiedBy: null,
|
||||||
verifiedAt: null,
|
verifiedAt: null,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
|
|
@ -145,6 +161,7 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
||||||
|
|
||||||
return c.json({ message: "Successfully submitted the assessment request", data: newAssessment }, 201);
|
return c.json({ message: "Successfully submitted the assessment request", data: newAssessment }, 201);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Update assessment status when the user clicks the start assessment button
|
// Update assessment status when the user clicks the start assessment button
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ export const createAssessmentRequest = async ({ respondentsId }: { respondentsId
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Failed to create assessment request");
|
throw new Error("Asesemen sedang berlangsung, Selesaikan terlebih dahulu.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return await response.json();
|
return await response.json();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user