clone zone with calenday days (#1482) & fixed clone hour #1458
gitea/salix/master This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-05-28 12:55:50 +02:00
parent e9c2ae073a
commit 749c6f1167
5 changed files with 25 additions and 10 deletions

View File

@ -22,6 +22,7 @@ module.exports = Self => {
Self.clone = async id => { Self.clone = async id => {
const models = Self.app.models; const models = Self.app.models;
const transaction = await Self.beginTransaction({}); const transaction = await Self.beginTransaction({});
const options = {transaction};
// Find original zone // Find original zone
const zone = await models.Zone.findOne({ const zone = await models.Zone.findOne({
@ -35,22 +36,36 @@ module.exports = Self => {
'bonus', 'bonus',
'isVolumetric'], 'isVolumetric'],
where: {id} where: {id}
}); }, options);
const hour = zone.hour;
const offset = hour.getTimezoneOffset() * 60000;
hour.setTime(hour.getTime() + offset);
// Find all original included geolocations // Find all original included geolocations
const includedGeo = await models.ZoneIncluded.find({ const includedGeo = await models.ZoneIncluded.find({
fields: ['geoFk', 'isIncluded'], fields: ['geoFk', 'isIncluded'],
where: {zoneFk: id} where: {zoneFk: id}
}); }, options);
// Find all original selected days
const calendarDays = await models.ZoneCalendar.find({
where: {zoneFk: id}
}, options);
try { try {
const newZone = await Self.create(zone, {transaction}); const newZone = await Self.create(zone, options);
const newIncludedGeo = includedGeo.map(included => { const newIncludedGeo = includedGeo.map(included => {
included.zoneFk = newZone.id; included.zoneFk = newZone.id;
return included; 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(); await transaction.commit();
return newZone; return newZone;

View File

@ -48,6 +48,6 @@
<vn-confirm <vn-confirm
vn-id="delete-zone" vn-id="delete-zone"
on-response="$ctrl.returnDialog(response)" on-response="$ctrl.returnDialog(response)"
question="Delete zone" question="Are you sure you want to delete this zone?"
message="Are you sure you want to delete this zone?"> message="This zone will be removed">
</vn-confirm> </vn-confirm>

View File

@ -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 All it's properties will be copied: Todas sus propiedades serán copiadas

View File

@ -4,8 +4,8 @@ Hour: Hora (ETD)
ETD: Tiempo de salida estimado ETD: Tiempo de salida estimado
Price: Precio Price: Precio
Locations: Localizaciones Locations: Localizaciones
Delete zone: Eliminar zona This zone will be removed: La zona será eliminada
Are you sure you want to delete this zone?: ¿Estás seguro de querer eliminar esta zona? Are you sure you want to delete this zone?: ¿Seguro de que quieres eliminar esta zona?
Zones: Zonas Zones: Zonas
New zone: Nueva zona New zone: Nueva zona
Volumetric: Volumétrico Volumetric: Volumétrico

View File

@ -26,7 +26,7 @@
value="{{$ctrl.summary.price | currency: 'EUR': 2}}"> value="{{$ctrl.summary.price | currency: 'EUR': 2}}">
</vn-label-value> </vn-label-value>
<vn-label-value label="Bonus" <vn-label-value label="Bonus"
value="{{$ctrl.summary.price | currency: 'EUR': 2}}"> value="{{$ctrl.summary.bonus | currency: 'EUR': 2}}">
</vn-label-value> </vn-label-value>
<vn-vertical> <vn-vertical>
<vn-check label="Volumetric" disabled="true" <vn-check label="Volumetric" disabled="true"