Add a verification interface for review

This commit is contained in:
Dominic Ferrando
2026-09-19 17:57:52 -04:00
parent f593aabd25
commit dc7ebd6873
6 changed files with 772 additions and 4 deletions
@@ -0,0 +1,95 @@
import { Activity, Gender, inToCm, lbToKg, minToMs, secToMs } from "@blade-and-brawn/domain";
import { db } from "../database/db";
import { env, log } from "../util";
import type { AccountRole } from "../services/accounts";
import { VerificationsService } from "../services/verifications";
const TEST_DISCORD_ID = "test-verification-seed";
const TEST_ASSESSMENT_NAME = "Test Verification Player";
async function seedTestAccount(): Promise<string> {
const existing = await db.selectFrom("accounts")
.select("id")
.where("discord_id", "=", TEST_DISCORD_ID)
.executeTakeFirst();
if (existing) {
log.info({ id: existing.id }, "test account already seeded, reusing");
return existing.id;
}
const account = await db.insertInto("accounts")
.values({
discord_id: TEST_DISCORD_ID,
name: "Test Player",
role: "user" satisfies AccountRole,
})
.returning("id")
.executeTakeFirstOrThrow();
log.info({ id: account.id }, "seeded test account");
return account.id;
}
async function seedTestAssessment(accountId: string): Promise<string> {
const existing = await db.selectFrom("assessments")
.select("id")
.where("account_id", "=", accountId)
.where("name", "=", TEST_ASSESSMENT_NAME)
.executeTakeFirst();
if (existing) {
log.info({ id: existing.id }, "test assessment already seeded, reusing");
return existing.id;
}
const result = await db.insertInto("assessments")
.values({
account_id: accountId,
name: TEST_ASSESSMENT_NAME,
gender: Gender.Male,
age: 22,
weight: lbToKg(180),
perf_back_squat: lbToKg(225),
perf_deadlift: lbToKg(315),
perf_bench_press: lbToKg(185),
perf_broad_jump: inToCm(96),
perf_run: minToMs(7) + secToMs(30),
perf_cone_drill: secToMs(7),
})
.returning("id")
.executeTakeFirstOrThrow();
log.info({ id: result.id }, "seeded test assessment");
return result.id;
}
(async () => {
const answer = prompt(`Seed a test verification request in the database (${env.DATABASE_URL})? (y/N)`);
if (answer?.trim().toLowerCase() !== "y") {
log.info("Aborted");
await db.destroy();
return;
}
try {
const accountId = await seedTestAccount();
const assessmentId = await seedTestAssessment(accountId);
const verifications = new VerificationsService();
const verification = await verifications.request(assessmentId, accountId, {
[Activity.BackSquat]: "https://example.com/videos/back-squat.mp4",
[Activity.Deadlift]: "https://example.com/videos/deadlift.mp4",
[Activity.BenchPress]: "https://example.com/videos/bench-press.mp4",
[Activity.Run]: "https://example.com/videos/run.mp4",
[Activity.BroadJump]: "https://example.com/videos/broad-jump.mp4",
[Activity.ConeDrill]: "https://example.com/videos/cone-drill.mp4",
});
if (!verification) throw new Error("Failed to seed verification request — assessment ownership check failed");
log.info({ id: verification.id, assessmentId, accountId }, "seeded test verification request");
}
catch (err) {
log.error({ err }, "seed failed");
process.exit(1);
}
finally {
await db.destroy();
}
})();