Pull Request branch dev-clone to main #1
|
|
@ -15,7 +15,7 @@ export const respondents = pgTable("respondents", {
|
|||
phoneNumber: varchar("phoneNumber", { length: 13 }).notNull(),
|
||||
createdAt: timestamp("createdAt", { mode: "date" }).defaultNow(),
|
||||
updatedAt: timestamp("updatedAt", { mode: "date" }).defaultNow(),
|
||||
deletedAt: timestamp("deletetAt", { mode: "date" }),
|
||||
deletedAt: timestamp("deletedAt", { mode: "date" }),
|
||||
});
|
||||
|
||||
export const respondentsRelations = relations(respondents, ({ one }) => ({
|
||||
|
|
|
|||
|
|
@ -98,7 +98,6 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
// Post assessment request by user ID
|
||||
.post(
|
||||
"/",
|
||||
|
|
@ -106,7 +105,7 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
|||
requestValidator(
|
||||
"json",
|
||||
z.object({
|
||||
respondentId: z.string().min(1),
|
||||
respondentId: z.string().min(1), // Memastikan respondentId minimal ada
|
||||
})
|
||||
),
|
||||
async (c) => {
|
||||
|
|
@ -114,35 +113,35 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
|
|||
const currentUser = c.get("currentUser");
|
||||
const userId = currentUser?.id; // Mengambil userId dari currentUser yang disimpan di context
|
||||
|
||||
// Make sure the userId exists
|
||||
// Memastikan user sudah terautentikasi
|
||||
if (!userId) {
|
||||
throw new HTTPException(400, { message: "User not authenticated" });
|
||||
return c.text("User not authenticated", 401);
|
||||
}
|
||||
|
||||
// Validate if respondent exists
|
||||
// Validasi apakah respondent dengan respondentId tersebut ada
|
||||
const respondent = await db
|
||||
.select()
|
||||
.from(respondents)
|
||||
.where(eq(respondents.id, respondentId));
|
||||
.where(and(eq(respondents.id, respondentId), eq(respondents.userId, userId)));
|
||||
|
||||
if (!respondent.length) {
|
||||
throw new HTTPException(404, { message: "Respondent not found." });
|
||||
throw new HTTPException(404, { message: "Respondent not found or unauthorized." });
|
||||
}
|
||||
|
||||
// Create the assessment request
|
||||
// Membuat permohonan asesmen baru
|
||||
const newAssessment = await db
|
||||
.insert(assessments)
|
||||
.values({
|
||||
id: createId(),
|
||||
respondentId,
|
||||
status: "menunggu konfirmasi",
|
||||
status: "menunggu konfirmasi", // Status awal permohonan
|
||||
validatedBy: null,
|
||||
validatedAt: null,
|
||||
createdAt: new Date(),
|
||||
})
|
||||
.returning();
|
||||
|
||||
return c.json({ message: "Successfully submitted the assessment request" }, 201);
|
||||
return c.json({ message: "Successfully submitted the assessment request", data: newAssessment }, 201);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user