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

36 lines
843 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,
},
{
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});
};
};