module.exports = Self => { Self.remoteMethod('toggleIsIncluded', { description: 'Toggle include to delivery', accepts: [{ arg: 'id', type: 'Number', description: 'The zone id', http: {source: 'path'}, required: true }, { arg: 'geoId', type: 'Number', required: true }, { arg: 'isIncluded', type: 'Boolean' }], returns: { type: 'object', root: true }, http: { path: `/:id/toggleIsIncluded`, verb: 'POST' } }); Self.toggleIsIncluded = async(id, geoId, isIncluded) => { const models = Self.app.models; if (isIncluded === undefined) return models.ZoneIncluded.destroyAll({zoneFk: id, geoFk: geoId}); else { return models.ZoneIncluded.upsert({ zoneFk: id, geoFk: geoId, isIncluded: isIncluded }); } }; };