perf: refs #6184 Requested changes
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Guillermo Bonet 2023-11-13 08:36:05 +01:00
parent 05a7498219
commit 2792efa9cd
1 changed files with 16 additions and 15 deletions

View File

@ -31,38 +31,39 @@ module.exports = Self => {
}
try {
const dmsTypeCmr = await models.DmsType.findOne({
where: {code: 'cmr'},
fields: ['id']
}, myOptions);
for (const ticketId of tickets) {
const ticket = await models.Ticket.findById(ticketId, myOptions);
if (ticket.cmrFk) {
const dmsType = await models.DmsType.findOne({
where: {code: 'cmr'},
fields: ['id']
}, myOptions);
const hasDmsCmr = await models.TicketDms.findOne({
where: { ticketFk: ticketId },
include: {
relation: 'dms',
fields: ['dmsFk'],
scope: {
where: { dmsTypeFk: dmsType.id }
where: { dmsTypeFk: dmsTypeCmr.id }
}
}
}, myOptions);
if (!hasDmsCmr.dms()) {
const zip = await models.Route.downloadCmrsZip(ctx, ticket.cmrFk.toString(), myOptions);
let ctxUploadFile;
ctx.req.file = Object.assign({}, zip);
ctxUploadFile = Object.assign({}, ctx);
ctxUploadFile.args = {
warehouseId: ticket.warehouseFk,
companyId: ticket.companyFk,
dmsTypeId: dmsType.id,
reference: '',
description: `${ticket.cmrFk} - ${ticket.id}`,
hasFile: false
const ctxUploadFile = {
...ctx,
args: {
warehouseId: ticket.warehouseFk,
companyId: ticket.companyFk,
dmsTypeId: dmsTypeCmr.id,
reference: ticket.id,
description: `${ticket.cmrFk} - ${ticket.id}`,
hasFile: false
}
};
const dms = await models.Dms.uploadFile(ctxUploadFile, myOptions);
await models.TicketDms.create({