3888-ticket.expedition_moveExpedition #1097
|
@ -235,5 +235,6 @@
|
|||
"Dirección incorrecta": "Dirección incorrecta",
|
||||
"Modifiable user details only by an administrator": "Detalles de usuario modificables solo por un administrador",
|
||||
"Modifiable password only via recovery or by an administrator": "Contraseña modificable solo a través de la recuperación o por un administrador",
|
||||
"Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente"
|
||||
"Not enough privileges to edit a client": "No tienes suficientes privilegios para editar un cliente",
|
||||
"This route not exists": "Esta ruta no existe"
|
||||
vicent marked this conversation as resolved
Outdated
|
||||
}
|
|
@ -1,19 +1,47 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('moveExpeditions', {
|
||||
Self.remoteMethodCtx('moveExpeditions', {
|
||||
description: 'Move the selected expeditions to another ticket',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'clientId',
|
||||
type: 'number',
|
||||
description: `The client id`,
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'landed',
|
||||
type: 'date',
|
||||
description: `The landing date`
|
||||
},
|
||||
{
|
||||
arg: 'warehouseId',
|
||||
type: 'number',
|
||||
description: `The warehouse id`,
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'addressId',
|
||||
type: 'number',
|
||||
description: `The address id`,
|
||||
required: true
|
||||
},
|
||||
{
|
||||
arg: 'agencyModeId',
|
||||
type: 'any',
|
||||
description: `The agencyMode id`
|
||||
},
|
||||
{
|
||||
arg: 'routeId',
|
||||
type: 'any',
|
||||
description: `The route id`
|
||||
},
|
||||
{
|
||||
arg: 'expeditionIds',
|
||||
type: ['number'],
|
||||
required: true,
|
||||
description: 'The expeditions ids to nove'
|
||||
},
|
||||
{
|
||||
arg: 'ticketId',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'the ticket id to which the expeditions are added'
|
||||
description: 'The expeditions ids to move'
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
|
@ -25,8 +53,9 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.moveExpeditions = async(expeditionIds, ticketId, options) => {
|
||||
Self.moveExpeditions = async(ctx, options) => {
|
||||
const models = Self.app.models;
|
||||
const args = ctx.args;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
|
@ -39,18 +68,23 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
try {
|
||||
if (args.routeId) {
|
||||
const route = await models.Route.findById(args.routeId, null, myOptions);
|
||||
if (!route) throw new UserError('This route not exists');
|
||||
}
|
||||
const ticket = await models.Ticket.new(ctx, myOptions);
|
||||
const promises = [];
|
||||
for (let expeditionsId of expeditionIds) {
|
||||
for (let expeditionsId of args.expeditionIds) {
|
||||
const expeditionToUpdate = await models.Expedition.findById(expeditionsId);
|
||||
vicent marked this conversation as resolved
Outdated
joan
commented
pasar transacción null, myOptions pasar transacción null, myOptions
|
||||
const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticketId, myOptions);
|
||||
const expeditionUpdated = expeditionToUpdate.updateAttribute('ticketFk', ticket.id, myOptions);
|
||||
promises.push(expeditionUpdated);
|
||||
}
|
||||
|
||||
const updated = await Promise.all(promises);
|
||||
await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return updated;
|
||||
return ticket;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
|
|
|
@ -44,22 +44,17 @@ class Controller extends Section {
|
|||
}
|
||||
|
||||
createTicket(landed, routeFk) {
|
||||
const ticketParams = {
|
||||
const params = {
|
||||
clientId: this.ticket.clientFk,
|
||||
landed: landed,
|
||||
warehouseId: this.ticket.warehouseFk,
|
||||
addressId: this.ticket.addressFk,
|
||||
agencyModeId: this.ticket.agencyModeFk,
|
||||
warehouseId: this.ticket.warehouseFk
|
||||
};
|
||||
const query = `Tickets/new`;
|
||||
this.$http.post(query, ticketParams).then(res => {
|
||||
if (routeFk) this.$http.patch(`Tickets/${res.data.id}`, {routeFk: routeFk});
|
||||
const params = {
|
||||
expeditionIds: this.checked,
|
||||
ticketId: res.data.id
|
||||
routeId: routeFk,
|
||||
expeditionIds: this.checked
|
||||
};
|
||||
const query = `Expeditions/moveExpeditions`;
|
||||
this.$http.post(query, params);
|
||||
this.$http.post(query, params).then(res => {
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.$state.go('ticket.card.summary', {id: res.data.id});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
This route does not exists