refs #4770 ahora clona las 'paradas' tmb
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Vicent Llopis 2023-05-03 13:52:58 +02:00
parent 6ac12187c5
commit 05b87dbff2
2 changed files with 24 additions and 8 deletions

View File

@ -1,3 +1,4 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('clone', {
description: 'Clones the selected routes',
@ -34,28 +35,43 @@ module.exports = Self => {
const originalRoadmaps = await models.Roadmap.find({
where: {id: {inq: ids}},
fields: [
'id',
'tractorPlate',
'trailerPlate',
'phone',
'supplierFk',
'etd',
'observations',
'price']
'price'],
include: [{
relation: 'expeditionTruck',
scope: {
fields: ['roadmapFk', 'warehouseFk', 'ETD', 'description']
}
}]
}, options);
if (ids.length != originalRoadmaps.length)
throw new Error(`The amount of roadmaps found don't match`);
throw new UserError(`The amount of roadmaps found don't match`);
const roadmaps = originalRoadmaps.map(roadmap => {
for (const roadmap of originalRoadmaps) {
roadmap.id = undefined;
roadmap.etd = ETD;
return roadmap;
});
const clones = await models.Roadmap.create(roadmaps, options);
const clone = await models.Roadmap.create(roadmap, options);
const expeditionTrucks = roadmap.expeditionTruck();
expeditionTrucks.map(expeditionTruck => {
expeditionTruck.roadmapFk = clone.id;
return expeditionTruck;
});
await models.ExpeditionTruck.create(expeditionTrucks, options);
}
await tx.commit();
return clones;
return true;
} catch (e) {
await tx.rollback();
throw e;

View File

@ -9,7 +9,7 @@
<vn-data-viewer
model="model">
<form
class="vn-w-xl"
class="vn-w-md"
name="form">
<vn-card>
<section class="vn-pa-md">