salix/loopback/common/methods/log/models.js

45 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-04-24 17:10:04 +00:00
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)
);
};
};