Merge pull request 'refs #6184 fixSaveSign' (!2096) from 6184-fixSaveSign into test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2096
This commit is contained in:
commit
8da9475eb1
|
@ -57,7 +57,7 @@ module.exports = Self => {
|
|||
AND dt.code = 'cmr'
|
||||
`, [ticketId]);
|
||||
|
||||
if (!dms.lenght) throw new UserError('Cmr file does not exist');
|
||||
if (!dms.length) throw new UserError('Cmr file does not exist');
|
||||
|
||||
const response = await models.Dms.downloadFile(ctx, dms[0].id);
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ module.exports = Self => {
|
|||
const myOptions = {userId: ctx.req.accessToken.userId};
|
||||
let tx;
|
||||
let ticket;
|
||||
let dms;
|
||||
let isSignUploaded;
|
||||
let externalTickets = [];
|
||||
|
||||
if (typeof options == 'object')
|
||||
|
@ -59,19 +61,15 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
async function hasSignDms(ticketId) {
|
||||
const ticketDms = await models.TicketDms.findOne({
|
||||
where: {ticketFk: ticketId},
|
||||
include: [
|
||||
{
|
||||
relation: 'dms',
|
||||
fields: ['id'],
|
||||
scope: {
|
||||
where: {dmsTypeFk: dmsTypeTicket.id}
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
if (ticketDms?.dms()?.id) return true;
|
||||
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);
|
||||
|
||||
if (hasTicketDms.length) return true;
|
||||
}
|
||||
|
||||
async function createGestDoc() {
|
||||
|
@ -84,8 +82,10 @@ module.exports = Self => {
|
|||
description: `Firma del cliente - Ruta ${ticket.route().id}`,
|
||||
hasFile: true
|
||||
};
|
||||
const dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
||||
await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions);
|
||||
dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
|
||||
// Si se ha subido ya la firma, no se vuelve a subir, ya que si no
|
||||
// da un error de deadlock en la db
|
||||
isSignUploaded = true;
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -112,17 +112,17 @@ module.exports = Self => {
|
|||
fields: ['id']
|
||||
}
|
||||
}]
|
||||
});
|
||||
}, myOptions);
|
||||
|
||||
const ticketState = await models.TicketState.findOne({
|
||||
where: {ticketFk: ticketId},
|
||||
fields: ['alertLevel']
|
||||
});
|
||||
}, myOptions);
|
||||
|
||||
const packedAlertLevel = await models.AlertLevel.findOne({
|
||||
where: {code: 'PACKED'},
|
||||
fields: ['id']
|
||||
});
|
||||
}, myOptions);
|
||||
|
||||
if (!ticketState)
|
||||
throw new UserError('Ticket does not exist');
|
||||
|
@ -134,12 +134,15 @@ module.exports = Self => {
|
|||
throw new UserError('Ticket is already signed');
|
||||
|
||||
if (location) await setLocation(ticketId);
|
||||
if (!await hasSignDms(ticketId)) await createGestDoc(ticketId);
|
||||
if (!await hasSignDms(ticketId) && !isSignUploaded)
|
||||
await createGestDoc(ticketId);
|
||||
if (isSignUploaded)
|
||||
await models.TicketDms.create({ticketFk: ticket.id, dmsFk: dms[0].id}, myOptions);
|
||||
await ticket.updateAttribute('isSigned', true, myOptions);
|
||||
|
||||
const deliveryState = await models.State.findOne({
|
||||
where: {code: 'DELIVERED'}
|
||||
});
|
||||
}, myOptions);
|
||||
|
||||
await models.Ticket.state(ctx, {
|
||||
ticketFk: ticketId,
|
||||
|
|
Loading…
Reference in New Issue