Add patient personalization: profile saved once, reused every chat turn

This commit is contained in:
2026-08-25 11:55:13 +07:00
parent 501c226ecd
commit 1ddd878431
12 changed files with 548 additions and 6 deletions
+26 -1
View File
@@ -1,4 +1,9 @@
import type { AuthUser, LoginRequest } from "@duoc-thu/shared-types";
import type {
AuthUser,
LoginRequest,
PatientProfile,
PatientProfileUpdate,
} from "@duoc-thu/shared-types";
export class AuthError extends Error {
constructor(readonly status: number) {
@@ -34,3 +39,23 @@ export async function me(): Promise<AuthUser | null> {
if (!response.ok) throw new AuthError(response.status);
return (await response.json()) as AuthUser;
}
/** Returns `null` on 401, same "not logged in is not an error" rule as `me`. */
export async function getPatientProfile(): Promise<PatientProfile | null> {
const response = await fetch("/api/patient-profile");
if (response.status === 401) return null;
if (!response.ok) throw new AuthError(response.status);
return (await response.json()) as PatientProfile;
}
export async function savePatientProfile(
update: PatientProfileUpdate
): Promise<PatientProfile> {
const response = await fetch("/api/patient-profile", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(update),
});
if (!response.ok) throw new AuthError(response.status);
return (await response.json()) as PatientProfile;
}