Skip to content

Commit

Permalink
Added support for search parameters (#55) (#57)
Browse files Browse the repository at this point in the history
* added support for search parameters

* error message update
  • Loading branch information
MitanshiKshatriya authored Jan 10, 2022
1 parent 6cc22ce commit 2679d4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/controllers/certificate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion src/controllers/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2679d4c

Please sign in to comment.