feat: expose archived general histories

This commit is contained in:
2026-07-29 00:05:18 +00:00
parent 1181f6f4e0
commit d621023508
9 changed files with 537 additions and 43 deletions
@@ -1,5 +1,6 @@
import { asRecord, HALL_OF_FAME_TYPES, type HallOfFameType } from '@sammo-ts/common';
import type { GamePrisma, InputJsonValue } from '@sammo-ts/infra';
import { LogCategory, LogScope } from '@sammo-ts/logic';
import type { GeneralLifecycleEvent } from './inMemoryWorld.js';
@@ -260,10 +261,20 @@ const archiveDeletedGeneral = async (
): Promise<void> => {
const serverId =
typeof worldMeta.serverId === 'string' && worldMeta.serverId.trim() ? worldMeta.serverId.trim() : 'default';
const history = await prisma.logEntry.findMany({
where: {
generalId: event.generalId,
scope: LogScope.GENERAL,
category: LogCategory.HISTORY,
},
orderBy: { id: 'desc' },
select: { text: true },
});
const data = {
...event.before,
turnTime: event.before.turnTime.toISOString(),
recentWarTime: event.before.recentWarTime?.toISOString() ?? null,
history: history.map((entry) => entry.text),
};
await prisma.oldGeneral.upsert({
where: { by_no: { serverId, generalNo: event.generalId } },
@@ -651,6 +651,26 @@ export const createUnificationHandler = (options: {
const oldGeneralTargets = generalRows.filter(
(general) => general.nationId === 0 || general.nationId === winnerNationId
);
const generalHistoryRows = oldGeneralTargets.length
? await prisma.logEntry.findMany({
where: {
generalId: { in: oldGeneralTargets.map((general) => general.id) },
scope: LogScope.GENERAL,
category: LogCategory.HISTORY,
},
orderBy: { id: 'desc' },
select: { generalId: true, text: true },
})
: [];
const historyByGeneral = new Map<number, string[]>();
for (const row of generalHistoryRows) {
if (row.generalId === null) {
continue;
}
const history = historyByGeneral.get(row.generalId) ?? [];
history.push(row.text);
historyByGeneral.set(row.generalId, history);
}
await Promise.all(
oldGeneralTargets.map((general) =>
((snapshot) =>
@@ -680,6 +700,7 @@ export const createUnificationHandler = (options: {
}))({
...general,
turnTime: general.turnTime.toISOString(),
history: historyByGeneral.get(general.id) ?? [],
})
)
);