module.exports = function(Self) { Self.remoteMethodCtx('toggleStarredModule', { description: 'returns the receved modules adding the starred property.', returns: { type: 'object', root: true }, accepts: { arg: 'moduleName', type: 'string', required: true, description: 'The module name' }, http: { path: `/toggleStarredModule`, verb: 'post' } }); Self.toggleStarredModule = async(ctx, moduleName) => { const userId = ctx.req.accessToken.userId; const filter = { where: { workerFk: userId, moduleFk: moduleName } }; const [starredModule] = await Self.app.models.StarredModule.find(filter); if (starredModule) await starredModule.destroy(); else { return Self.app.models.StarredModule.create({ workerFk: userId, moduleFk: moduleName }); } }; };