36 lines
843 B
JavaScript
36 lines
843 B
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethod('toggleIsIncluded', {
|
||
|
description: 'Toggle include to delivery',
|
||
|
accessType: '',
|
||
|
accepts: [{
|
||
|
arg: 'zoneFk',
|
||
|
type: 'Number',
|
||
|
required: true,
|
||
|
},
|
||
|
{
|
||
|
arg: 'geoFk',
|
||
|
type: 'Number',
|
||
|
required: true,
|
||
|
}],
|
||
|
returns: {
|
||
|
type: 'object',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/toggleIsIncluded`,
|
||
|
verb: 'POST'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.toggleIsIncluded = async(zoneFk, geoFk) => {
|
||
|
const isIncluded = await Self.findOne({
|
||
|
where: {zoneFk, geoFk}
|
||
|
});
|
||
|
|
||
|
if (isIncluded)
|
||
|
return Self.destroyAll({zoneFk, geoFk});
|
||
|
else
|
||
|
return Self.upsert({zoneFk, geoFk});
|
||
|
};
|
||
|
};
|