37 lines
888 B
JavaScript
37 lines
888 B
JavaScript
module.exports = Self => {
|
|
Self.remoteMethod('toggleIsIncluded', {
|
|
description: 'Toggle include to delivery',
|
|
accessType: '',
|
|
accepts: [{
|
|
arg: 'zoneFk',
|
|
type: 'Number',
|
|
required: true,
|
|
},
|
|
{
|
|
arg: 'item',
|
|
type: 'Object',
|
|
required: true,
|
|
}],
|
|
returns: {
|
|
type: 'object',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/toggleIsIncluded`,
|
|
verb: 'POST'
|
|
}
|
|
});
|
|
|
|
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
|
|
});
|
|
}
|
|
};
|
|
};
|