From c3479499202c1c2c7d5fe95882a7949159a0e185 Mon Sep 17 00:00:00 2001
From: ajdj100
Date: Mon, 15 Sep 2025 21:02:32 -0400
Subject: [PATCH] added support for posting an LOA
---
api/index.js | 2 ++
api/routes/loa.js | 33 ++++++++++++++++++++++-
ui/src/api/loa.ts | 45 +++++++++++++++++++++++++++++++
ui/src/pages/LOA.vue | 63 +++++++++++++++++++++++++++++++++++++++-----
4 files changed, 135 insertions(+), 8 deletions(-)
create mode 100644 ui/src/api/loa.ts
diff --git a/api/index.js b/api/index.js
index 73d6699..2c1dd02 100644
--- a/api/index.js
+++ b/api/index.js
@@ -15,11 +15,13 @@ const port = 3000;
const applicationsRouter = require('./routes/applications');
const { memberRanks, ranks} = require('./routes/ranks');
const members = require('./routes/users');
+const loaHandler = require('./routes/loa')
app.use('/application', applicationsRouter);
app.use('/ranks', ranks);
app.use('/userRoles', memberRanks);
app.use('/members', members);
+app.use('/loa', loaHandler);
app.listen(port, () => {
console.log(`Example app listening on port ${port} `)
diff --git a/api/routes/loa.js b/api/routes/loa.js
index f818368..1e138a9 100644
--- a/api/routes/loa.js
+++ b/api/routes/loa.js
@@ -6,7 +6,38 @@ const pool = require('../db');
//post a new LOA
router.post("/", async (req, res) => {
-
+ const { member_id, filed_date, start_date, end_date, reason } = req.body;
+
+ if (!member_id || !filed_date || !start_date || !end_date) {
+ return res.status(400).json({ error: "Missing required fields" });
+ }
+
+ try {
+ const result = await pool.query(
+ `INSERT INTO leave_of_absences
+ (member_id, filed_date, start_date, end_date, reason)
+ VALUES (?, ?, ?, ?, ?)`,
+ [member_id, filed_date, start_date, end_date, reason]
+ );
+ res.sendStatus(201);
+ } catch (error) {
+ console.error(error);
+ res.status(500).send('Something went wrong', error);
+ }
+});
+
+//get my current LOA
+router.get("/me", async (req, res) => {
+ //TODO: implement current user getter
+ const user = 89;
+
+ try {
+ const result = await pool.query("SELECT * FROM leave_of_absences WHERE member_id = ?", [user])
+ res.status(200).json(result)
+ } catch (error) {
+ console.error(error);
+ res.status(500).send(error);
+ }
})
module.exports = router;
diff --git a/ui/src/api/loa.ts b/ui/src/api/loa.ts
new file mode 100644
index 0000000..3e10105
--- /dev/null
+++ b/ui/src/api/loa.ts
@@ -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 {
+ 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;
+ }
+}
diff --git a/ui/src/pages/LOA.vue b/ui/src/pages/LOA.vue
index 2225ab0..de8ef4e 100644
--- a/ui/src/pages/LOA.vue
+++ b/ui/src/pages/LOA.vue
@@ -1,7 +1,6 @@
@@ -62,7 +106,6 @@ onMounted(async () => {
Policy goes here.
-
@@ -113,10 +156,16 @@ onMounted(async () => {
-
+
-
+
+
{{ submitError }}
+
LOA submitted successfully!
\ No newline at end of file