Pull Request branch dev-clone to main #1

Merged
gitea merged 429 commits from dev-clone into main 2024-12-23 09:31:34 +00:00
2 changed files with 11 additions and 12 deletions
Showing only changes of commit 4453cc49d7 - Show all commits

View File

@ -15,7 +15,7 @@ export const respondents = pgTable("respondents", {
phoneNumber: varchar("phoneNumber", { length: 13 }).notNull(), phoneNumber: varchar("phoneNumber", { length: 13 }).notNull(),
createdAt: timestamp("createdAt", { mode: "date" }).defaultNow(), createdAt: timestamp("createdAt", { mode: "date" }).defaultNow(),
updatedAt: timestamp("updatedAt", { 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 }) => ({ export const respondentsRelations = relations(respondents, ({ one }) => ({

View File

@ -97,7 +97,6 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
}); });
} }
) )
// Post assessment request by user ID // Post assessment request by user ID
.post( .post(
@ -106,7 +105,7 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
requestValidator( requestValidator(
"json", "json",
z.object({ z.object({
respondentId: z.string().min(1), respondentId: z.string().min(1), // Memastikan respondentId minimal ada
}) })
), ),
async (c) => { async (c) => {
@ -114,36 +113,36 @@ const assessmentRequestRoute = new Hono<HonoEnv>()
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; // Mengambil userId dari currentUser yang disimpan di context
// Make sure the userId exists // Memastikan user sudah terautentikasi
if (!userId) { 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 const respondent = await db
.select() .select()
.from(respondents) .from(respondents)
.where(eq(respondents.id, respondentId)); .where(and(eq(respondents.id, respondentId), eq(respondents.userId, userId)));
if (!respondent.length) { 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 const newAssessment = await db
.insert(assessments) .insert(assessments)
.values({ .values({
id: createId(), id: createId(),
respondentId, respondentId,
status: "menunggu konfirmasi", status: "menunggu konfirmasi", // Status awal permohonan
validatedBy: null, validatedBy: null,
validatedAt: null, validatedAt: null,
createdAt: new Date(), createdAt: new Date(),
}) })
.returning(); .returning();
return c.json({ message: "Successfully submitted the assessment request" }, 201); return c.json({ message: "Successfully submitted the assessment request", data: newAssessment }, 201);
} }
); );
export default assessmentRequestRoute; export default assessmentRequestRoute;