Skip to content

Instantly share code, notes, and snippets.

@thakursaurabh1998
Created June 14, 2020 09:50
Show Gist options
  • Save thakursaurabh1998/574e28c36d25cff45b8f29c65ff217c6 to your computer and use it in GitHub Desktop.
Save thakursaurabh1998/574e28c36d25cff45b8f29c65ff217c6 to your computer and use it in GitHub Desktop.
const _ = require('underscore');
const { query, model, operation } = offer.eligibility;
// the query is parsed because the query string in
// the offer document is an undercore string template where
// the variables can be replaced with the provided value
const parsedQuery = JSON.parse(
_.template(query)({
brokeruserId: event.data.brokeruserId,
})
);
// this gives us a parsed JSON query which can be further
// passed on to the mongoose model for querying
// models is an Object which contains the map of
// the collection name to mongoose model of that collection
const result = await models[model][operation](parsedQuery).exec();
if (result === expectedResult) {
// do the needful
} else {
// skip everything
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment