Harden sortie item save recovery

This commit is contained in:
2026-07-05 09:36:25 +09:00
parent 2256669719
commit 7185566b5d
2 changed files with 11 additions and 6 deletions

View File

@@ -991,17 +991,17 @@ function normalizeReserveTrainingSnapshot(value: unknown): CampaignReserveTraini
};
}
function normalizeSortieItemAssignments(assignments?: CampaignSortieItemAssignments) {
function normalizeSortieItemAssignments(assignments?: Record<string, unknown>) {
return Object.entries(assignments ?? {}).reduce<CampaignSortieItemAssignments>((next, [unitId, stocks]) => {
const unitStocks = Object.entries(stocks ?? {}).reduce<Record<string, number>>((nextStocks, [itemId, amount]) => {
const normalizedAmount = Math.floor(Number(amount));
const unitStocks = Object.entries(recordOrEmpty(stocks)).reduce<Record<string, number>>((nextStocks, [itemId, amount]) => {
const normalizedAmount = normalizeNonNegativeInteger(amount);
if (itemId && normalizedAmount > 0) {
nextStocks[itemId] = normalizedAmount;
}
return nextStocks;
}, {});
if (Object.keys(unitStocks).length > 0) {
if (unitId && Object.keys(unitStocks).length > 0) {
next[unitId] = unitStocks;
}
return next;