added support for posting an LOA
This commit is contained in:
45
ui/src/api/loa.ts
Normal file
45
ui/src/api/loa.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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;
|
||||
};
|
||||
|
||||
const addr = "localhost:3000";
|
||||
|
||||
export async function submitLOA(request: LOARequest): Promise<{ id?: number; error?: string }> {
|
||||
const res = await fetch(`http://${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(`http://${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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user