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

Added support for search parameters (#55) #57

merged 2 commits into from
Jan 10, 2022

Conversation

MitanshiKshatriya
Copy link
Contributor

closes #55

Added changes in controllers/certificate.js and controllers/template.js to support multiple query parameters.

  1. controllers/certificate.js
  • if req.query contains tags check if value of req.query.tags can be decoded into JSON object
  • if err while decoding send 400 Bad request message
  • else use req.query object to filter certificates (in case of no parameters req.query={})
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);
  1. controllers/template.js
  • if req.query contains tags check if value of req.query.tags can be decoded into JSON object
  • if err while decoding send 400 Bad request message
  • else use req.query object to filter templates (in case of no parameters req.query={})
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);

@paramsiddharth paramsiddharth added the enhancement New feature or request label Jan 10, 2022
@paramsiddharth paramsiddharth merged commit 2679d4c into heyrema:main Jan 10, 2022
@paramsiddharth paramsiddharth added the SWoC Under the Script Winter of Contributing. label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SWoC Under the Script Winter of Contributing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for search parameters
2 participants