How to use parseFilter from forest-express-sequelize

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(
  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 ?

Hey @Justin_Martin,

The second argument is not the sequelize models, but the forest model schema.

const {
  parseFilter, Schemas,
} = require('forest-express-sequelize');


  const conditions = await parseFilter(

If it does not work, could you please share the complete stack trace here?

Thanks in advance :pray:

1 Like

Ok perfect it’s work well with this change thank you

1 Like