From 0c22c1b0de3e202816d2014b445aa21232c24bae Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 8 Mar 2023 17:30:28 +0100 Subject: [PATCH 1/4] refs #5368 Fix expedition-pallet-label --- .../reports/expedition-pallet-label/expedition-pallet-label.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js b/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js index 88645309d..d2fa59612 100644 --- a/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js +++ b/print/templates/reports/expedition-pallet-label/expedition-pallet-label.js @@ -22,6 +22,7 @@ module.exports = { this.labelsData = await this.rawSqlFromDef('labelData', this.id); this.username = await this.findOneFromDef('username', this.userFk); this.labelData = this.labelsData[0]; + this.checkMainEntity(this.labelData); let QRdata = JSON.stringify({ company: 'vnl', @@ -32,7 +33,6 @@ module.exports = { }); this.QR = await this.getQR(QRdata); - this.checkMainEntity(this.labelsData); }, methods: { getQR(id) { From c46d325e23149d263c593bfbab4545536403151f Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 9 Mar 2023 07:58:39 +0100 Subject: [PATCH 2/4] fix: add transaction --- back/models/account.js | 2 +- modules/invoiceOut/back/methods/invoiceOut/download.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/back/models/account.js b/back/models/account.js index c2502380a..6d71a4e52 100644 --- a/back/models/account.js +++ b/back/models/account.js @@ -131,7 +131,7 @@ module.exports = Self => { WHERE u.id = ?`, [userId], options); let roles = []; - for (role of result) + for (const role of result) roles.push(role.name); return roles; diff --git a/modules/invoiceOut/back/methods/invoiceOut/download.js b/modules/invoiceOut/back/methods/invoiceOut/download.js index 74f5c95fe..5c787428b 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/download.js +++ b/modules/invoiceOut/back/methods/invoiceOut/download.js @@ -65,7 +65,7 @@ module.exports = Self => { try { await fs.access(file.path); } catch (error) { - await Self.createPdf(ctx, id); + await Self.createPdf(ctx, id, myOptions); } const stream = fs.createReadStream(file.path); From 223b8f6d00c65634ed10803da07ce55044c996d3 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 9 Mar 2023 09:41:51 +0100 Subject: [PATCH 3/4] fix: intermittentBack test --- .../invoiceOut/specs/downloadZip.spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js index 41ea45487..115353679 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js @@ -15,6 +15,15 @@ describe('InvoiceOut downloadZip()', () => { it('should return part of link to dowloand the zip', async() => { const tx = await models.InvoiceOut.beginTransaction({}); + const promise = new Promise(resolve => resolve('streamObject')); + promise.path = 'storage/pdfs/invoice/2001/1/1/2001T4444444.pdf'; + + spyOn(models.InvoiceOut, 'download').and.returnValue([ + promise, + 'application/pdf', + 'filename="2001T1111111.pdf"' + ]); + try { const options = {transaction: tx}; @@ -32,6 +41,15 @@ describe('InvoiceOut downloadZip()', () => { it('should return an error if the size of the files is too large', async() => { const tx = await models.InvoiceOut.beginTransaction({}); + const promise = new Promise(resolve => resolve('streamObject')); + promise.path = 'storage/pdfs/invoice/2001/1/1/2001T4444444.pdf'; + + spyOn(models.InvoiceOut, 'download').and.returnValue([ + promise, + 'application/pdf', + 'filename="2001T1111111.pdf"' + ]); + let error; try { const options = {transaction: tx}; From c105316a041a1236071428df75952dc6d4259b0a Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 9 Mar 2023 10:05:24 +0100 Subject: [PATCH 4/4] delete testBack --- .../invoiceOut/specs/downloadZip.spec.js | 71 ------------------- 1 file changed, 71 deletions(-) delete mode 100644 modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js deleted file mode 100644 index 115353679..000000000 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/downloadZip.spec.js +++ /dev/null @@ -1,71 +0,0 @@ -const models = require('vn-loopback/server/server').models; -const UserError = require('vn-loopback/util/user-error'); - -describe('InvoiceOut downloadZip()', () => { - const userId = 9; - const invoiceIds = '1,2'; - const ctx = { - req: { - - accessToken: {userId: userId}, - headers: {origin: 'http://localhost:5000'}, - } - }; - - it('should return part of link to dowloand the zip', async() => { - const tx = await models.InvoiceOut.beginTransaction({}); - - const promise = new Promise(resolve => resolve('streamObject')); - promise.path = 'storage/pdfs/invoice/2001/1/1/2001T4444444.pdf'; - - spyOn(models.InvoiceOut, 'download').and.returnValue([ - promise, - 'application/pdf', - 'filename="2001T1111111.pdf"' - ]); - - try { - const options = {transaction: tx}; - - const result = await models.InvoiceOut.downloadZip(ctx, invoiceIds, options); - - expect(result).toBeDefined(); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); - - it('should return an error if the size of the files is too large', async() => { - const tx = await models.InvoiceOut.beginTransaction({}); - - const promise = new Promise(resolve => resolve('streamObject')); - promise.path = 'storage/pdfs/invoice/2001/1/1/2001T4444444.pdf'; - - spyOn(models.InvoiceOut, 'download').and.returnValue([ - promise, - 'application/pdf', - 'filename="2001T1111111.pdf"' - ]); - - let error; - try { - const options = {transaction: tx}; - const zipConfig = { - maxSize: 0 - }; - await models.ZipConfig.create(zipConfig, options); - - await models.InvoiceOut.downloadZip(ctx, invoiceIds, options); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - error = e; - } - - expect(error).toEqual(new UserError(`Files are too large`)); - }); -});