Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01e9ac8403 | ||
|
|
dbcfb6900b |
+34
-2
@@ -10,7 +10,7 @@ import {
|
|||||||
Printful,
|
Printful,
|
||||||
Webflow,
|
Webflow,
|
||||||
} from "@blade-and-brawn/commerce";
|
} from "@blade-and-brawn/commerce";
|
||||||
import { DEFAULT_NAME, DUMMY_PASSWORD_HASH, env, log, sha256Sum } from "./util";
|
import { DEFAULT_NAME, DUMMY_PASSWORD_HASH, env, log } from "./util";
|
||||||
import serverTiming from "@elysia/server-timing";
|
import serverTiming from "@elysia/server-timing";
|
||||||
import jwt from "@elysia/jwt";
|
import jwt from "@elysia/jwt";
|
||||||
import { CommerceService, WOrderStatusSchema } from "./services/commerce";
|
import { CommerceService, WOrderStatusSchema } from "./services/commerce";
|
||||||
@@ -22,6 +22,7 @@ import { StandardsService } from "./services/standards";
|
|||||||
import { EventsService, EventStatusSchema } from "./services/events";
|
import { EventsService, EventStatusSchema } from "./services/events";
|
||||||
import { AccountsService, type AccountRole } from "./services/accounts";
|
import { AccountsService, type AccountRole } from "./services/accounts";
|
||||||
import { Value } from "@sinclair/typebox/value";
|
import { Value } from "@sinclair/typebox/value";
|
||||||
|
import { AssessmentsService } from "./services/assessments";
|
||||||
|
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
// -----------------------
|
// -----------------------
|
||||||
@@ -37,7 +38,8 @@ const s = (() => {
|
|||||||
const Commerce = new CommerceService();
|
const Commerce = new CommerceService();
|
||||||
const Accounts = new AccountsService(Calculator);
|
const Accounts = new AccountsService(Calculator);
|
||||||
const Events = new EventsService();
|
const Events = new EventsService();
|
||||||
return { Standards, Calculator, Commerce, Accounts, Events };
|
const Assessments = new AssessmentsService();
|
||||||
|
return { Standards, Calculator, Commerce, Accounts, Events, Assessments };
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// QUEUES
|
// QUEUES
|
||||||
@@ -476,6 +478,36 @@ export const app = new Elysia()
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ASSESSMENTS
|
||||||
|
.group("/assessments", (app) => app
|
||||||
|
.guard({ auth: true }, (app) => app
|
||||||
|
.post("/me", async ({ body: { player, activityPerformances }, accountId }) => {
|
||||||
|
await s.Assessments.create(player, activityPerformances, accountId);
|
||||||
|
}, {
|
||||||
|
body: t.Object({
|
||||||
|
player: PlayerSchema,
|
||||||
|
activityPerformances: t.Array(ActivityPerformanceSchema)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.get("/me", async ({ accountId }) => {
|
||||||
|
const assessments = await s.Assessments.list({ filter: { accountId } });
|
||||||
|
if (!assessments) throw new NotFoundError("Assessments not found");
|
||||||
|
return assessments;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.guard({ authAdmin: true }, (app) => app
|
||||||
|
.post("/", async ({ body: { player, activityPerformances, id } }) => {
|
||||||
|
await s.Assessments.create(player, activityPerformances, id);
|
||||||
|
}, {
|
||||||
|
body: t.Object({
|
||||||
|
player: PlayerSchema,
|
||||||
|
activityPerformances: t.Array(ActivityPerformanceSchema),
|
||||||
|
id: t.Optional(t.String()),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
// WEBHOOKS
|
// WEBHOOKS
|
||||||
.post("/webhooks/printful", async ({ body, query }) => {
|
.post("/webhooks/printful", async ({ body, query }) => {
|
||||||
// https://webflow.com/integrations/printful
|
// https://webflow.com/integrations/printful
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { Activity, type ActivityPerformance, type Player } from "@blade-and-brawn/domain";
|
||||||
|
import { db } from "../database/db";
|
||||||
|
|
||||||
|
export class AssessmentsService {
|
||||||
|
async create(player: Player, activityPerformances: ActivityPerformance[], accountId?: string) {
|
||||||
|
const performanceFor = (activity: Activity) =>
|
||||||
|
activityPerformances.find((p) => p.activity === activity)?.performance ?? null;
|
||||||
|
|
||||||
|
return await db.insertInto("assessments")
|
||||||
|
.values({
|
||||||
|
account_id: accountId ?? null,
|
||||||
|
name: player.name ?? "Anonymous",
|
||||||
|
age: player.metrics.age,
|
||||||
|
weight: player.metrics.weight,
|
||||||
|
gender: player.metrics.gender,
|
||||||
|
perf_back_squat: performanceFor(Activity.BackSquat),
|
||||||
|
perf_deadlift: performanceFor(Activity.Deadlift),
|
||||||
|
perf_bench_press: performanceFor(Activity.BenchPress),
|
||||||
|
perf_broad_jump: performanceFor(Activity.BroadJump),
|
||||||
|
perf_run: performanceFor(Activity.Run),
|
||||||
|
perf_cone_drill: performanceFor(Activity.ConeDrill),
|
||||||
|
})
|
||||||
|
.returning("id")
|
||||||
|
.executeTakeFirstOrThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
async list(opt: {
|
||||||
|
filter?: { accountId?: string },
|
||||||
|
limit?: number,
|
||||||
|
offset?: number,
|
||||||
|
} = {}) {
|
||||||
|
return await db.selectFrom("assessments")
|
||||||
|
.selectAll()
|
||||||
|
.$if(opt.filter?.accountId !== undefined, (qb) => qb
|
||||||
|
.where("account_id", "=", opt.filter!.accountId!)
|
||||||
|
)
|
||||||
|
.orderBy("created_at", "desc")
|
||||||
|
.$if(opt.limit !== undefined, (qb) => qb.limit(opt.limit!))
|
||||||
|
.$if(opt.offset !== undefined, (qb) => qb.offset(opt.offset!))
|
||||||
|
.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
"@elysia/eden": "^1.4.10",
|
"@elysia/eden": "^1.4.10",
|
||||||
"@tailwindcss/vite": "^4.3.3",
|
"@tailwindcss/vite": "^4.3.3",
|
||||||
"daisyui": "^5.7.20",
|
"daisyui": "^5.7.20",
|
||||||
"jose": "^6.2.9",
|
"jose": "^6.2.10",
|
||||||
"tailwindcss": "^4.3.3"
|
"tailwindcss": "^4.3.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@
|
|||||||
"@elysia/eden": "^1.4.10",
|
"@elysia/eden": "^1.4.10",
|
||||||
"@tailwindcss/vite": "^4.3.3",
|
"@tailwindcss/vite": "^4.3.3",
|
||||||
"daisyui": "^5.7.20",
|
"daisyui": "^5.7.20",
|
||||||
"jose": "^6.2.9",
|
"jose": "^6.2.10",
|
||||||
"tailwindcss": "^4.3.3",
|
"tailwindcss": "^4.3.3",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -461,7 +461,7 @@
|
|||||||
|
|
||||||
"esm-env": ["esm-env@1.2.2", "", {}, "sha512-Epxrv+Nr/CaL4ZcFGPJIYLWFom+YeV1DqMLHJoEd9SYRxNbaFruBwfEX/kkHUJf55j2+TUbmDcmuilbP1TmXHA=="],
|
"esm-env": ["esm-env@1.2.2", "", {}, "sha512-Epxrv+Nr/CaL4ZcFGPJIYLWFom+YeV1DqMLHJoEd9SYRxNbaFruBwfEX/kkHUJf55j2+TUbmDcmuilbP1TmXHA=="],
|
||||||
|
|
||||||
"esrap": ["esrap@2.3.5", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.4.15" }, "peerDependencies": { "@typescript-eslint/types": "^8.2.0" }, "optionalPeers": ["@typescript-eslint/types"] }, "sha512-KciPkeZZX8srrh6xELzLR2cBaWOzgBQ4CwggO6Dh/KMlrfOcIcfyXCVy/Vvc3/OlS5gvFOd5tcxUYuaGM8o45A=="],
|
"esrap": ["esrap@2.3.6", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.4.15" }, "peerDependencies": { "@typescript-eslint/types": "^8.2.0" }, "optionalPeers": ["@typescript-eslint/types"] }, "sha512-yc0OC12UjPqLoc+fe+v5GNs4TOjAigUw3sTikfC+xeBPGUw7gDRz3DtYaqEhxyMVJojcSWJw7jT0QWR+CbuE/A=="],
|
||||||
|
|
||||||
"exact-mirror": ["exact-mirror@0.2.7", "", { "peerDependencies": { "@sinclair/typebox": "^0.34.15" }, "optionalPeers": ["@sinclair/typebox"] }, "sha512-+MeEmDcLA4o/vjK2zujgk+1VTxPR4hdp23qLqkWfStbECtAq9gmsvQa3LW6z/0GXZyHJobrCnmy1cdeE7BjsYg=="],
|
"exact-mirror": ["exact-mirror@0.2.7", "", { "peerDependencies": { "@sinclair/typebox": "^0.34.15" }, "optionalPeers": ["@sinclair/typebox"] }, "sha512-+MeEmDcLA4o/vjK2zujgk+1VTxPR4hdp23qLqkWfStbECtAq9gmsvQa3LW6z/0GXZyHJobrCnmy1cdeE7BjsYg=="],
|
||||||
|
|
||||||
@@ -501,7 +501,7 @@
|
|||||||
|
|
||||||
"jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="],
|
"jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="],
|
||||||
|
|
||||||
"jose": ["jose@6.2.9", "", {}, "sha512-XrchZOFZUl/T3vTwRe8XK+cJrGtMF4th1ARnDfwbBXFKThGhlsxEE4Zu03AD/bjJSt/9jT/mxrOCkJWOg77aPA=="],
|
"jose": ["jose@6.2.10", "", {}, "sha512-iiW7J9qRFlGxvCOIBDBDxFePQSn7ZMAnrYGhrrOo6siO/MIqwfyilLR27pkfDgUk+raLuzADS8A3S/KLBisc0g=="],
|
||||||
|
|
||||||
"joycon": ["joycon@3.1.1", "", {}, "sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw=="],
|
"joycon": ["joycon@3.1.1", "", {}, "sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw=="],
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user