diff --git a/src/controllers/certificate.js b/src/controllers/certificate.js index 6be5a61..b467bd0 100644 --- a/src/controllers/certificate.js +++ b/src/controllers/certificate.js @@ -198,7 +198,18 @@ const getSingle = async (req, res) => { * @type {RequestHandler} */ const getAll = async (req, res) => { - const certificates = (await Certificate.find({}, { + if(req.query.tags){ + try{ + const formData = req.query.tags; + const decodedData = decodeURIComponent(formData); + const jsonObject = JSON.parse(decodedData); + req.query['tags'] = {'$in': jsonObject}; + }catch(e){ + return res.status(statusCode.BAD_REQUEST).send(`Failed to get certificates: Bad fromat ${e.message}`); + } + } + + const certificates = (await Certificate.find(req.query, { _id: 0, uid: 1 })).map(t => t.uid); diff --git a/src/controllers/template.js b/src/controllers/template.js index a257c39..cad7c66 100644 --- a/src/controllers/template.js +++ b/src/controllers/template.js @@ -207,7 +207,18 @@ const getSingle = async (req, res) => { * @type {RequestHandler} */ const getAll = async (req, res) => { - const templates = (await Template.find({}, { + if(req.query.tags){ + try{ + const formData = req.query.tags; + const decodedData = decodeURIComponent(formData); + const jsonObject = JSON.parse(decodedData); + req.query['tags'] = {'$in': jsonObject}; + }catch(e){ + return res.status(statusCode.BAD_REQUEST).send(`Failed to get templates: Bad fromat ${e.message}`); + } + } + + const templates = (await Template.find(req.query, { _id: 0, name: 1 })).map(t => t.name);