36 lines
864 B
JavaScript
36 lines
864 B
JavaScript
module.exports = Self => {
|
|
Self.remoteMethod('toggleIsIncluded', {
|
|
description: 'Toggle include to delivery',
|
|
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
|
|
});
|
|
}
|
|
};
|
|
};
|