salix/back/methods/starred-module/getStarredModules.js

35 lines
901 B
JavaScript

module.exports = function(Self) {
Self.remoteMethodCtx('getStarredModules', {
description: 'returns the starred modules for the current user',
accessType: 'READ',
returns: {
type: 'object',
root: true
},
http: {
path: `/getStarredModules`,
verb: 'get'
}
});
Self.getStarredModules = async(ctx, options) => {
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
let myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const filter = {
where: {
workerFk: userId
},
fields: ['id', 'workerFk', 'moduleFk', 'position'],
order: 'position ASC'
};
return models.StarredModule.find(filter, myOptions);
};
};