Implement .verify bot command

This commit is contained in:
Dominic Ferrando
2026-10-03 23:01:27 -04:00
parent e497982222
commit 7afde2c323
9 changed files with 359 additions and 10 deletions
+41 -3
View File
@@ -490,6 +490,21 @@ export const app = new Elysia()
}, {
params: t.Object({ id: AccountIdSchema })
})
// TODO: for added security, MUST enforce bot or admin only access
.get("/:id/verifications", async ({ query, params: { id } }) => {
return await s.Verifications.list({
filter: { status: query.status, accountId: id },
limit: query.limit,
offset: query.offset,
});
}, {
params: t.Object({ id: AccountIdSchema }),
query: t.Object({
status: t.Optional(VerificationStatusSchema),
limit: t.Optional(t.Numeric()),
offset: t.Optional(t.Numeric()),
})
})
.guard({ authAdmin: true }, (app) => app
.get("/:id", async ({ params: { id } }) => {
const account = await s.Accounts.get(id);
@@ -523,6 +538,19 @@ export const app = new Elysia()
}, {
params: t.Object({ id: BigIntIdSchema })
})
.get("/verifications", async ({ query, accountId }) => {
return await s.Verifications.list({
filter: { status: query.status, accountId },
limit: query.limit,
offset: query.offset,
});
}, {
query: t.Object({
status: t.Optional(VerificationStatusSchema),
limit: t.Optional(t.Numeric()),
offset: t.Optional(t.Numeric()),
})
})
.post("/verifications", async ({ body: { assessmentId }, accountId }) => {
const assessment = await s.Assessments.get(assessmentId, accountId);
if (!assessment) return status(404, { error: "Assessment not found" });
@@ -599,7 +627,7 @@ export const app = new Elysia()
)
// VERIFICATIONS
.group("/verifications", { authAdmin: true }, (app) => app
.group("/verifications", (app) => app
.get("/", async ({ query }) => {
return await s.Verifications.list({
filter: { status: query.status },
@@ -607,12 +635,14 @@ export const app = new Elysia()
offset: query.offset,
});
}, {
authAdmin: true,
query: t.Object({
status: t.Optional(VerificationStatusSchema),
limit: t.Optional(t.Numeric()),
offset: t.Optional(t.Numeric()),
})
})
// TODO: dev-only, unguarded so the bot can call it; restore admin/bot auth
.get("/:id", async ({ params: { id } }) => {
const verification = await s.Verifications.get(id);
if (!verification) return status(404, { error: "Verification not found" });
@@ -629,6 +659,7 @@ export const app = new Elysia()
}, {
params: t.Object({ id: BigIntIdSchema })
})
// TODO: dev-only, unguarded so the bot can call it; restore admin/bot auth
.post("/:id/request-action", async ({ params: { id }, body: { reviewerNotes, activityVerifications } }) => {
const updated = await s.Verifications.requestAction(id, reviewerNotes ?? null, activityVerifications);
if (updated) return updated;
@@ -643,8 +674,14 @@ export const app = new Elysia()
activityVerifications: ActivityVerificationsSchema,
})
})
.post("/:id/complete", async ({ params: { id }, body: { activityVerifications }, accountId }) => {
const updated = await s.Verifications.complete(id, accountId, activityVerifications);
// TODO: dev-only, unguarded so the bot can call it; restore admin/bot auth and drop completedBy from the body
.post("/:id/complete", async ({ params: { id }, body: { activityVerifications, completedBy }, jwt, cookie: { auth } }) => {
const portalSession = auth.value && await jwt.verify(auth.value);
const completerId = completedBy ?? (portalSession ? portalSession.accountId?.toString() : undefined);
const completer = completerId && await s.Accounts.get(completerId);
if (!completer || completer.role !== "admin") return status(403, { error: "Only a classmaster can complete a verification" });
const updated = await s.Verifications.complete(id, completer.id, activityVerifications);
if (updated) return updated;
const verification = await s.Verifications.get(id);
@@ -654,6 +691,7 @@ export const app = new Elysia()
params: t.Object({ id: BigIntIdSchema }),
body: t.Object({
activityVerifications: ActivityVerificationsSchema,
completedBy: t.Optional(AccountIdSchema),
})
})
)