Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for search parameters (#55) #57

Merged
merged 2 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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