salix/modules/agency/back/methods/zone/toggleIsIncluded.js

42 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-10-08 05:22:38 +00:00
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
});
}
};
};