From 7ccd5cb7fbcfa1e885a1cad1ff5716a65397fc85 Mon Sep 17 00:00:00 2001 From: chin Date: Mon, 11 Jan 2021 17:38:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=8C=AF=E5=87=BA?= =?UTF-8?q?=E9=A0=90=E6=8E=92=E8=AA=B2=E8=A1=A8pdf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. storeData暫存使用者預排課表 fix: 修正無法匯出查詢結果 因更改匯出function,需用到"req.query" 所以用成object放query傳入function --- routes/api/pdfmake/controller/get_pdfmake.js | 18 +++++++++++++----- .../api/pdfmake/controller/get_storeData.js | 10 ++++++++++ routes/api/pdfmake/controller/pdfmake_func.js | 19 ++++--------------- .../api/pdfmake/controller/post_storeData.js | 4 ++++ routes/api/pdfmake/index.js | 2 ++ 5 files changed, 33 insertions(+), 20 deletions(-) create mode 100644 routes/api/pdfmake/controller/get_storeData.js create mode 100644 routes/api/pdfmake/controller/post_storeData.js diff --git a/routes/api/pdfmake/controller/get_pdfmake.js b/routes/api/pdfmake/controller/get_pdfmake.js index 196fa18..8660334 100644 --- a/routes/api/pdfmake/controller/get_pdfmake.js +++ b/routes/api/pdfmake/controller/get_pdfmake.js @@ -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); diff --git a/routes/api/pdfmake/controller/get_storeData.js b/routes/api/pdfmake/controller/get_storeData.js new file mode 100644 index 0000000..9d8a471 --- /dev/null +++ b/routes/api/pdfmake/controller/get_storeData.js @@ -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; \ No newline at end of file diff --git a/routes/api/pdfmake/controller/pdfmake_func.js b/routes/api/pdfmake/controller/pdfmake_func.js index 3897358..4421e86 100644 --- a/routes/api/pdfmake/controller/pdfmake_func.js +++ b/routes/api/pdfmake/controller/pdfmake_func.js @@ -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)); }); } diff --git a/routes/api/pdfmake/controller/post_storeData.js b/routes/api/pdfmake/controller/post_storeData.js new file mode 100644 index 0000000..f6604a1 --- /dev/null +++ b/routes/api/pdfmake/controller/post_storeData.js @@ -0,0 +1,4 @@ +module.exports = function (req , res) { + req.session.storeData = req.body.data; + res.end(); +} \ No newline at end of file diff --git a/routes/api/pdfmake/index.js b/routes/api/pdfmake/index.js index a900b4b..bd9173d 100644 --- a/routes/api/pdfmake/index.js +++ b/routes/api/pdfmake/index.js @@ -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;