Get stats command to console log the current users stats
This commit is contained in:
@@ -70,9 +70,11 @@ async function seedCalculator(standardsConfigId: string): Promise<void> {
|
||||
}
|
||||
|
||||
async function seedAccounts(): Promise<void> {
|
||||
const ACCOUNT_NAME = "Xominus";
|
||||
|
||||
const existing = await db.selectFrom("accounts")
|
||||
.select(["id"])
|
||||
.where("name", "=", DEFAULT_NAME)
|
||||
.where("name", "=", ACCOUNT_NAME)
|
||||
.executeTakeFirst();
|
||||
if (existing) {
|
||||
log.info({ id: existing.id }, "default account already seeded, skipping");
|
||||
@@ -81,9 +83,9 @@ async function seedAccounts(): Promise<void> {
|
||||
|
||||
const account = await db.insertInto("accounts")
|
||||
.values({
|
||||
name: DEFAULT_NAME,
|
||||
discord_id: "1521640671721685157",
|
||||
email: "outgrow_document040@simplelogin.com"
|
||||
name: ACCOUNT_NAME,
|
||||
discord_id: "1325552430942916731",
|
||||
email: "xominus@bladeandbrawn.com"
|
||||
})
|
||||
.returning("id")
|
||||
.executeTakeFirstOrThrow();
|
||||
@@ -92,7 +94,7 @@ async function seedAccounts(): Promise<void> {
|
||||
await db.insertInto("assessments")
|
||||
.values({
|
||||
account_id: account.id,
|
||||
name: DEFAULT_NAME,
|
||||
name: ACCOUNT_NAME,
|
||||
gender: Gender.Male,
|
||||
age: 25,
|
||||
weight: 80,
|
||||
|
||||
@@ -7,10 +7,16 @@ import { t } from "elysia";
|
||||
export class AccountsService {
|
||||
constructor(private Calculator: CalculatorService) { }
|
||||
|
||||
private static idComparison(id: string): ["accounts.id" | "accounts.discord_id", "=", string] {
|
||||
return id.startsWith("@")
|
||||
? ["accounts.discord_id", "=", id.slice(1)]
|
||||
: ["accounts.id", "=", id];
|
||||
}
|
||||
|
||||
async get(id: string) {
|
||||
return await (db).selectFrom("accounts")
|
||||
.selectAll()
|
||||
.where("id", "=", id)
|
||||
.where(...AccountsService.idComparison(id))
|
||||
.executeTakeFirst();
|
||||
}
|
||||
|
||||
@@ -22,7 +28,7 @@ export class AccountsService {
|
||||
"assessments.perf_back_squat", "assessments.perf_bench_press", "assessments.perf_broad_jump",
|
||||
"assessments.perf_cone_drill", "assessments.perf_deadlift", "assessments.perf_run"
|
||||
])
|
||||
.where("accounts.id", "=", id)
|
||||
.where(...AccountsService.idComparison(id))
|
||||
.orderBy("assessments.created_at", "desc")
|
||||
.limit(1)
|
||||
.executeTakeFirst();
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import type { Message } from "discord.js";
|
||||
import type { Command } from "../service";
|
||||
import { api } from "../../../util";
|
||||
|
||||
export default {
|
||||
name: "stats",
|
||||
description: "View your fitness statistics!",
|
||||
execute: async (message: Message) => {
|
||||
console.log("Stats executed");
|
||||
const res = await api.accounts({ id: `@${message.author.id}` }).stats.get();
|
||||
const stats = res.data;
|
||||
console.log(stats);
|
||||
}
|
||||
} as Command;
|
||||
|
||||
Reference in New Issue
Block a user