Bug #425 Split no funciona en produccion
This commit is contained in:
parent
ff6d86f6c2
commit
3dfa4bfc04
|
@ -1,5 +1,5 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('moveToNewTicket', {
|
Self.remoteMethodCtx('moveToNewTicket', {
|
||||||
description: 'Change the state of a ticket',
|
description: 'Change the state of a ticket',
|
||||||
accessType: '',
|
accessType: '',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
|
@ -25,7 +25,8 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.moveToNewTicket = async params => {
|
Self.moveToNewTicket = async(ctx, params) => {
|
||||||
|
let userId = ctx.req.accessToken.userId;
|
||||||
let model = Self.app.models;
|
let model = Self.app.models;
|
||||||
let thisTicketIsEditable = await model.Ticket.isEditable(params.ticket.oldTicketFk);
|
let thisTicketIsEditable = await model.Ticket.isEditable(params.ticket.oldTicketFk);
|
||||||
if (!thisTicketIsEditable)
|
if (!thisTicketIsEditable)
|
||||||
|
@ -44,14 +45,18 @@ module.exports = Self => {
|
||||||
agencyModeFk: params.ticket.agencyModeFk,
|
agencyModeFk: params.ticket.agencyModeFk,
|
||||||
warehouseFk: params.ticket.warehouseFk,
|
warehouseFk: params.ticket.warehouseFk,
|
||||||
shipped: shipped,
|
shipped: shipped,
|
||||||
landed: landed
|
landed: landed,
|
||||||
|
userId: userId
|
||||||
};
|
};
|
||||||
|
|
||||||
let newTicket = await model.Ticket.new(newTicketParams);
|
let newTicket = await model.Ticket.new(newTicketParams);
|
||||||
|
|
||||||
|
let promises = [];
|
||||||
for (let i = 0; i < params.sales.length; i++) {
|
for (let i = 0; i < params.sales.length; i++) {
|
||||||
await model.Sale.update({id: params.sales[i].id}, {ticketFk: newTicket});
|
promises.push(model.Sale.update({id: params.sales[i].id}, {ticketFk: newTicket}));
|
||||||
}
|
}
|
||||||
|
await Promise.all(promises);
|
||||||
|
|
||||||
return newTicket;
|
return newTicket;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@ module.exports = Self => {
|
||||||
arg: 'params',
|
arg: 'params',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'ClientFk, Shipped, WharehouseFk, CompanyFk, AddressFk, AgencyModeFk, RouteFk, Landed',
|
description: 'ClientFk, Shipped, WharehouseFk, CompanyFk, AddressFk, AgencyModeFk, RouteFk, Landed, userId',
|
||||||
http: {source: 'body'}
|
http: {source: 'body'}
|
||||||
}],
|
}],
|
||||||
returns: {
|
returns: {
|
||||||
|
@ -24,7 +24,8 @@ module.exports = Self => {
|
||||||
if (!existsAddress)
|
if (!existsAddress)
|
||||||
throw new Error(`This address doesn't exist`);
|
throw new Error(`This address doesn't exist`);
|
||||||
|
|
||||||
let query = `CALL vn.ticketListCreate(?, ?, ?, ?, ?, ?, ?, ?);`;
|
let query = `CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @pe);
|
||||||
|
SELECT @pe newTicketId;`;
|
||||||
let result = await Self.rawSql(query, [
|
let result = await Self.rawSql(query, [
|
||||||
params.clientFk,
|
params.clientFk,
|
||||||
params.shipped,
|
params.shipped,
|
||||||
|
@ -33,8 +34,10 @@ module.exports = Self => {
|
||||||
params.addressFk,
|
params.addressFk,
|
||||||
params.agencyModeFk,
|
params.agencyModeFk,
|
||||||
params.routeFk | null,
|
params.routeFk | null,
|
||||||
params.landed
|
params.landed,
|
||||||
|
params.userId
|
||||||
]);
|
]);
|
||||||
return result[0][0].vNewTicket;
|
|
||||||
|
return result[1][0].newTicketId;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue