Filtering a HasMany Smart Relationship

Thank you, i think something like below do the trick.

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

router.get('/user/:recordId/relationships/activity', (request, response, next) => {
...
  let where = { [Op.or]: [{ someField: targetId }, { anotherField: targetId }] };

  if (req.query.filter) {
    const parsedWhere = await parseFilter(JSON.parse(req.query.filters), Schemas.schemas.activity, req.query.timezone);
    where = { [Op.and]: [parsedWhere, where] };
  }

  const findAll = activity.findAll({
        where,
        offset,
        limit,
    });

let me know.

4 Likes