diff --git a/src/plugins/buildQuery.js b/src/plugins/buildQuery.js index a87d637535..3864778539 100644 --- a/src/plugins/buildQuery.js +++ b/src/plugins/buildQuery.js @@ -5,14 +5,11 @@ export default function buildQuery(schema) { schema.statics.apiQuery = function (rawParams, locale, cb) { const model = this; const params = paramParser(this, rawParams, locale); - console.log('parsed params', params); // Create the Mongoose Query object. let query = model .find(params.searchParams); - console.log('after query find'); - if (params.sort) query = query.sort(params.sort); @@ -40,7 +37,7 @@ function paramParser(model, rawParams, locale) { query = parseParam(key, rawParams[key], model, query, locale); } else { for (let i = 0; i < separatedParams.length; ++i) { - query = parseParam(key, separatedParams[i], model, query); + query = parseParam(key, separatedParams[i], model, query, locale); } } } @@ -105,7 +102,7 @@ function parseParam(key, val, model, query, locale) { function parseSchemaForKey(schema, query, keyPrefix, lcKey, val, operator, locale) { let paramType; - const key = keyPrefix + lcKey; + let key = keyPrefix + lcKey; let matches = lcKey.match(/(.+)\.(.+)/); if (matches) { @@ -119,7 +116,8 @@ function parseSchemaForKey(schema, query, keyPrefix, lcKey, val, operator, local } } else if (typeof schema === 'object' ) { if (schema.obj[lcKey].intl) { - query = addSearchParam(query, `${key}.${locale}`, val); + key = `${key}.${locale}`; + paramType = 'String' } } else if (typeof schema === 'undefined') { paramType = 'String'; diff --git a/src/requestHandlers/query.js b/src/requestHandlers/query.js index a71deecb8f..3ce45e5aa7 100644 --- a/src/requestHandlers/query.js +++ b/src/requestHandlers/query.js @@ -1,14 +1,10 @@ import httpStatus from 'http-status'; const query = (req, res) => { - console.log('inside query'); - req.model.apiQuery(req.query, req.locale, (err, result) => { if (err) { - console.log('api query error', err); return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ error: err }); } - console.log('no error inside api query'); return res.json( result.map(doc => { //TODO: 'result.docs' will need to be used for the pagination plugin if (req.locale) { @@ -17,7 +13,6 @@ const query = (req, res) => { return doc.toJSON({ virtuals: true }) }) - ); }); };