const mergeFilters = require('vn-loopback/util/filter').mergeFilters; module.exports = Self => { Self.remoteMethod('models', { description: 'Get the list of entity models', accepts: [ { arg: 'id', type: 'integer', description: 'The model id', required: true }, { arg: 'filter', type: 'Object', description: 'The filter object' } ], returns: { type: [Self], root: true }, http: { path: `/:id/models`, verb: 'GET' } }); Self.models = async(id, filter) => { filter = mergeFilters(filter, { fields: ['changedModel'], where: { originFk: id, changedModel: {neq: null} } }); const res = await Self.find(filter); const set = new Set(); return res.filter(x => set.has(x.changedModel) ? false : set.add(x.changedModel) ); }; };