Skip to content

Commit

Permalink
Merge pull request #248 from flyvictor/PO-4636-bookings-list-screen
Browse files Browse the repository at this point in the history
chore(PO-4636): fix query parser on the adapter
  • Loading branch information
alexgolafv authored Jul 9, 2024
2 parents 2e5c5bc + 443d6a4 commit 12f8128
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 3 additions & 2 deletions lib/adapters/mongodb.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const mongoose = require('mongoose');
const RSVP = require('rsvp');
const _ = require('lodash');
const { ensureInArray } = require('../querytree');

const Promise = RSVP.Promise;
const adapter = {};
Expand Down Expand Up @@ -584,9 +585,9 @@ adapter.parseQuery = function (model, query) {
},
{},
);
} else if (_.isString(val.in || val.$in)) {
} else if (val.in || val.$in) {
query[key] = {
$in: (val.in || val.$in).split(','),
$in: ensureInArray(val.in || val.$in),
};
} else if (_.isObject(val) && _.isString(val.regex)) {
//regex
Expand Down
20 changes: 11 additions & 9 deletions lib/querytree.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ function isSpecial(query) {
});
}

function ensureInArray(inValue) {
if (_.isArray(inValue)) return inValue;
if (_.isString(inValue)) return inValue.split(',');
if (_.isObject(inValue)) return _.values(inValue);

console.log('ensureInArray cannot handle the input value', inValue);
throw new Error('ensureInArray cannot handle the input value');
}

/**
* registers fortune instance
* expects that all resources have been defined
Expand All @@ -30,15 +39,6 @@ exports.init = function (fortune) {
this.query = parseQuery(request, query, resource);
}

function ensureInArray(inValue) {
if (_.isArray(inValue)) return inValue;
if (_.isString(inValue)) return inValue.split(',');
if (_.isObject(inValue)) return _.values(inValue);

console.log('ensureInArray cannot handle the input value', inValue);
throw new Error('ensureInArray cannot handle the input value');
}

/**
* Iterates first level of query detecting filtering by referenced resources fields
* @param query
Expand Down Expand Up @@ -154,3 +154,5 @@ exports.init = function (fortune) {

return instance;
};

exports.ensureInArray = ensureInArray;

0 comments on commit 12f8128

Please sign in to comment.