41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
|
|
|
module.exports = Self => {
|
|
Self.remoteMethod('editors', {
|
|
description: 'Get the list of entity editors',
|
|
accepts: [
|
|
{
|
|
arg: 'id',
|
|
type: 'integer',
|
|
description: 'The model id',
|
|
required: true
|
|
}, {
|
|
arg: 'filter',
|
|
type: 'Object',
|
|
description: 'The user filter object'
|
|
}
|
|
],
|
|
returns: {
|
|
type: [Self],
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/:id/editors`,
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.editors = async(id, filter) => {
|
|
const res = await Self.find({
|
|
fields: ['userFk'],
|
|
where: {originFk: id}
|
|
});
|
|
const userIds = new Set(res.map(x => x.userFk));
|
|
|
|
filter = mergeFilters(filter, {
|
|
where: {id: {inq: [...userIds]}}
|
|
});
|
|
return await Self.app.models.VnUser.find(filter);
|
|
};
|
|
};
|