Add patient personalization: profile saved once, reused every chat turn
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user