From 3dfa4bfc040e08f05d748b9d7af4df73302f1343 Mon Sep 17 00:00:00 2001 From: gerard Date: Tue, 24 Jul 2018 11:27:04 +0200 Subject: [PATCH] Bug #425 Split no funciona en produccion --- .../loopback/common/methods/sale/moveToNewTicket.js | 13 +++++++++---- services/loopback/common/methods/ticket/new.js | 11 +++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/services/loopback/common/methods/sale/moveToNewTicket.js b/services/loopback/common/methods/sale/moveToNewTicket.js index 469b729fe..529305671 100644 --- a/services/loopback/common/methods/sale/moveToNewTicket.js +++ b/services/loopback/common/methods/sale/moveToNewTicket.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethod('moveToNewTicket', { + Self.remoteMethodCtx('moveToNewTicket', { description: 'Change the state of a ticket', accessType: '', 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 thisTicketIsEditable = await model.Ticket.isEditable(params.ticket.oldTicketFk); if (!thisTicketIsEditable) @@ -44,14 +45,18 @@ module.exports = Self => { agencyModeFk: params.ticket.agencyModeFk, warehouseFk: params.ticket.warehouseFk, shipped: shipped, - landed: landed + landed: landed, + userId: userId }; let newTicket = await model.Ticket.new(newTicketParams); + let promises = []; 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; }; }; diff --git a/services/loopback/common/methods/ticket/new.js b/services/loopback/common/methods/ticket/new.js index b6d9e87bb..04cf104e9 100644 --- a/services/loopback/common/methods/ticket/new.js +++ b/services/loopback/common/methods/ticket/new.js @@ -6,7 +6,7 @@ module.exports = Self => { arg: 'params', type: 'object', required: true, - description: 'ClientFk, Shipped, WharehouseFk, CompanyFk, AddressFk, AgencyModeFk, RouteFk, Landed', + description: 'ClientFk, Shipped, WharehouseFk, CompanyFk, AddressFk, AgencyModeFk, RouteFk, Landed, userId', http: {source: 'body'} }], returns: { @@ -24,7 +24,8 @@ module.exports = Self => { if (!existsAddress) 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, [ params.clientFk, params.shipped, @@ -33,8 +34,10 @@ module.exports = Self => { params.addressFk, params.agencyModeFk, params.routeFk | null, - params.landed + params.landed, + params.userId ]); - return result[0][0].vNewTicket; + + return result[1][0].newTicketId; }; };