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

37 lines
888 B
JavaScript
Raw Normal View History

2019-01-21 10:45:53 +00:00
module.exports = Self => {
Self.remoteMethod('toggleIsIncluded', {
description: 'Toggle include to delivery',
accessType: '',
accepts: [{
arg: 'zoneFk',
type: 'Number',
required: true,
},
{
2019-02-18 07:37:26 +00:00
arg: 'item',
type: 'Object',
2019-01-21 10:45:53 +00:00
required: true,
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/toggleIsIncluded`,
verb: 'POST'
}
});
2019-02-18 07:37:26 +00:00
Self.toggleIsIncluded = async(zoneFk, item) => {
if (item.isIncluded === null)
return Self.destroyAll({zoneFk, geoFk: item.id});
else {
return Self.upsert({
zoneFk: zoneFk,
geoFk: item.id,
isIncluded: item.isIncluded
});
}
2019-01-21 10:45:53 +00:00
};
};