diff --git a/api/audit.js b/api/audit.js new file mode 100644 index 0000000..623b533 --- /dev/null +++ b/api/audit.js @@ -0,0 +1,89 @@ +// Required modules +const router = require('express').Router(); +const util = require("./../utilities/utilities_main.js"); +const moment = require("moment"); + +router.get("/", async function(req, res) { + try { + let conn; + try { + conn = await util.getDBConnection(); // get connection from db + const query = ` //語法有問題 + SELECT + item_form.application_id, + item_form.item_info_id, + item_form.application_unit, + item_form.subsidy, + scholarship_application.application_date, + scholarship_application.student_id, + student.student_name + FROM + item_form + RIGHT JOIN + scholarship_application ON item_form.application_id = scholarship_application.application_id; + RIGHT JOIN + student ON scholarship_application.student_id = student.student_id; + `; + const result = await conn.query(query); + res.json({ success: true, data: result }); + } + catch(e) { + console.error(e); + res.json({suc : false}); + } + finally { + util.closeDBConnection(conn); // close db connection + } + } + catch(e) { + console.log(e); + } +}) + +router.post("/", async function(req, res) { + try { + let conn; + try { + console.log(req.body); + // data + const apply_infos = req.body.apply_infos; // get data from request + 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]); + } + await conn.commit(); + + res.json({suc : true}); + } + catch(e) { + console.error(e); + await conn.rollback(); + res.json({suc : false}); + } + finally { + util.closeDBConnection(conn); // close db connection + } + } + catch(e) { + console.log(e); + } +}) + +module.exports = router; \ No newline at end of file diff --git a/api/login.js b/api/login.js index bb38a79..38ec3b2 100644 --- a/api/login.js +++ b/api/login.js @@ -1,6 +1,6 @@ // Required modules const router = require('express').Router(); -const util = require("./../utilities/utilities.js"); +const util = require("./../utilities/utilities_main.js"); const jwt = require('jsonwebtoken'); router.post("/", async function(req, res) { diff --git a/api/main.js b/api/main.js index 7428bd7..28cad07 100644 --- a/api/main.js +++ b/api/main.js @@ -33,6 +33,10 @@ router.post("/", async function(req, res) { const apply_infos = req.body.apply_infos; // get data from request const time = moment(new Date()).format("YYYY-MM-DD"); + if (!student_id) { + throw new Error("Student ID is missing in the request body."); + } + conn = await util.getDBConnection(); // get connection from db await conn.beginTransaction(); diff --git a/db.js b/db.js index 88079bd..7a0dceb 100644 --- a/db.js +++ b/db.js @@ -27,7 +27,7 @@ const db = require("mariadb"); // create pool const pool = db.createPool({ - connectionLimit : 500, + connectionLimit : 10, host : 'localhost', user : 'user', password : '', diff --git a/index.js b/index.js index 52d0961..0b423fd 100644 --- a/index.js +++ b/index.js @@ -16,13 +16,15 @@ app.use(cookieParser()); //解析 HTTP 請求的 cookie // // pages +app.use("/example", require("./pages/example.js")); +app.use("/main", require("./pages/main.js")); -// app.use("/login", require("./pages/login.js")); -// app.use("/apply", require("./pages/apply.js")); ++app.use("/login", require("./pages/login.js")); ++app.use("/apply", require("./pages/apply.js")); ++app.use("/audit", require("./pages/audit.js")); // // api -// app.use("/api/login", require("./api/login.js")); +app.use("/api/login", require("./api/login.js")); app.use("/api/example", require("./api/example.js")); app.use("/api/main", require("./api/main.js")); +app.use("/api/audit", require("./api/audit.js")); // // static files app.use('/js', express.static('./js')); app.use('/css', express.static('./css')); @@ -48,70 +50,9 @@ app.get('/', (req, res) => { console.log(`Example app listening at http://localhost:${port}`) }) -// // 設定 view engine -// app.set('view engine', 'ejs') -// // 建立 todos data -// const todos = [ -// 'first todo', 'second todo', 'third todo' -// ] - -// app.get('/todos', (req, res) => { -// // 第二個參數可傳入資料 -// res.render('todos', { -// todos // todos: todos 一樣的話可省略寫法 -// }) -// }) - -// // 加上 :id 代表不確定的參數 -// app.get('/todos/:id', (req, res) => { -// // params: 可拿到網址列上指定的參數 -// const id = req.params.id -// const todo = todos[id] -// res.render('todo', { -// todo -// }) -// }) - -// app.get('/', (req, res) => { -// //res.send('index') -// }) - -// app.get('/main.ejs', (req, res) => { -// // 叫 express 去 render views 底下叫做 hello 的檔案,副檔名可省略 -// //res.render('hello') -// }) - -// app.listen(port, () => { -// console.log(`listening at http://localhost:${port}`) -// }) -// // 引入 controller -// const todoController = require('./controllers/todo') - -// app.set('view engine', 'ejs') - -// const todos = [ -// 'first todo', 'second todo', 'third todo' -// ] - -// // 可直接使用 controller 的方法拿取資料和進行 render -// app.get('/todos', todoController.getAll) - -// app.get('/todos/:id',) -// const todoController = require('./controllers/todo') - -// app.set('view engine', 'ejs') - -// app.get('/todos',) -// app.get('/todos/:id', todoController.get) - -// app.listen(port, () => { -// // 連線資料庫 -// db.connect() -// console.log(`Example app listening at http://localhost:${port}`) -// }) \ No newline at end of file diff --git a/js/audit.js b/js/audit.js new file mode 100644 index 0000000..463ef44 --- /dev/null +++ b/js/audit.js @@ -0,0 +1,121 @@ +let item_info_len = 0; + +async function getItemInfo() { + // get the data from table : item_info + try { + let result = await axios.get('/api/audit'); + result = result.data; + return result; + } + catch (e) { + console.error(e); + return null; + } +} + +async function putDataInTable(table_id) { + // get data + const data = await getItemInfo(); + if (data != null && table_id != null) { + // insert data into table + let table_content = document.getElementById(table_id).innerHTML; + + for (let i = 0; i < data.length; i++) { + + table_content += ` + + ${data[i].item_content} +
+ `; + } + `

