From 7ab06b6a4c8ac67652b32e763bbc9a690c50b10f Mon Sep 17 00:00:00 2001 From: ajdj100 Date: Thu, 11 Dec 2025 12:06:00 -0500 Subject: [PATCH] hooked up new LOA creation system --- api/src/routes/loa.ts | 2 ++ api/src/services/loaService.ts | 3 ++- shared/types/loa.ts | 8 ++++---- ui/src/components/loa/loaForm.vue | 16 ++++++++++++++-- ui/src/pages/ManageLOA.vue | 12 ------------ 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/api/src/routes/loa.ts b/api/src/routes/loa.ts index 7bd9492..8602b38 100644 --- a/api/src/routes/loa.ts +++ b/api/src/routes/loa.ts @@ -11,6 +11,7 @@ router.post("/", async (req: Request, res: Response) => { let LOARequest = req.body as LOARequest; LOARequest.member_id = req.user.id; LOARequest.created_by = req.user.id; + LOARequest.filed_date = new Date(); console.log(LOARequest); @@ -27,6 +28,7 @@ router.post("/", async (req: Request, res: Response) => { router.post("/admin", async (req: Request, res: Response) => { let LOARequest = req.body as LOARequest; LOARequest.created_by = req.user.id; + LOARequest.filed_date = new Date(); console.log(LOARequest); diff --git a/api/src/services/loaService.ts b/api/src/services/loaService.ts index ae65128..1261a1e 100644 --- a/api/src/services/loaService.ts +++ b/api/src/services/loaService.ts @@ -1,3 +1,4 @@ +import { toDateTime } from "@app/shared/utils/time"; import pool from "../db"; import { LOARequest, LOAType } from '@app/shared/types/loa' @@ -24,6 +25,6 @@ export async function createNewLOA(data: LOARequest) { const sql = `INSERT INTO leave_of_absences (member_id, filed_date, start_date, end_date, type_id, reason) VALUES (?, ?, ?, ?, ?, ?)`; - await pool.query(sql, [data.member_id, data.filed_date, data.start_date, data.end_date, data.type_id, data.reason]) + await pool.query(sql, [data.member_id, toDateTime(data.filed_date), toDateTime(data.start_date), toDateTime(data.end_date), data.type_id, data.reason]) return; } \ No newline at end of file diff --git a/shared/types/loa.ts b/shared/types/loa.ts index c87bf87..4eae0dc 100644 --- a/shared/types/loa.ts +++ b/shared/types/loa.ts @@ -1,10 +1,10 @@ export interface LOARequest { id?: number; member_id?: number; - filed_date?: string; // ISO 8601 string - start_date: string; // ISO 8601 string - end_date: string; // ISO 8601 string - extended_till?: string; + filed_date?: Date; // ISO 8601 string + start_date: Date; // ISO 8601 string + end_date: Date; // ISO 8601 string + extended_till?: Date; type_id?: number; reason?: string; expired?: boolean; diff --git a/ui/src/components/loa/loaForm.vue b/ui/src/components/loa/loaForm.vue index f66b2f7..1ae6063 100644 --- a/ui/src/components/loa/loaForm.vue +++ b/ui/src/components/loa/loaForm.vue @@ -20,7 +20,7 @@ import PopoverContent from "@/components/ui/popover/PopoverContent.vue"; import { cn } from "@/lib/utils"; import { CalendarIcon } from "lucide-vue-next" import Textarea from "@/components/ui/textarea/Textarea.vue"; -import { getLoaPolicy, getLoaTypes, submitLOA } from "@/api/loa"; // <-- import the submit function +import { adminSubmitLOA, getLoaPolicy, getLoaTypes, submitLOA } from "@/api/loa"; // <-- import the submit function import { LOARequest, LOAType } from "@shared/types/loa"; import { useForm, Field as VeeField } from "vee-validate"; import { @@ -68,8 +68,20 @@ const { handleSubmit, values, resetForm } = useForm({ validationSchema: toTypedSchema(loaSchema), }) -const onSubmit = handleSubmit((values) => { +const onSubmit = handleSubmit(async (values) => { console.log(values); + const out: LOARequest = { + member_id: values.member_id, + start_date: values.start_date, + end_date: values.end_date, + type_id: values.type.id, + reason: values.reason + }; + if (props.adminMode) { + await adminSubmitLOA(out); + } else { + await submitLOA(out); + } }) onMounted(async () => { diff --git a/ui/src/pages/ManageLOA.vue b/ui/src/pages/ManageLOA.vue index be94973..1b073e1 100644 --- a/ui/src/pages/ManageLOA.vue +++ b/ui/src/pages/ManageLOA.vue @@ -28,18 +28,6 @@ const showLOADialog = ref(false); - -