diff --git a/api/audit.js b/api/audit.js index 83f98da..760d91b 100644 --- a/api/audit.js +++ b/api/audit.js @@ -44,32 +44,21 @@ router.get("/", async function(req, res) { router.post("/", async function(req, res) { try { + if (req.body.assistant_s_num.length >= 9) { + return res.json({suc : false, msg : "invalid credentials"}) + } let conn; try { console.log(req.body); - // data - const apply_infos = req.body.apply_infos; // get data from request + // check the user is assitant const time = moment(new Date()).format("YYYY-MM-DD"); - if (!assistant_id) { - throw new Error("Assistant ID is missing in the request body."); - } - conn = await util.getDBConnection(); // get connection from db await conn.beginTransaction(); // insert data into table : scholarship_application - const scholarship_audit_info = await conn.batch("INSERT INTO audit_form(``, ``) VALUES(?, ?);", [time, req.body.student_id]); - const scholarship_audit_id = scholarship_audit_info.insertId; // get the application_id of previous record - - - console.log(scholarship_audit_info.insertId); - console.log(apply_infos); - - // insert each apply item into item_form - for (let i = 0;i < apply_infos.length;i++) { - await conn.batch("INSERT INTO item_form(`application_id`, `item_info_id`, `application_unit`, `subsidy`) VALUES(?, ?, ?, ?);", [scholarship_application_id, apply_infos[i], application_unit, subsidy]); - } + const data = [req.body.assistant_s_num, req.body.application_id, req.body.documents_ready, req.body.committee_review, req.body.meeting_name, req.body.passed_date, req.body.scholarship_amount]; + const scholarship_audit_info = await conn.batch("INSERT INTO audit_form(`assistant_id`, `application_id`, `documents_ready`, `committee_review`, `meeting_name`, `passed_date`, `scholarship_amount`) VALUES(?, ?, ?, ?, ?, ?, ?);", data); await conn.commit(); res.json({suc : true}); diff --git a/api/main.js b/api/main.js index 89f05ef..dc411fe 100644 --- a/api/main.js +++ b/api/main.js @@ -51,6 +51,7 @@ router.post("/", async function(req, res) { if (!stu_existed[0]["COUNT(*)"]) { await conn.batch("INSERT INTO student VALUES(?, ?, ?, ?);", [student_id, department_and_grade, student_name, advisor_id]); } + // insert data into table : scholarship_application const scholarship_application_info = await conn.batch("INSERT INTO scholarship_application(`application_date`, `student_id`) VALUES(?, ?);", [time, student_id]); const scholarship_application_id = scholarship_application_info.insertId; // get the application_id of previous record diff --git a/js/audit.js b/js/audit.js index a57ef14..5976234 100644 --- a/js/audit.js +++ b/js/audit.js @@ -3,6 +3,8 @@ let item_info_len = 0; let all_audit_data = null; let current_review_apllication_id; const application_detail_init_table_content = document.getElementById("application_detail").innerHTML; +let assistant_s_num; +let assistant_name; async function getItemInfo() { // get the data from table : item_info @@ -175,9 +177,9 @@ async function setAssistantName() { // get student name, and show on page const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); - const s_num = urlParams.get("s_num"); - const name = urlParams.get("name"); - document.getElementById("assistant_name").innerHTML = name; + assistant_s_num = urlParams.get("s_num"); + assistant_name = urlParams.get("name"); + document.getElementById("assistant_name").innerHTML = assistant_name; } async function sendApplyData() { @@ -215,7 +217,32 @@ async function sendApplyData() { async function sendReviewResult() { // send current review result of the application console.log(`send current review result of the application ${current_review_apllication_id}`); + let data = {assistant_s_num, "application_id" : current_review_apllication_id}; + // 你們這邊要將編號為 current_review_apllication_id 的審核表的資料送去後端處理 + const doc_missing = document.getElementById("doc_checkbox_no").checked; + + if (doc_missing) { + data["documents_ready"] = document.getElementById("missing_docs").value; + } + + const is_passed = document.getElementById("passed").checked; + data["committee_review"] = is_passed; + if (is_passed) { + data["meeting_name"] = document.getElementById("passedTimes").value; + data["scholarship_amount"] = document.getElementById("scholarshipAmount").value; + data["passed_date"] = document.getElementById("passed_date").value; + } + + console.log(data); + const result = await axios.post("/api/audit", data); + if (result.data.suc) { + alert("審核成功!"); + } + else { + alert("審核失敗!", result.data.msg); + } + window.location.reload(); } setAssistantName(); diff --git a/templates/audit.html b/templates/audit.html index 4bd13d1..ac95a76 100644 --- a/templates/audit.html +++ b/templates/audit.html @@ -46,18 +46,18 @@

證明文件是否備齊

- ,尚須補繳: + ,尚須補繳:

學生事務委員會審核結果

- + 會議名稱("學期-次數"):,核發獎學金 元 @@ -75,7 +75,7 @@
- +