module.exports = function(Self) { Self.installMethod('filter', filterParams, filterResults); function filterParams(params) { return { where: { clientFk: params.clientFk }, skip: (params.page - 1) * params.size, limit: params.size, order: params.order || 'created DESC', include: { relation: "employee", scope: { fields: ["id", "name", "surname"] } } }; } function filterResults(instances) { let result = JSON.parse(JSON.stringify(instances)); if (result && result.instances && result.instances.length) { result.instances.forEach((element, i) => { result.instances[i].employee.name = `${element.employee.name} ${element.employee.surname}`; delete result.instances[i].employee.surname; }); } return result; } };