From 12e02688706baba5530428b40d324d70a99c4282 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 28 May 2019 12:55:50 +0200 Subject: [PATCH] clone zone with calenday days (#1482) & fixed clone hour #1458 --- modules/agency/back/methods/zone/clone.js | 23 ++++++++++++++++++---- modules/agency/front/descriptor/index.html | 4 ++-- modules/agency/front/index/locale/es.yml | 2 +- modules/agency/front/locale/es.yml | 4 ++-- modules/agency/front/summary/index.html | 2 +- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/modules/agency/back/methods/zone/clone.js b/modules/agency/back/methods/zone/clone.js index 0fb8b5ad4..0f406c49a 100644 --- a/modules/agency/back/methods/zone/clone.js +++ b/modules/agency/back/methods/zone/clone.js @@ -22,6 +22,7 @@ module.exports = Self => { Self.clone = async id => { const models = Self.app.models; const transaction = await Self.beginTransaction({}); + const options = {transaction}; // Find original zone const zone = await models.Zone.findOne({ @@ -35,22 +36,36 @@ module.exports = Self => { 'bonus', 'isVolumetric'], where: {id} - }); + }, options); + + const hour = zone.hour; + const offset = hour.getTimezoneOffset() * 60000; + hour.setTime(hour.getTime() + offset); // Find all original included geolocations const includedGeo = await models.ZoneIncluded.find({ fields: ['geoFk', 'isIncluded'], where: {zoneFk: id} - }); + }, options); + + // Find all original selected days + const calendarDays = await models.ZoneCalendar.find({ + where: {zoneFk: id} + }, options); try { - const newZone = await Self.create(zone, {transaction}); + const newZone = await Self.create(zone, options); const newIncludedGeo = includedGeo.map(included => { included.zoneFk = newZone.id; return included; }); + const newCalendayDays = calendarDays.map(day => { + day.zoneFk = newZone.id; + return day; + }); - await models.ZoneIncluded.create(newIncludedGeo, {transaction}); + await models.ZoneIncluded.create(newIncludedGeo, options); + await models.ZoneCalendar.create(newCalendayDays, options); await transaction.commit(); return newZone; diff --git a/modules/agency/front/descriptor/index.html b/modules/agency/front/descriptor/index.html index 5abfab4cf..7f122bcf6 100644 --- a/modules/agency/front/descriptor/index.html +++ b/modules/agency/front/descriptor/index.html @@ -48,6 +48,6 @@ + question="Are you sure you want to delete this zone?" + message="This zone will be removed"> \ No newline at end of file diff --git a/modules/agency/front/index/locale/es.yml b/modules/agency/front/index/locale/es.yml index c0a97c819..14195e869 100644 --- a/modules/agency/front/index/locale/es.yml +++ b/modules/agency/front/index/locale/es.yml @@ -1,2 +1,2 @@ -Do you want to clone this zone?: ¿Seguro que quieres eliminar esta zona? +Do you want to clone this zone?: ¿Seguro que quieres clonar esta zona? All it's properties will be copied: Todas sus propiedades serán copiadas \ No newline at end of file diff --git a/modules/agency/front/locale/es.yml b/modules/agency/front/locale/es.yml index d34ab1f70..ef226ef10 100644 --- a/modules/agency/front/locale/es.yml +++ b/modules/agency/front/locale/es.yml @@ -4,8 +4,8 @@ Hour: Hora (ETD) ETD: Tiempo de salida estimado Price: Precio Locations: Localizaciones -Delete zone: Eliminar zona -Are you sure you want to delete this zone?: ¿Estás seguro de querer eliminar esta zona? +This zone will be removed: La zona será eliminada +Are you sure you want to delete this zone?: ¿Seguro de que quieres eliminar esta zona? Zones: Zonas New zone: Nueva zona Volumetric: Volumétrico diff --git a/modules/agency/front/summary/index.html b/modules/agency/front/summary/index.html index e37ba365e..54adc3586 100644 --- a/modules/agency/front/summary/index.html +++ b/modules/agency/front/summary/index.html @@ -26,7 +26,7 @@ value="{{$ctrl.summary.price | currency: 'EUR': 2}}"> + value="{{$ctrl.summary.bonus | currency: 'EUR': 2}}">