Ajust database schema to recent changes

This commit is contained in:
Clément Pons
2025-08-26 17:34:34 +02:00
parent da93fcd82d
commit 042d4479ee
17 changed files with 898 additions and 106 deletions

View File

@@ -1,8 +1,7 @@
import { and, eq, sql } from 'drizzle-orm';
import useDatabase from '~/composables/useDatabase';
import { characterTable } from '~/db/schema';
import { group } from '~/shared/general.util';
import type { Character, DoubleIndex, Level, MainStat, TrainingLevel } from '~/types/character';
import type { Character, CharacterVariables, Level, MainStat, TrainingLevel } from '~/types/character';
export default defineEventHandler(async (e) => {
const id = getRouterParam(e, "id");
@@ -26,9 +25,8 @@ export default defineEventHandler(async (e) => {
with: {
abilities: true,
levels: true,
modifiers: true,
spells: true,
training: true,
choices: true,
user: {
columns: { username: true }
}
@@ -46,15 +44,12 @@ export default defineEventHandler(async (e) => {
level: character.level,
aspect: character.aspect,
notes: character.notes,
health: character.health,
mana: character.mana,
variables: character.variables,
training: character.training.reduce((p, v) => { p[v.stat] ??= {}; p[v.stat][v.level as TrainingLevel] = v.choice; return p; }, {} as Record<MainStat, Partial<Record<TrainingLevel, number>>>),
leveling: character.levels.reduce((p, v) => { p[v.level as Level] = v.choice; return p; }, {} as Partial<Record<Level, number>>),
abilities: group(character.abilities.map(e => ({ ...e, value: e.value })), "ability", "value"),
spells: character.spells.map(e => e.value),
modifiers: group(character.modifiers, "modifier", "value"),
choices: {},
leveling: group(character.levels, "level", "choice"),
abilities: group(character.abilities, "ability", "value"),
choices: character.choices.reduce((p, v) => { p[v.id] ??= []; p[v.id]?.push(v.choice); return p; }, {} as Record<string, number[]>),
owner: character.owner,
username: character.user.username,