refactor: improve war module type safety and reserved turns test data handling

This commit is contained in:
2026-01-05 17:34:36 +00:00
parent 2e45a2d194
commit 44df19b079
10 changed files with 137 additions and 111 deletions
+22 -20
View File
@@ -17,14 +17,10 @@ const buildDb = () => {
type GeneralTurnFindManyArgs = Parameters<DatabaseClient['generalTurn']['findMany']>[0];
type GeneralTurnDeleteManyArgs = NonNullable<Parameters<DatabaseClient['generalTurn']['deleteMany']>[0]>;
type GeneralTurnCreateManyArgs = NonNullable<Parameters<DatabaseClient['generalTurn']['createMany']>[0]>;
type GeneralTurnCreateManyData = GeneralTurnCreateManyArgs['data'];
type GeneralTurnCreateManyRow = GeneralTurnCreateManyData extends Array<infer Row> ? Row : never;
type NationTurnFindManyArgs = Parameters<DatabaseClient['nationTurn']['findMany']>[0];
type NationTurnDeleteManyArgs = NonNullable<Parameters<DatabaseClient['nationTurn']['deleteMany']>[0]>;
type NationTurnCreateManyArgs = NonNullable<Parameters<DatabaseClient['nationTurn']['createMany']>[0]>;
type NationTurnCreateManyData = NationTurnCreateManyArgs['data'];
type NationTurnCreateManyRow = NationTurnCreateManyData extends Array<infer Row> ? Row : never;
const db = {
worldState: {
@@ -45,20 +41,23 @@ const buildDb = () => {
return generalId !== undefined ? (generalTurns.get(generalId) ?? []) : [];
},
deleteMany: async ({ where }: GeneralTurnDeleteManyArgs) => {
if (typeof where.generalId === 'number') {
if (where && typeof where.generalId === 'number') {
generalTurns.delete(where.generalId);
}
return {};
},
createMany: async ({ data }: GeneralTurnCreateManyArgs) => {
const rows = data.map((row: GeneralTurnCreateManyRow, index: number) => ({
const dataList = (Array.isArray(data) ? data : [data]) as Record<string, unknown>[];
const rows: GeneralTurnRow[] = dataList.map((row, index: number) => ({
id: index + 1,
generalId: row.generalId,
turnIdx: row.turnIdx,
actionCode: row.actionCode,
arg: row.arg,
generalId: row.generalId as number,
turnIdx: row.turnIdx as number,
actionCode: row.actionCode as string,
arg: row.arg as unknown as GeneralTurnRow['arg'],
createdAt: new Date(),
}));
const generalId = data[0]?.generalId;
const firstRow = dataList[0];
const generalId = firstRow?.generalId as number | undefined;
if (generalId !== undefined) {
generalTurns.set(generalId, rows);
}
@@ -76,22 +75,25 @@ const buildDb = () => {
return nationTurns.get(`${nationId}:${officerLevel}`) ?? [];
},
deleteMany: async ({ where }: NationTurnDeleteManyArgs) => {
if (typeof where.nationId === 'number' && typeof where.officerLevel === 'number') {
if (where && typeof where.nationId === 'number' && typeof where.officerLevel === 'number') {
nationTurns.delete(`${where.nationId}:${where.officerLevel}`);
}
return {};
},
createMany: async ({ data }: NationTurnCreateManyArgs) => {
const rows = data.map((row: NationTurnCreateManyRow, index: number) => ({
const dataList = (Array.isArray(data) ? data : [data]) as Record<string, unknown>[];
const rows: NationTurnRow[] = dataList.map((row, index: number) => ({
id: index + 1,
nationId: row.nationId,
officerLevel: row.officerLevel,
turnIdx: row.turnIdx,
actionCode: row.actionCode,
arg: row.arg,
nationId: row.nationId as number,
officerLevel: row.officerLevel as number,
turnIdx: row.turnIdx as number,
actionCode: row.actionCode as string,
arg: row.arg as unknown as NationTurnRow['arg'],
createdAt: new Date(),
}));
const nationId = data[0]?.nationId;
const officerLevel = data[0]?.officerLevel;
const firstRow = dataList[0];
const nationId = firstRow?.nationId as number | undefined;
const officerLevel = firstRow?.officerLevel as number | undefined;
if (nationId !== undefined && officerLevel !== undefined) {
nationTurns.set(`${nationId}:${officerLevel}`, rows);
}
+15 -14
View File
@@ -60,6 +60,7 @@ const handleLogout = async () => {
<div class="max-w-5xl mx-auto py-8 px-4 space-y-8">
<!-- Notice -->
<div v-if="notice" class="text-center">
<!-- eslint-disable-next-line vue/no-v-html -->
<span class="text-orange-500 text-3xl font-bold" v-html="notice"></span>
</div>
@@ -91,15 +92,15 @@ const handleLogout = async () => {
:style="{ color: profile.color }"
class="text-lg font-bold cursor-help"
:title="
profileDetails[profile.profileName]
? `시작일: ${profileDetails[profile.profileName].starttime}`
profileDetails[profile.profileName]?.starttime
? `시작일: ${profileDetails[profile.profileName]?.starttime}`
: ''
"
>
{{ profile.korName }}
</div>
<div v-if="profileDetails[profile.profileName]" class="text-xs text-zinc-500 mt-1">
&lt;{{ profileDetails[profile.profileName].nationCnt }} 경쟁중&gt;
&lt;{{ profileDetails[profile.profileName]?.nationCnt }} 경쟁중&gt;
</div>
</td>
@@ -108,25 +109,25 @@ const handleLogout = async () => {
<template v-if="profileDetails[profile.profileName]">
<div class="space-y-1">
<div>
서기 {{ profileDetails[profile.profileName].year }}
{{ profileDetails[profile.profileName].month }} (<span
서기 {{ profileDetails[profile.profileName]?.year }}
{{ profileDetails[profile.profileName]?.month }} (<span
class="text-orange-400"
>{{ profile.scenario }}</span
>)
</div>
<div class="text-zinc-400">
유저 : {{ profileDetails[profile.profileName].userCnt }} /
{{ profileDetails[profile.profileName].maxUserCnt }}
유저 : {{ profileDetails[profile.profileName]?.userCnt }} /
{{ profileDetails[profile.profileName]?.maxUserCnt }}
<span class="text-cyan-400 ml-2"
>NPC : {{ profileDetails[profile.profileName].npcCnt }}</span
>NPC : {{ profileDetails[profile.profileName]?.npcCnt }}</span
>
<span class="text-green-400 ml-2"
>({{ profileDetails[profile.profileName].turnTerm }} 서버)</span
>({{ profileDetails[profile.profileName]?.turnTerm }} 서버)</span
>
</div>
<div class="text-xs text-zinc-500">
(상성 설정:{{ profileDetails[profile.profileName].fictionMode }}), (기타
설정:{{ profileDetails[profile.profileName].otherTextInfo }})
(상성 설정:{{ profileDetails[profile.profileName]?.fictionMode }}), (기타
설정:{{ profileDetails[profile.profileName]?.otherTextInfo }})
</div>
</div>
</template>
@@ -145,14 +146,14 @@ const handleLogout = async () => {
class="w-12 h-12 mx-auto bg-zinc-800 rounded overflow-hidden border border-zinc-700"
>
<img
:src="profileDetails[profile.profileName].myGeneral.picture"
:src="profileDetails[profile.profileName]?.myGeneral?.picture ?? undefined"
class="w-full h-full object-cover"
/>
</div>
</td>
<td class="px-4 py-4 border-r border-zinc-800 text-center">
<div v-if="profileDetails[profile.profileName]?.myGeneral" class="font-medium">
{{ profileDetails[profile.profileName].myGeneral.name }}
{{ profileDetails[profile.profileName]?.myGeneral?.name }}
</div>
<div v-else class="text-zinc-600">- -</div>
</td>
@@ -161,7 +162,7 @@ const handleLogout = async () => {
<td class="px-4 py-4 text-center">
<template v-if="profileDetails[profile.profileName]">
<button
v-if="profileDetails[profile.profileName].myGeneral"
v-if="profileDetails[profile.profileName]?.myGeneral"
class="w-full bg-zinc-700 hover:bg-zinc-600 text-white py-1.5 rounded text-sm transition-colors"
>
입장