refs #4770 ahora clona las 'paradas' tmb
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
6ac12187c5
commit
05b87dbff2
|
@ -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;
|
||||
|
|
|
@ -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">
|
||||
|
|
Loading…
Reference in New Issue