diff --git a/db/changes/10210-summer/00-ticket_beforeUpdate.sql b/db/changes/10210-summer/00-ticket_beforeUpdate.sql new file mode 100644 index 000000000..fa1cb6c5f --- /dev/null +++ b/db/changes/10210-summer/00-ticket_beforeUpdate.sql @@ -0,0 +1,31 @@ +DROP TRIGGER IF EXISTS `vn`.`ticket_beforeUpdate`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` TRIGGER `ticket_beforeUpdate` + BEFORE UPDATE ON `ticket` + FOR EACH ROW +BEGIN + IF !(NEW.shipped <=> OLD.shipped) THEN + IF YEAR(NEW.shipped) < 2000 THEN + SIGNAL SQLSTATE '46000' + SET MESSAGE_TEXT = 'Year cannot be lesser than 2000'; + END IF; + + IF YEAR(NEW.shipped) = 2000 THEN + SET NEW.isDeleted = TRUE; + END IF; + END IF; + + IF !(NEW.isDeleted <=> OLD.isDeleted) AND NEW.isDeleted THEN + SET NEW.shipped = DATE_FORMAT(NEW.shipped, '2000-%m-%d %T'); + SET NEW.landed = DATE_FORMAT(NEW.landed, '2000-%m-%d %T'); + SET NEW.routeFk = NULL; + SET NEW.zoneFk = NULL; + END IF; + + IF NEW.routeFk AND NEW.isDeleted THEN + CALL util.throw ('This ticket is deleted'); + END IF; +END$$ +DELIMITER ; diff --git a/modules/zone/back/methods/zone/deleteZone.js b/modules/zone/back/methods/zone/deleteZone.js index baa442491..7bf807f7d 100644 --- a/modules/zone/back/methods/zone/deleteZone.js +++ b/modules/zone/back/methods/zone/deleteZone.js @@ -29,7 +29,8 @@ module.exports = Self => { const options = {transaction: tx}; const filter = { where: { - zoneFk: id + zoneFk: id, + shipped: {gte: today} }, include: { relation: 'ticketState', @@ -46,10 +47,10 @@ module.exports = Self => { where: {userFk: userId} }, options); - ticketList.forEach(ticket => { - promises.push(ticket.updateAttributes({zoneFk: null}, options)); + await models.Ticket.rawSql('UPDATE ticket SET zoneFk = NULL WHERE zoneFk = ?', [id], options); - if (ticket.ticketState().alertLevel == 0 && ticket.shipped >= today) { + ticketList.forEach(ticket => { + if (ticket.ticketState().alertLevel == 0) { promises.push(models.TicketTracking.create({ ticketFk: ticket.id, stateFk: fixingState.id, diff --git a/modules/zone/front/descriptor/locale/es.yml b/modules/zone/front/descriptor/locale/es.yml index 67bcbb5b7..0581ee93a 100644 --- a/modules/zone/front/descriptor/locale/es.yml +++ b/modules/zone/front/descriptor/locale/es.yml @@ -1,4 +1,4 @@ -This zone contains tickets: Esta zona contiene {{ticketsAmount}} tickets. ¿Seguro que quieres eliminar esta zona? +This zone contains tickets: Esta zona contiene {{ticketsAmount}} tickets por servir. ¿Seguro que quieres eliminar esta zona? Do you want to clone this zone?: ¿Quieres clonar esta zona? All it's properties will be copied: Todas sus propiedades serán copiadas Zone deleted: Zona eliminada \ No newline at end of file