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
|
2021-06-18 13:05:03 +00:00
|
|
|
},
|
|
|
|
{
|
2019-10-08 05:22:38 +00:00
|
|
|
arg: 'geoId',
|
|
|
|
type: 'Number',
|
|
|
|
required: true
|
2021-06-18 13:05:03 +00:00
|
|
|
},
|
|
|
|
{
|
2019-10-08 05:22:38 +00:00
|
|
|
arg: 'isIncluded',
|
|
|
|
type: 'Boolean'
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:id/toggleIsIncluded`,
|
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-18 13:05:03 +00:00
|
|
|
Self.toggleIsIncluded = async(id, geoId, isIncluded, options) => {
|
2019-10-08 05:22:38 +00:00
|
|
|
const models = Self.app.models;
|
2021-11-18 10:17:30 +00:00
|
|
|
const myOptions = {};
|
2021-06-18 13:05:03 +00:00
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
2019-10-08 05:22:38 +00:00
|
|
|
|
|
|
|
if (isIncluded === undefined)
|
2021-06-18 13:05:03 +00:00
|
|
|
return models.ZoneIncluded.destroyAll({zoneFk: id, geoFk: geoId}, myOptions);
|
2019-10-08 05:22:38 +00:00
|
|
|
else {
|
|
|
|
return models.ZoneIncluded.upsert({
|
|
|
|
zoneFk: id,
|
|
|
|
geoFk: geoId,
|
|
|
|
isIncluded: isIncluded
|
2021-06-18 13:05:03 +00:00
|
|
|
}, myOptions);
|
2019-10-08 05:22:38 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|