Skip to content

Commit

Permalink
feat: 新增匯出預排課表pdf
Browse files Browse the repository at this point in the history
1. storeData暫存使用者預排課表

fix: 修正無法匯出查詢結果

因更改匯出function,需用到"req.query"
所以用成object放query傳入function
  • Loading branch information
Chinlinlee committed Jan 11, 2021
1 parent 883570d commit 7ccd5cb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
18 changes: 13 additions & 5 deletions routes/api/pdfmake/controller/get_pdfmake.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ const pdfMakePrinter = require('pdfmake');
const My_Course_Search_Func = require('./Course_Search_Func.js');
const fs = require('fs');
const pdfmake_func = require('./pdfmake_func.js');
const { getData } = require('./get_storeData');

module.exports = async function (req ,res)
{
var data = await pdfmake_func.Get_Data(req);
if (data.includes('err'))
{
res.status(500).send('Error:' + data);
return ;
let data;
if (req.query.IsPreSchedule == "true") {
data = getData(req);
data = [data];
} else {
data = await pdfmake_func.Get_Data(req);
if (data.includes('err'))
{
res.status(500).send('Error:' + data);
return ;
}
}

/* else
{
data = JSON.parse(data);
Expand Down
10 changes: 10 additions & 0 deletions routes/api/pdfmake/controller/get_storeData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = function (req , res) {
return res.json(getData(req));
}


function getData (req) {
return req.session.storeData;
}

module.exports.getData = getData;
19 changes: 4 additions & 15 deletions routes/api/pdfmake/controller/pdfmake_func.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@ module.exports.Get_Data = async function(req)

return new Promise (async (resolve)=>
{
return resolve(await getCourseSearch(JSON.parse(query)));
request(
{
url : "https://www.chinstudio.icu/api/Course_Search" ,
method : "GET" ,
qs : JSON.parse(query)
} , function (err , response , body)
{
if (err)
{
console.log("err : " + err);
return resolve("err:" + err);
}
return resolve(body);
})
let newReq = {
query : JSON.parse(query)
}
return resolve(await getCourseSearch(newReq));
});
}

Expand Down
4 changes: 4 additions & 0 deletions routes/api/pdfmake/controller/post_storeData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function (req , res) {
req.session.storeData = req.body.data;
res.end();
}
2 changes: 2 additions & 0 deletions routes/api/pdfmake/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ router.get('/' , require('./controller/get_pdfmake'));
router.get('/docx' , require('./controller/get_docx'));
router.get('/xlsx' , require('./controller/get_xlsx'));
router.post('/picture' , require('./controller/post_picture'));
router.post('/storeData' , require('./controller/post_storeData'));
router.get('/storeData' , require('./controller/get_storeData'));
module.exports = router;

0 comments on commit 7ccd5cb

Please sign in to comment.