Implement assessment delete service method and endpoint
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user