Update: comments on the API assessment Request and fixed other typos
This commit is contained in:
parent
a80e55d9d7
commit
03478b25bc
|
|
@ -107,20 +107,19 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
|||
requestValidator(
|
||||
"json",
|
||||
z.object({
|
||||
respondentId: z.string().min(1), // Memastikan respondentId minimal ada
|
||||
respondentId: z.string().min(1), // Ensure respondentId has at least one character
|
||||
})
|
||||
),
|
||||
async (c) => {
|
||||
const { respondentId } = c.req.valid("json");
|
||||
const currentUser = c.get("currentUser");
|
||||
const userId = currentUser?.id; // Mengambil userId dari currentUser yang disimpan di context
|
||||
const userId = currentUser?.id; // Get userId from currentUser stored in context
|
||||
|
||||
// Memastikan user sudah terautentikasi
|
||||
if (!userId) {
|
||||
return c.text("User not authenticated", 401);
|
||||
}
|
||||
|
||||
// Validasi apakah respondent dengan respondentId tersebut ada
|
||||
// Validate if respondent with respondentId exists
|
||||
const respondent = await db
|
||||
.select()
|
||||
.from(respondents)
|
||||
|
|
@ -130,7 +129,7 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
|||
throw new HTTPException(404, { message: "Respondent not found or unauthorized." });
|
||||
}
|
||||
|
||||
// Cek jika ada permohonan dengan status "dalam pengerjaan"
|
||||
// Check if there is an assessment request with status "in progress"
|
||||
const existingAssessment = await db
|
||||
.select()
|
||||
.from(assessments)
|
||||
|
|
@ -141,16 +140,13 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
|||
)
|
||||
);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
|
||||
if (!existingAssessment.length) {
|
||||
const newAssessment = await db
|
||||
.insert(assessments)
|
||||
.values({
|
||||
id: createId(),
|
||||
respondentId,
|
||||
status: "menunggu konfirmasi", // Status awal permohonan
|
||||
status: "menunggu konfirmasi",
|
||||
reviewedAt: null,
|
||||
reviewedBy: null,
|
||||
verifiedBy: null,
|
||||
|
|
@ -160,6 +156,7 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
|||
.returning();
|
||||
|
||||
return c.json({ message: "Successfully submitted the assessment request", data: newAssessment }, 201);
|
||||
|
||||
}
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export const createAssessmentRequest = async ({ respondentsId }: { respondentsId
|
|||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Asesemen sedang berlangsung, Selesaikan terlebih dahulu.");
|
||||
throw new Error("Asesmen sedang berlangsung, Selesaikan terlebih dahulu.");
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user