update api : POST /api/audit
This commit is contained in:
parent
03b8b5e23e
commit
899e6d5852
23
api/audit.js
23
api/audit.js
@ -44,32 +44,21 @@ router.get("/", async function(req, res) {
|
|||||||
|
|
||||||
router.post("/", async function(req, res) {
|
router.post("/", async function(req, res) {
|
||||||
try {
|
try {
|
||||||
|
if (req.body.assistant_s_num.length >= 9) {
|
||||||
|
return res.json({suc : false, msg : "invalid credentials"})
|
||||||
|
}
|
||||||
let conn;
|
let conn;
|
||||||
try {
|
try {
|
||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
// data
|
// check the user is assitant
|
||||||
const apply_infos = req.body.apply_infos; // get data from request
|
|
||||||
const time = moment(new Date()).format("YYYY-MM-DD");
|
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
|
conn = await util.getDBConnection(); // get connection from db
|
||||||
await conn.beginTransaction();
|
await conn.beginTransaction();
|
||||||
|
|
||||||
// insert data into table : scholarship_application
|
// insert data into table : scholarship_application
|
||||||
const scholarship_audit_info = await conn.batch("INSERT INTO audit_form(``, ``) VALUES(?, ?);", [time, req.body.student_id]);
|
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_id = scholarship_audit_info.insertId; // get the application_id of previous record
|
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);
|
||||||
|
|
||||||
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
await conn.commit();
|
await conn.commit();
|
||||||
|
|
||||||
res.json({suc : true});
|
res.json({suc : true});
|
||||||
|
|||||||
@ -51,6 +51,7 @@ router.post("/", async function(req, res) {
|
|||||||
if (!stu_existed[0]["COUNT(*)"]) {
|
if (!stu_existed[0]["COUNT(*)"]) {
|
||||||
await conn.batch("INSERT INTO student VALUES(?, ?, ?, ?);", [student_id, department_and_grade, student_name, advisor_id]);
|
await conn.batch("INSERT INTO student VALUES(?, ?, ?, ?);", [student_id, department_and_grade, student_name, advisor_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert data into table : scholarship_application
|
// 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_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
|
const scholarship_application_id = scholarship_application_info.insertId; // get the application_id of previous record
|
||||||
|
|||||||
33
js/audit.js
33
js/audit.js
@ -3,6 +3,8 @@ let item_info_len = 0;
|
|||||||
let all_audit_data = null;
|
let all_audit_data = null;
|
||||||
let current_review_apllication_id;
|
let current_review_apllication_id;
|
||||||
const application_detail_init_table_content = document.getElementById("application_detail").innerHTML;
|
const application_detail_init_table_content = document.getElementById("application_detail").innerHTML;
|
||||||
|
let assistant_s_num;
|
||||||
|
let assistant_name;
|
||||||
|
|
||||||
async function getItemInfo() {
|
async function getItemInfo() {
|
||||||
// get the data from table : item_info
|
// get the data from table : item_info
|
||||||
@ -175,9 +177,9 @@ async function setAssistantName() {
|
|||||||
// get student name, and show on page
|
// get student name, and show on page
|
||||||
const queryString = window.location.search;
|
const queryString = window.location.search;
|
||||||
const urlParams = new URLSearchParams(queryString);
|
const urlParams = new URLSearchParams(queryString);
|
||||||
const s_num = urlParams.get("s_num");
|
assistant_s_num = urlParams.get("s_num");
|
||||||
const name = urlParams.get("name");
|
assistant_name = urlParams.get("name");
|
||||||
document.getElementById("assistant_name").innerHTML = name;
|
document.getElementById("assistant_name").innerHTML = assistant_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendApplyData() {
|
async function sendApplyData() {
|
||||||
@ -215,7 +217,32 @@ async function sendApplyData() {
|
|||||||
async function sendReviewResult() {
|
async function sendReviewResult() {
|
||||||
// send current review result of the application
|
// send current review result of the application
|
||||||
console.log(`send current review result of the application ${current_review_apllication_id}`);
|
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 的審核表的資料送去後端處理
|
// 你們這邊要將編號為 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();
|
setAssistantName();
|
||||||
|
|||||||
@ -46,18 +46,18 @@
|
|||||||
<h3>證明文件是否備齊</h3>
|
<h3>證明文件是否備齊</h3>
|
||||||
<div>
|
<div>
|
||||||
<label>
|
<label>
|
||||||
<input type="radio" id="checkbox_yes_${i}" value="yes"/> 是
|
<input type="radio" name="doc_checkbox" id="doc_checkbox_yes"/> 是
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
<input type="radio" id="checkbox_no_${i}" value="no"/> 否
|
<input type="radio" name="doc_checkbox" id="doc_checkbox_no"/> 否
|
||||||
</label>
|
</label>
|
||||||
,尚須補繳:<input type="text" id="unit_${i}"/>
|
,尚須補繳:<input type="text" id="missing_docs"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>學生事務委員會審核結果</h2>
|
<h2>學生事務委員會審核結果</h2>
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
<input type="radio" id="passed" value="passed">
|
<input type="radio" name="passed" id="passed">
|
||||||
<label >經</label>
|
<label >經</label>
|
||||||
會議名稱("學期-次數"):<input type="text" id="passedTimes" style="width: 50px;">,核發獎學金
|
會議名稱("學期-次數"):<input type="text" id="passedTimes" style="width: 50px;">,核發獎學金
|
||||||
<input type="number" id="scholarshipAmount" style="width: 100px;">元
|
<input type="number" id="scholarshipAmount" style="width: 100px;">元
|
||||||
@ -75,7 +75,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<input type="radio" id="notPassed" value="notPassed">
|
<input type="radio" name="passed" id="notPassed">
|
||||||
<label>未通過</label>
|
<label>未通過</label>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user