Here is the code. Mabye request.query.filters
can be added to where
somehow.
router.get('/user/:recordId/relationships/activity', (request, response, next) => {
const targetId = `prefix-${request.params.recordId}`
const limit = parseInt(request.query.page.size, 10) || 20;
const offset = (parseInt(request.query.page.number, 10) - 1) * limit;
const recordsGetter = new RecordsGetter(activity, request.user, request.query);
let where = { [Op.or]: [{ someField: targetId }, { anotherField: targetId }] };
const findAll = activity.findAll({
where,
offset,
limit,
});
const count = activity.count({ where });
Promise.all([findAll, count])
.then(([activitiesFound, activitiesCount]) =>
recordsGetter.serialize(activitiesFound, { count: activitiesCount }))
.then((recordsSerialized) => response.send(recordsSerialized))
.catch(next);
});