diff --git a/modules/ticket/back/methods/ticket/saveSign.js b/modules/ticket/back/methods/ticket/saveSign.js index a751bd93a..bc0da686c 100644 --- a/modules/ticket/back/methods/ticket/saveSign.js +++ b/modules/ticket/back/methods/ticket/saveSign.js @@ -51,23 +51,23 @@ module.exports = Self => { fields: ['id'] }); - async function setLocation(ticketId) { + async function setLocation() { await models.Delivery.create({ - ticketFk: ticketId, + ticketFk: ticket.id, longitude: location.Longitude, latitude: location.Latitude, dated: signedTime || new Date() }, myOptions); } - async function hasSignDms(ticketId) { + async function hasSignDms() { const hasTicketDms = await Self.rawSql(` SELECT d.id FROM ticketDms td JOIN dms d ON d.id = td.dmsFk WHERE td.ticketFk = ? AND d.dmsTypeFk = ? - `, [ticketId, dmsTypeTicket.id], myOptions); + `, [ticket.id, dmsTypeTicket.id], myOptions); if (hasTicketDms.length) return true; } @@ -133,9 +133,9 @@ module.exports = Self => { if (await ticket.isSigned) throw new UserError('Ticket is already signed'); - if (location) await setLocation(ticketId); - if (!await hasSignDms(ticketId) && !isSignUploaded) - await createGestDoc(ticketId); + if (location) await setLocation(); + if (!await hasSignDms() && !isSignUploaded) + await createGestDoc(); if (isSignUploaded) await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions); await ticket.updateAttribute('isSigned', true, myOptions);