fix: repair missing reported birth-time status

This commit is contained in:
Jesse_Chen
2026-07-26 13:14:14 +08:00
parent 5f492be1b9
commit cdf7a76766
6 changed files with 146 additions and 9 deletions
+1 -3
View File
@@ -163,9 +163,7 @@ export async function PATCH(request: Request) {
if (currentProfileError) {
return NextResponse.json({ error: "暂时无法核对现有出生资料" }, { status: 500 });
}
const applicationPatch = currentProfile
? resolveAccountBirthTimeApplicationPatch(currentProfile, payload)
: {};
const applicationPatch = resolveAccountBirthTimeApplicationPatch(currentProfile, payload);
const baseProfile = {
id: userId,
...(payload.name !== undefined ? { name: payload.name } : {}),
+19 -5
View File
@@ -235,17 +235,31 @@ export type AccountBirthTimeApplicationPatch = Readonly<{
}>;
export function resolveAccountBirthTimeApplicationPatch(
current: AccountBirthTimeState,
current: AccountBirthTimeState | null,
patch: AccountProfilePatch,
): AccountBirthTimeApplicationPatch {
const declarationChanged = declarationFields.some((field) => (
patch[field] !== undefined && patch[field] !== current[field]
));
if (!declarationChanged) return {};
if (!current) {
return patch.birth_time_source ? {
active_birth_time: null,
birth_time: null,
birth_time_status: "reported",
rectification_case_id: null,
} : {};
}
const confirmed = current.birth_time_status === "confirmed"
|| (current.birth_time_status === null && isBirthClockTime(current.birth_time ?? ""));
if (confirmed) return {};
const declarationChanged = declarationFields.some((field) => (
patch[field] !== undefined && patch[field] !== current[field]
));
const repairsMissingStatus = current.birth_time_status === null
&& current.active_birth_time === null
&& current.birth_time === null
&& current.rectification_case_id === null
&& Boolean(patch.birth_time_source);
if (!declarationChanged && !repairsMissingStatus) return {};
return {
active_birth_time: null,
birth_time: null,