fix(housekeeping): restore people partial compatibility
CI / check (pull_request) Successful in 42s
CI / release (pull_request) Skipped
CI / deploy (pull_request) Skipped

This commit is contained in:
Simo committed 2026-08-29 21:03:43 +02:00
1 parent fcd1dfd96e
commit a6a288d9ff
6 files changed
+412 -11

No files matched your search

+41 -9
View File
@@ -52,6 +52,35 @@ function failedIds(value: unknown): Array<{ userId: number; reason: string }> {
: [];
}
function legacyBulkOutcome(
after: Readonly<Record<string, unknown>> | null,
userIds: readonly number[],
): {
readonly completed: number;
readonly total: number;
readonly failedIds: Array<{ userId: number; reason: string }>;
} {
const databaseFailures = failedIds(after?.failedIds);
const externalSyncFailures = failedIds(after?.externalSyncFailures).map(
({ userId }) => ({ userId, reason: "Database error" }),
);
const pendingFailures = [...databaseFailures, ...externalSyncFailures];
const orderedFailures = userIds.flatMap((userId) => {
const index = pendingFailures.findIndex(
(failure) => failure.userId === userId,
);
return index === -1 ? [] : pendingFailures.splice(index, 1);
});
return {
completed: Math.max(
0,
numberValue(after?.completed) - externalSyncFailures.length,
),
total: numberValue(after?.total),
failedIds: [...orderedFailures, ...pendingFailures],
};
}
export async function bulkUnban({
userIds,
}: {
@@ -113,12 +142,13 @@ export async function bulkGiveCurrency({
type,
});
if (!result.ok) return { ok: false, error: "Bulk currency failed" };
const outcome = legacyBulkOutcome(result.data.after, userIds);
return {
ok: true,
data: {
given: numberValue(result.data.after?.completed),
total: numberValue(result.data.after?.total),
failedIds: failedIds(result.data.after?.failedIds),
given: outcome.completed,
total: outcome.total,
failedIds: outcome.failedIds,
},
};
}
@@ -142,12 +172,13 @@ export async function bulkGiveBadge({
badgeCode,
});
if (!result.ok) return { ok: false, error: "Bulk badge failed" };
const outcome = legacyBulkOutcome(result.data.after, userIds);
return {
ok: true,
data: {
given: numberValue(result.data.after?.completed),
total: numberValue(result.data.after?.total),
failedIds: failedIds(result.data.after?.failedIds),
given: outcome.completed,
total: outcome.total,
failedIds: outcome.failedIds,
},
};
}
@@ -178,12 +209,13 @@ export async function bulkAdjustCurrency({
type,
});
if (!result.ok) return { ok: false, error: "Currency adjustment failed" };
const outcome = legacyBulkOutcome(result.data.after, userIds);
return {
ok: true,
data: {
adjusted: numberValue(result.data.after?.completed),
total: numberValue(result.data.after?.total),
failedIds: failedIds(result.data.after?.failedIds),
adjusted: outcome.completed,
total: outcome.total,
failedIds: outcome.failedIds,
},
};
}