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(
|
requestValidator(
|
||||||
"json",
|
"json",
|
||||||
z.object({
|
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) => {
|
async (c) => {
|
||||||
const { respondentId } = c.req.valid("json");
|
const { respondentId } = c.req.valid("json");
|
||||||
const currentUser = c.get("currentUser");
|
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) {
|
if (!userId) {
|
||||||
return c.text("User not authenticated", 401);
|
return c.text("User not authenticated", 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validasi apakah respondent dengan respondentId tersebut ada
|
// Validate if respondent with respondentId exists
|
||||||
const respondent = await db
|
const respondent = await db
|
||||||
.select()
|
.select()
|
||||||
.from(respondents)
|
.from(respondents)
|
||||||
|
|
@ -130,7 +129,7 @@ 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"
|
// Check if there is an assessment request with status "in progress"
|
||||||
const existingAssessment = await db
|
const existingAssessment = await db
|
||||||
.select()
|
.select()
|
||||||
.from(assessments)
|
.from(assessments)
|
||||||
|
|
@ -141,16 +140,13 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
||||||
)
|
)
|
||||||
);console.log(existingAssessment);
|
);console.log(existingAssessment);
|
||||||
|
|
||||||
if (existingAssessment.length) {
|
if (!existingAssessment.length) {
|
||||||
return c.json({ message: "Asesmen sedang dalam pengerjaan, tidak bisa membuat permohonan baru." }, 400);
|
|
||||||
}else{
|
|
||||||
// Membuat permohonan asesmen baru
|
|
||||||
const newAssessment = await db
|
const newAssessment = await db
|
||||||
.insert(assessments)
|
.insert(assessments)
|
||||||
.values({
|
.values({
|
||||||
id: createId(),
|
id: createId(),
|
||||||
respondentId,
|
respondentId,
|
||||||
status: "menunggu konfirmasi", // Status awal permohonan
|
status: "menunggu konfirmasi",
|
||||||
reviewedAt: null,
|
reviewedAt: null,
|
||||||
reviewedBy: null,
|
reviewedBy: null,
|
||||||
verifiedBy: null,
|
verifiedBy: null,
|
||||||
|
|
@ -160,6 +156,7 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
return c.json({ message: "Successfully submitted the assessment request", data: newAssessment }, 201);
|
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) {
|
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();
|
return await response.json();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user