Created
June 14, 2020 09:50
-
-
Save thakursaurabh1998/574e28c36d25cff45b8f29c65ff217c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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