Validate on Linux Node 22 and PostgreSQL 17: 3894 frontend tests and 64 database tests pass, with no removed test names or new failures. Preserve static Home, bounded gzip, assertion-change records and manual acceptance gaps. Co-Authored-By: Claude Code <noreply@anthropic.com>
41 lines
2.0 KiB
TypeScript
41 lines
2.0 KiB
TypeScript
import { resolveMissingBirthTimezoneOffset } from "./birth-profile-timezone.ts";
|
|
import { resolveReportBirthClock } from "./personal-report-route-core.ts";
|
|
import { PersonalReportWorkerError } from "./personal-report-worker-core.ts";
|
|
import { ConsultationSubjectError, loadSubjectBirth } from "./subject-birth.ts";
|
|
|
|
export async function loadReportWorkerProfile(client: unknown, userId: string, subjectId: string): Promise<unknown> {
|
|
try {
|
|
const resolved = await loadSubjectBirth(client, userId, subjectId);
|
|
if (!resolved.chartable) throw new PersonalReportWorkerError("profile_incomplete", false);
|
|
let row = resolved.row;
|
|
if (resolved.role === "self") {
|
|
// Case linkage is worker metadata, not a second source of birth data.
|
|
const metadataClient = client as { from: (table: string) => {
|
|
select: (columns: string) => { eq: (column: string, value: string) => {
|
|
maybeSingle: () => PromiseLike<{ data: { rectification_case_id?: unknown } | null; error: unknown }>;
|
|
} };
|
|
} };
|
|
const { data, error } = await metadataClient.from("profiles")
|
|
.select("rectification_case_id").eq("id", userId).maybeSingle();
|
|
if (error) throw new PersonalReportWorkerError("profile_incomplete", true);
|
|
row = { ...row, rectification_case_id: data?.rectification_case_id ?? null };
|
|
}
|
|
return await resolveMissingBirthTimezoneOffset(row, { useActiveDate: true });
|
|
} catch (error) {
|
|
if (error instanceof ConsultationSubjectError) {
|
|
// Missing/deleted/foreign subjects are terminal and release the existing
|
|
// reservation. A temporary database outage may retry, never as self.
|
|
throw new PersonalReportWorkerError("profile_incomplete", error.code === "subject_unavailable");
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
export function reportWorkerUsesCandidateRange(
|
|
report: { chartProfileId: string | null },
|
|
profile: Record<string, unknown>,
|
|
): boolean {
|
|
return (!report.chartProfileId || report.chartProfileId === "self")
|
|
&& resolveReportBirthClock(profile)?.status !== "confirmed";
|
|
}
|