Implement assessment delete service method and endpoint

This commit is contained in:
Dominic Ferrando
2026-08-22 12:00:36 -04:00
parent 01e9ac8403
commit 951f9286aa
2 changed files with 16 additions and 4 deletions
+8 -4
View File
@@ -482,7 +482,7 @@ export const app = new Elysia()
.group("/assessments", (app) => app .group("/assessments", (app) => app
.guard({ auth: true }, (app) => app .guard({ auth: true }, (app) => app
.post("/me", async ({ body: { player, activityPerformances }, accountId }) => { .post("/me", async ({ body: { player, activityPerformances }, accountId }) => {
await s.Assessments.create(player, activityPerformances, accountId); return await s.Assessments.create(player, activityPerformances, accountId);
}, { }, {
body: t.Object({ body: t.Object({
player: PlayerSchema, player: PlayerSchema,
@@ -490,9 +490,13 @@ export const app = new Elysia()
}) })
}) })
.get("/me", async ({ accountId }) => { .get("/me", async ({ accountId }) => {
const assessments = await s.Assessments.list({ filter: { accountId } }); return await s.Assessments.list({ filter: { accountId } });
if (!assessments) throw new NotFoundError("Assessments not found"); })
return assessments; .delete("/me/:id", async ({ params: { id }, accountId }) => {
const deleted = await s.Assessments.delete(id, accountId);
if (!deleted) throw new NotFoundError("Assessment not found");
}, {
params: t.Object({ id: t.String() })
}) })
) )
.guard({ authAdmin: true }, (app) => app .guard({ authAdmin: true }, (app) => app
+8
View File
@@ -39,4 +39,12 @@ export class AssessmentsService {
.$if(opt.offset !== undefined, (qb) => qb.offset(opt.offset!)) .$if(opt.offset !== undefined, (qb) => qb.offset(opt.offset!))
.execute(); .execute();
} }
async delete(id: string, accountId: string): Promise<boolean> {
const result = await db.deleteFrom("assessments")
.where("id", "=", id)
.where("account_id", "=", accountId)
.executeTakeFirst();
return result.numDeletedRows > 0n;
}
} }