46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
export type LOARequest = {
|
|
member_id: number;
|
|
filed_date: string; // ISO 8601 string
|
|
start_date: string; // ISO 8601 string
|
|
end_date: string; // ISO 8601 string
|
|
reason?: string;
|
|
};
|
|
// @ts-ignore
|
|
const addr = import.meta.env.VITE_APIHOST;
|
|
|
|
export async function submitLOA(request: LOARequest): Promise<{ id?: number; error?: string }> {
|
|
const res = await fetch(`${addr}/loa`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(request),
|
|
});
|
|
|
|
if (res.ok) {
|
|
return res.json();
|
|
} else {
|
|
return { error: "Failed to submit LOA" };
|
|
}
|
|
}
|
|
|
|
export async function getMyLOA(): Promise<LOARequest | null> {
|
|
const res = await fetch(`${addr}/loa/me`, {
|
|
method: "GET",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
});
|
|
|
|
|
|
if (res.ok) {
|
|
const out = res.json();
|
|
if (!out) {
|
|
return null;
|
|
}
|
|
return out;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|