refactor: improve type definitions and enhance state management in profile and daily components

This commit is contained in:
2026-03-14 16:31:16 +01:00
parent 4e95abf09f
commit e5a21cb0af
5 changed files with 139 additions and 76 deletions

View File

@@ -1,5 +1,5 @@
import { db } from '$lib/server/db';
import { arc, character, characterHistory, characterOverride, devilFruit } from '$lib/server/db/schema';
import { arc, character, characterHistory, characterOverride, devilFruit, type Character, type CharacterOverride } from '$lib/server/db/schema';
import { desc, eq, inArray, and } from 'drizzle-orm';
// Generate or get random seed for daily character selection
@@ -29,14 +29,12 @@ const characterWithRelationsSelect = {
arcName: arc.name
};
export type CharacterWithRelations = typeof character.$inferSelect & {
export type CharacterWithRelations = Character & {
devilFruitName: string | null;
devilFruitType: string | null;
arcName: string | null;
};
type CharacterOverrideRow = typeof characterOverride.$inferSelect;
type RelationMaps = {
arcNameById: Map<string, string | null>;
devilFruitById: Map<string, { name: string | null; type: string | null }>;
@@ -48,7 +46,7 @@ function isNotNullish<T>(value: T | null | undefined): value is T {
function mergeCharacterWithOverride(
baseCharacter: CharacterWithRelations,
overrideRow?: CharacterOverrideRow,
overrideRow?: CharacterOverride,
relationMaps?: RelationMaps
): CharacterWithRelations {
if (!overrideRow) {
@@ -104,7 +102,7 @@ async function applyCharacterOverrides(
return characters;
}
const overrideByCharacterId = new Map<string, CharacterOverrideRow>(
const overrideByCharacterId = new Map<string, CharacterOverride>(
overrideRows.map((overrideRow) => [overrideRow.characterId, overrideRow])
);