Setting up calculator config management
This commit is contained in:
@@ -20,12 +20,27 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
// INDEX: ONE_ACTIVE_PRODUCT_SYNC
|
// INDEX: ONE_ACTIVE_PRODUCT_SYNC
|
||||||
await db.schema.createIndex("idx_one_active_product_sync")
|
await db.schema.createIndex("idx_one_active_product_sync")
|
||||||
.on("product_syncs")
|
.on("product_syncs")
|
||||||
.unique()
|
|
||||||
.column("ended_at")
|
.column("ended_at")
|
||||||
|
.unique()
|
||||||
.where(sql.ref("started_at"), "is not", null)
|
.where(sql.ref("started_at"), "is not", null)
|
||||||
.where("ended_at", "is", null)
|
.where("ended_at", "is", null)
|
||||||
.nullsNotDistinct()
|
.nullsNotDistinct()
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
// TABLE: CALCULATOR_CONFIGS
|
||||||
|
await db.schema.createTable("calculator_configs")
|
||||||
|
.$call(addDefaultColumns)
|
||||||
|
.addColumn("parameters", "jsonb", (cb) => cb.notNull())
|
||||||
|
.addColumn("is_selected", "boolean", (cb) => cb.notNull())
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
// INDEX: ONE_SELECTED_CALCULATOR_CONFIG
|
||||||
|
await db.schema.createIndex("idx_one_selected_calculator_config")
|
||||||
|
.on("calculator_configs")
|
||||||
|
.column("is_selected")
|
||||||
|
.unique()
|
||||||
|
.where("is_selected", "=", true)
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
@@ -34,4 +49,10 @@ export async function down(db: Kysely<any>): Promise<void> {
|
|||||||
|
|
||||||
// INDEX: ONE_ACTIVE_PRODUCT_SYNC
|
// INDEX: ONE_ACTIVE_PRODUCT_SYNC
|
||||||
await db.schema.dropIndex("idx_one_active_product_sync").ifExists().execute();
|
await db.schema.dropIndex("idx_one_active_product_sync").ifExists().execute();
|
||||||
|
|
||||||
|
// TABLE: CALCULATOR_CONFIGS
|
||||||
|
await db.schema.dropTable("calculator_configs").ifExists().execute()
|
||||||
|
|
||||||
|
// INDEX: ONE_SELECTED_CALCULATOR_CONFIG
|
||||||
|
await db.schema.dropIndex("idx_one_selected_calculator_config").ifExists().execute();
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-13
@@ -96,6 +96,7 @@ export const app = new Elysia()
|
|||||||
status
|
status
|
||||||
}, "request");
|
}, "request");
|
||||||
})
|
})
|
||||||
|
.guard({ cookie: t.Cookie({ auth: t.Optional(t.String()) }) })
|
||||||
|
|
||||||
.get("/", () => ({ status: "ok" }))
|
.get("/", () => ({ status: "ok" }))
|
||||||
.get("/health", () => ({ status: "ok" }))
|
.get("/health", () => ({ status: "ok" }))
|
||||||
@@ -115,24 +116,30 @@ export const app = new Elysia()
|
|||||||
".bladeandbrawn.com" :
|
".bladeandbrawn.com" :
|
||||||
undefined
|
undefined
|
||||||
});
|
});
|
||||||
}, {
|
}, { body: t.Object({ password: t.String() }) })
|
||||||
body: t.Object({ password: t.String() }),
|
|
||||||
cookie: t.Cookie({ auth: t.Optional(t.String()) })
|
|
||||||
})
|
|
||||||
|
|
||||||
// CALCULATOR
|
// CALCULATOR
|
||||||
.post("/calculate", async ({ body }) => {
|
.group("/calculator",
|
||||||
return { levels: levelCalculator.calculate(body.player, body.activityPerformances) };
|
(app) => app
|
||||||
}, {
|
.post("/calculate", async ({ body }) => {
|
||||||
body: t.Object({
|
return { levels: levelCalculator.calculate(body.player, body.activityPerformances) };
|
||||||
player: PlayerSchema,
|
}, {
|
||||||
activityPerformances: t.Array(ActivityPerformanceSchema)
|
body: t.Object({
|
||||||
}),
|
player: PlayerSchema,
|
||||||
})
|
activityPerformances: t.Array(ActivityPerformanceSchema)
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
.resolve(async ({ jwt, cookie: { auth } }) => {
|
||||||
|
const token = auth.value && await jwt.verify(auth.value);
|
||||||
|
if (!token || !token.sessionId) throw status(401, "Unauthorized");
|
||||||
|
return { sessionId: token.sessionId.toString() };
|
||||||
|
})
|
||||||
|
.post("/config", () => { })
|
||||||
|
.get("/config", () => { })
|
||||||
|
)
|
||||||
|
|
||||||
// COMMERCE
|
// COMMERCE
|
||||||
.group("/products",
|
.group("/products",
|
||||||
{ cookie: t.Cookie({ auth: t.Optional(t.String()) }) },
|
|
||||||
(app) => app
|
(app) => app
|
||||||
.resolve(async ({ jwt, cookie: { auth } }) => {
|
.resolve(async ({ jwt, cookie: { auth } }) => {
|
||||||
const token = auth.value && await jwt.verify(auth.value);
|
const token = auth.value && await jwt.verify(auth.value);
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export class CalculatorService {
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user