證明文件是否備齊

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

學生事務委員會審核結果

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

+ ` + // write back data into table + document.getElementById(table_id).innerHTML = table_content; + // set info length + item_info_len = data.length; + } + else { + console.error("data and table id can not be null"); + } +} + +async function setAssistantName() { + // get student name, and show on page + document.getElementById("assistant_name").innerHTML = "test"; +} + +async function sendApplyData() { + // get student name + const student_name = document.getElementById("assistant_name").value; + + // get checked infos + let apply_infos = []; + let application_units = []; + let subsidy_amounts = []; + for (let i = 0; i < item_info_len; i++) { + if (document.getElementById(`checkbox_${i}`).checked) { + apply_infos.push(i + 1); + // get unit、subsidy + if (document.getElementById(`unit_${i}`) && document.getElementById(`subsidy_${i}`)) { + application_units.push(document.getElementById(`unit_${i}`).value); + subsidy_amounts.push(document.getElementById(`subsidy_${i}`).value); + } else { + application_units.push(null); + subsidy_amounts.push(null); + } + } + } + + const data = {student_id,student_name,department_and_grade, advisor_name, + apply_infos, + application_units, + subsidy_amounts + }; + // send data + let result = await axios.post('/api/main', data); + console.log(result); +} + +putDataInTable("info_item"); \ No newline at end of file diff --git a/js/main.js b/js/main.js index ba11358..dc3f99a 100644 --- a/js/main.js +++ b/js/main.js @@ -23,24 +23,36 @@ async function putDataInTable(table_id) { for (let i = 0; i < data.length; i++) { if (i === 2 || i === 3 || i === 10 || i === 11) { table_content += ` - +
${data[i].item_content} -
申請單位:
-
獲得補助金額:
- `; + ,申請單位: + 獲得補助金額:NT$ +
`; } else if (i === 4 || i === 5 || i === 12 || i === 13) { table_content += ` ${data[i].item_content} -
申請單位:
+ ,申請單位: +
`; - } else { + } else if(i===data.length-1){ table_content += ` ${data[i].item_content} + +
+
+ `; + } + else { + table_content += ` + + + ${data[i].item_content} +
`; } } @@ -55,17 +67,17 @@ async function putDataInTable(table_id) { } } -// async function setStudentName() { -// // get student name, and show on page -// document.getElementById("student_name").innerHTML = "test"; -// } +async function setStudentName() { + // get student name, and show on page + document.getElementById("student_name").innerHTML = "test"; +} async function sendApplyData() { // get student name - const student_name = document.getElementById("student_name").innerHTML; - const student_id = document.getElementById("student_id").innerHTML; - const department_and_grade = document.getElementById("department_and_grade").innerHTML; - const advisor_name = document.getElementById("advisor_name").innerHTML; + const student_name = document.getElementById("student_name").value; + const student_id = document.getElementById("student_id").value; + const department_and_grade = document.getElementById("department_and_grade").value; + const advisor_name = document.getElementById("advisor_name").value; // get checked infos let apply_infos = []; let application_units = []; diff --git a/pages/audit.js b/pages/audit.js new file mode 100644 index 0000000..02a3547 --- /dev/null +++ b/pages/audit.js @@ -0,0 +1,17 @@ +const router = require('express').Router(); +const { error } = require('console'); +const util = require("./../utilities/utilities_main.js"); + +// processing request +router.get('/', async function(req, res) { + try { + res.sendFile(util.getParentPath(__dirname) + '/templates/audit.html'); + } + catch(e) { + console.log(e); + res.json({error_msg : "failed to access the file"}); + } + return; +}); + +module.exports = router; diff --git a/templates/audit.html b/templates/audit.html new file mode 100644 index 0000000..a7ef5b8 --- /dev/null +++ b/templates/audit.html @@ -0,0 +1,41 @@ + + + + + 國立暨南國際大學資管系獎學金審核表 + + +

國立暨南國際大學資管系獎學金審核表

+ + +
+
+ + +
+
+
+ + +
+
+
+

申請資料

+
+
+
+

審核區

+
+ + +
+ + + + \ No newline at end of file diff --git a/templates/main.html b/templates/main.html index 89a21da..739c474 100644 --- a/templates/main.html +++ b/templates/main.html @@ -54,12 +54,22 @@

申請項目及說明

- - - - - -
是否申請項目內容
+
+ +
+ +
+
+ + + +

+ 說明:
+ 一、依據「國立暨南國際大學資訊管理學系獎助學金作業要點」辦理。
+ 二、申辦流程:由學生詳填本申請書並檢附相關證明文件,逕送系辦審查資料是否齊全,提交學生事務委員會審核後,由系辦通知申請學生核定結果(獎學金將逕行撥入申請學生帳戶)。
+ 三、獲得本系獎助學金補助者須提供申請事項之詳細資訊,供系上公告與相關宣傳使用。若後續有召開分享會等相關需要,獲補助者需配合辦理。 + +