Files
Jyotisha/frontend/src/lib/personal-report-worker-subject.ts
T
jesse-uxandClaude Code 4d801e53c3
Independent Staging Quality Gate / validate (push) Successful in 16m28s
Independent Staging Quality Gate / publish (push) Successful in 3m33s
fix: integrate people archive, report reader and western chart corrections
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>
2026-09-25 20:41:16 +08:00

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";
}