Files
milsim-site-v4/ui/src/api/loa.ts
2025-11-19 21:32:12 -05:00

63 lines
1.4 KiB
TypeScript

export type LOARequest = {
id?: number;
name?: string;
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;
}
}
export function getAllLOAs(): Promise<LOARequest[]> {
return fetch(`${addr}/loa/all`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).then((res) => {
if (res.ok) {
return res.json();
} else {
return [];
}
});
}