refactor(toggleIsIcluded): actualizo la versión y modifico el proc refs #5749
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Pablo Natek 2023-10-17 15:05:48 +02:00
parent 541926d3f7
commit 8d44bb8867
2 changed files with 14 additions and 17 deletions

View File

@ -13,15 +13,14 @@ DROP TRIGGER IF EXISTS `vn`.`zoneIncluded_afterDelete`;
USE `vn`;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterDelete`
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`zoneIncluded_afterDelete`
AFTER DELETE ON `zoneIncluded`
FOR EACH ROW
BEGIN
INSERT INTO zoneLog
SET `action` = 'delete',
`changedModel` = 'ZoneIncluded',
`changedModelId` = OLD.id,
`changedModel` = 'zoneIncluded',
`changedModelId` = OLD.zoneFk,
`userFk` = account.myUser_getId();
END$$
DELIMITER ;

View File

@ -30,23 +30,21 @@ module.exports = Self => {
Self.toggleIsIncluded = async(id, geoId, isIncluded, options) => {
const models = Self.app.models;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
if (isIncluded === undefined)
return models.ZoneIncluded.destroyAll({zoneFk: id, geoFk: geoId}, myOptions);
else {
const zoneIncluded = await models.ZoneIncluded.findOne({where: {zoneFk: id, geoFk: geoId}}, myOptions);
if (zoneIncluded)
return zoneIncluded.updateAttribute('isIncluded', isIncluded, myOptions);
else {
return models.ZoneIncluded.create({
zoneFk: id,
geoFk: geoId,
isIncluded: isIncluded
}, myOptions);
}
}
const zoneIncluded = await models.ZoneIncluded.findOne({where: {zoneFk: id, geoFk: geoId}}, myOptions);
if (zoneIncluded)
return zoneIncluded.updateAttribute('isIncluded', isIncluded, myOptions);
return models.ZoneIncluded.create({
zoneFk: id,
geoFk: geoId,
isIncluded: isIncluded
}, myOptions);
};
};