Hello (again),
In my project we use forest-express-sequelize with our SQL database. I explored the github repository to find a way to parse the query.filters to sequelize where conditions. I found this file
function makeParseFilter(FiltersParser, publicExports) {
/**
* @param {*} filter
* @param {*} modelSchema
* @param {string} timezone
* @returns {Promise<any>} Sequelize condition
*/
return function parseFilter(filter, modelSchema, timezone) {
if (!publicExports.opts) throw new Error('Liana must be initialized before using parseFilter');
const parser = new FiltersParser(modelSchema, timezone, publicExports.opts);
return parser.perform(JSON.stringify(filter));
};
}
module.exports = makeParseFilter;
I tried to use it with this code :
const { parseFilter } = = require('forest-express-sequelize');
router.get('/careGiver', permissionMiddlewareCreator.list(), async (request, response) => {
const conditions = await parseFilter(
JSON.parse(request.query.filters),
models.careGiver,
'Europe/Paris',
);
console.log('condition', conditions);
})
But it throw TypeError: Cannot read property 'find' of undefined
so i guess it’s because parseFilter did not have access to my sequelize instance. How can i use it ?