module.exports = function(Self) { Self.remoteMethodCtx('toggleStarredModule', { description: 'creates or deletes a starred module for the current user', accessType: 'WRITE', 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 }); } }; };