Add VerificationsService with some basic methods
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { Activity, type ActivityVideoUrls } from "@blade-and-brawn/domain";
|
||||
import { db } from "../database/db";
|
||||
|
||||
export type VerificationStatus = "request" | "in_review" | "action_required" | "completed";
|
||||
|
||||
export class VerificationsService {
|
||||
async request(assessmentId: string, activityVideoUrls: ActivityVideoUrls) {
|
||||
return await db.insertInto("verifications")
|
||||
.values({
|
||||
assessment_id: assessmentId,
|
||||
status: "request" satisfies VerificationStatus,
|
||||
url_back_squat: activityVideoUrls[Activity.BackSquat] ?? null,
|
||||
url_deadlift: activityVideoUrls[Activity.Deadlift] ?? null,
|
||||
url_bench_press: activityVideoUrls[Activity.BenchPress] ?? null,
|
||||
url_broad_jump: activityVideoUrls[Activity.BroadJump] ?? null,
|
||||
url_run: activityVideoUrls[Activity.Run] ?? null,
|
||||
url_cone_drill: activityVideoUrls[Activity.ConeDrill] ?? null,
|
||||
})
|
||||
.onConflict((oc) => oc
|
||||
.column("assessment_id")
|
||||
.doUpdateSet((eb) => ({
|
||||
status: "request" satisfies VerificationStatus,
|
||||
url_back_squat: eb.ref("excluded.url_back_squat"),
|
||||
url_deadlift: eb.ref("excluded.url_deadlift"),
|
||||
url_bench_press: eb.ref("excluded.url_bench_press"),
|
||||
url_broad_jump: eb.ref("excluded.url_broad_jump"),
|
||||
url_run: eb.ref("excluded.url_run"),
|
||||
url_cone_drill: eb.ref("excluded.url_cone_drill"),
|
||||
// Re-requesting means new videos are under review, so the
|
||||
// previous cycle's per-activity judgments and completion
|
||||
// info no longer apply.
|
||||
verf_back_squat: null,
|
||||
verf_deadlift: null,
|
||||
verf_bench_press: null,
|
||||
verf_broad_jump: null,
|
||||
verf_run: null,
|
||||
verf_cone_drill: null,
|
||||
completed_at: null,
|
||||
completed_by: null,
|
||||
}))
|
||||
)
|
||||
.returning("id")
|
||||
.executeTakeFirstOrThrow();
|
||||
}
|
||||
|
||||
async list(opt: {
|
||||
filter?: { status?: VerificationStatus },
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
} = {}) {
|
||||
return await db.selectFrom("verifications")
|
||||
.selectAll()
|
||||
.$if(opt.filter?.status !== undefined, (qb) => qb
|
||||
.where("status", "=", opt.filter!.status!)
|
||||
)
|
||||
.orderBy("created_at", "desc")
|
||||
.$if(opt.limit !== undefined, (qb) => qb.limit(opt.limit!))
|
||||
.$if(opt.offset !== undefined, (qb) => qb.offset(opt.offset!))
|
||||
.execute();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user