From 6e999302bf6c7b8bd1723ace8844457df0c94d68 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 11 Apr 2022 10:09:54 +0200 Subject: [PATCH] refactor: replace let for const --- modules/claim/back/methods/claim/deleteOldFiles.js | 6 ++---- .../claim/back/methods/claim/specs/downloadFile.spec.js | 6 +++--- modules/claim/back/methods/claim/specs/uploadFile.spec.js | 6 +++--- modules/claim/back/methods/claim/uploadFile.js | 7 +++---- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/modules/claim/back/methods/claim/deleteOldFiles.js b/modules/claim/back/methods/claim/deleteOldFiles.js index 292d980e3..410742c77 100644 --- a/modules/claim/back/methods/claim/deleteOldFiles.js +++ b/modules/claim/back/methods/claim/deleteOldFiles.js @@ -16,16 +16,14 @@ module.exports = Self => { }); Self.deleteOldFiles = async options => { - let tx; + const tx = await Self.beginTransaction({}); const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); + if (!myOptions.transaction) myOptions.transaction = tx; - } try { const claimContainer = './storage/claim'; diff --git a/modules/claim/back/methods/claim/specs/downloadFile.spec.js b/modules/claim/back/methods/claim/specs/downloadFile.spec.js index 44a54db63..3e46a9bc3 100644 --- a/modules/claim/back/methods/claim/specs/downloadFile.spec.js +++ b/modules/claim/back/methods/claim/specs/downloadFile.spec.js @@ -1,11 +1,11 @@ const app = require('vn-loopback/server/server'); describe('claim downloadFile()', () => { - let dmsId = 7; + const dmsId = 7; it('should return a response for an employee with image content-type', async() => { - let workerId = 1107; - let ctx = {req: {accessToken: {userId: workerId}}}; + const workerId = 1107; + const ctx = {req: {accessToken: {userId: workerId}}}; const result = await app.models.Claim.downloadFile(ctx, dmsId); expect(result[1]).toEqual('image/jpeg'); diff --git a/modules/claim/back/methods/claim/specs/uploadFile.spec.js b/modules/claim/back/methods/claim/specs/uploadFile.spec.js index 02852ed80..952d80d27 100644 --- a/modules/claim/back/methods/claim/specs/uploadFile.spec.js +++ b/modules/claim/back/methods/claim/specs/uploadFile.spec.js @@ -2,9 +2,9 @@ const app = require('vn-loopback/server/server'); describe('claim uploadFile()', () => { it(`should return an error for a user without enough privileges`, async() => { - let clientId = 1101; - let ticketDmsTypeId = 14; - let ctx = {req: {accessToken: {userId: clientId}}, args: {dmsTypeId: ticketDmsTypeId}}; + const clientId = 1101; + const ticketDmsTypeId = 14; + const ctx = {req: {accessToken: {userId: clientId}}, args: {dmsTypeId: ticketDmsTypeId}}; let error; await app.models.Claim.uploadFile(ctx).catch(e => { diff --git a/modules/claim/back/methods/claim/uploadFile.js b/modules/claim/back/methods/claim/uploadFile.js index e5071afaa..3d0737cf8 100644 --- a/modules/claim/back/methods/claim/uploadFile.js +++ b/modules/claim/back/methods/claim/uploadFile.js @@ -57,16 +57,15 @@ module.exports = Self => { }); Self.uploadFile = async(ctx, id, options) => { - let tx; + const tx = await Self.beginTransaction({}); const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); + if (!myOptions.transaction) myOptions.transaction = tx; - } + const models = Self.app.models; const promises = []; const TempContainer = models.TempContainer;