From c81ca94d2e5c8d7e1a5cb94e2d2da1c0f23dcdce Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 11 Dec 2023 14:44:33 +0100 Subject: [PATCH 01/21] refs #6220 add filter address --- modules/client/back/methods/client/filter.js | 56 +++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index 47d5f6d2f..782d355ca 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -129,25 +129,43 @@ module.exports = Self => { const stmts = []; const stmt = new ParameterizedSQL( `SELECT - DISTINCT c.id, - c.name, - c.fi, - c.socialName, - c.phone, - c.mobile, - c.city, - c.postcode, - c.email, - c.isActive, - c.isFreezed, - p.id AS provinceFk, - p.name AS province, - u.id AS salesPersonFk, - u.name AS salesPerson - FROM client c - LEFT JOIN account.user u ON u.id = c.salesPersonFk - LEFT JOIN province p ON p.id = c.provinceFk - JOIN vn.address a ON a.clientFk = c.id + DISTINCT c.id, + c.name, + c.fi, + c.socialName, + c.phone, + c.mobile, + c.city, + c.postcode, + c.email, + c.isActive, + c.isFreezed, + p.id AS provinceFk, + p.name AS province, + u.id AS salesPersonFk, + u.name AS salesPerson, + a.street, + a.city AS addressCity, + a.provinceFk AS addressProvinceFk, + a.postalCode AS addressPostalCode, + a.phone AS addressPhone, + a.mobile AS addressMobile, + a.nickname, + a.isDefaultAddress, + a.agencyModeFk AS addressAgencyModeFk, + a.isActive AS addressIsActive, + a.longitude AS addressLongitude, + a.latitude AS addressLatitude, + a.isEqualizated, + a.customsAgentFk AS addressCustomsAgentFk, + a.incotermsFk AS addressIncotermsFk, + a.isLogifloraAllowed, + a.editorFk AS addressEditorFk + FROM client c + LEFT JOIN account.user u ON u.id = c.salesPersonFk + LEFT JOIN province p ON p.id = c.provinceFk + JOIN vn.address a ON a.clientFk = c.id; + ` ); From 7e6f311a431502c72abd7116a76518638bcc0160 Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 11 Dec 2023 14:51:11 +0100 Subject: [PATCH 02/21] refs #6220 address filter --- modules/client/back/methods/client/filter.js | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index 782d355ca..d88f15c3f 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -140,27 +140,27 @@ module.exports = Self => { c.email, c.isActive, c.isFreezed, - p.id AS provinceFk, - p.name AS province, - u.id AS salesPersonFk, - u.name AS salesPerson, + p.id, + p.name, + u.id, + u.name, a.street, - a.city AS addressCity, - a.provinceFk AS addressProvinceFk, - a.postalCode AS addressPostalCode, - a.phone AS addressPhone, - a.mobile AS addressMobile, + a.city, + a.provinceFk, + a.postalCode, + a.phone, + a.mobile, a.nickname, a.isDefaultAddress, - a.agencyModeFk AS addressAgencyModeFk, - a.isActive AS addressIsActive, - a.longitude AS addressLongitude, - a.latitude AS addressLatitude, + a.agencyModeFk, + a.isActive, + a.longitude, + a.latitude, a.isEqualizated, - a.customsAgentFk AS addressCustomsAgentFk, - a.incotermsFk AS addressIncotermsFk, + a.customsAgentFk, + a.incotermsFk, a.isLogifloraAllowed, - a.editorFk AS addressEditorFk + a.editorFk FROM client c LEFT JOIN account.user u ON u.id = c.salesPersonFk LEFT JOIN province p ON p.id = c.provinceFk From ae767762451137bb58fcaee927f8b401cfe18284 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 12 Dec 2023 12:09:06 +0100 Subject: [PATCH 03/21] refs #2051 feat: removeFile approach --- back/methods/dms/removeFile.js | 15 +++++++---- back/methods/dms/specs/removeFile.spec.js | 2 +- .../back/methods/claim-dms/removeFile.js | 16 ++++++------ .../claim-dms/specs/removeFile.spec.js | 3 ++- .../client-dms/specs/removeFile.spec.js | 3 ++- .../back/methods/ticket-dms/removeFile.js | 14 +++++------ .../ticket-dms/specs/removeFile.spec.js | 2 +- .../back/methods/worker-dms/removeFile.js | 25 ++++++++++++++++--- .../worker-dms/specs/removeFile.spec.js | 3 ++- 9 files changed, 54 insertions(+), 29 deletions(-) diff --git a/back/methods/dms/removeFile.js b/back/methods/dms/removeFile.js index a9ff36883..cb81ff322 100644 --- a/back/methods/dms/removeFile.js +++ b/back/methods/dms/removeFile.js @@ -34,20 +34,25 @@ module.exports = Self => { } try { - const dms = await models.Dms.findById(id, null, myOptions); + let modelDms = null; + if (myOptions.model) { + modelDms = await models[myOptions.model].findById(id, null, myOptions); + id = modelDms.dmsFk; + } + const targetDms = await models.Dms.findById(id, null, myOptions); const trashDmsType = await models.DmsType.findOne({ where: {code: 'trash'} }, myOptions); - const hasWriteRole = await models.DmsType.hasWriteRole(ctx, dms.dmsTypeFk, myOptions); + const hasWriteRole = await models.DmsType.hasWriteRole(ctx, targetDms.dmsTypeFk, myOptions); if (!hasWriteRole) throw new UserError(`You don't have enough privileges`); - await dms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions); + await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions); if (tx) await tx.commit(); - - return dms; + if (modelDms) modelDms.destroy(myOptions); + return targetDms; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/back/methods/dms/specs/removeFile.spec.js b/back/methods/dms/specs/removeFile.spec.js index 59a2acecb..e0d1dc1e7 100644 --- a/back/methods/dms/specs/removeFile.spec.js +++ b/back/methods/dms/specs/removeFile.spec.js @@ -1,6 +1,6 @@ const {models} = require('vn-loopback/server/server'); -describe('dms removeFile()', () => { +fdescribe('dms removeFile()', () => { let dmsId = 1; it(`should return an error for a user without enough privileges`, async() => { diff --git a/modules/claim/back/methods/claim-dms/removeFile.js b/modules/claim/back/methods/claim-dms/removeFile.js index edc714235..257b09cf2 100644 --- a/modules/claim/back/methods/claim-dms/removeFile.js +++ b/modules/claim/back/methods/claim-dms/removeFile.js @@ -31,15 +31,15 @@ module.exports = Self => { } try { - const models = Self.app.models; - const targetClaimDms = await models.ClaimDms.findById(id, null, myOptions); - const targetDms = await models.Dms.findById(targetClaimDms.dmsFk, null, myOptions); - const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}}, myOptions); + // const {models: ClaimDms, Dms} = Self.app.models; + // const targetClaimDms = await ClaimDms.findById(id, null, myOptions); + // await Dms.findById(targetClaimDms.dmsFk, null, myOptions); + // const trashDmsType = await DmsType.findOne({where: {code: 'trash'}}, myOptions); + myOptions.model = 'ClaimDms'; + const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions); + // await targetClaimDms.destroy(myOptions); - await models.Dms.removeFile(ctx, targetClaimDms.dmsFk, myOptions); - await targetClaimDms.destroy(myOptions); - - await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions); + // await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions); if (tx) await tx.commit(); diff --git a/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js b/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js index 1cd3b16cb..210d805e7 100644 --- a/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js +++ b/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js @@ -1,6 +1,7 @@ const app = require('vn-loopback/server/server'); -describe('TicketDms removeFile()', () => { +// f +fdescribe('TicketDms removeFile()', () => { const ticketDmsId = 1; it(`should return an error for a user without enough privileges`, async() => { let clientId = 1101; diff --git a/modules/client/back/methods/client-dms/specs/removeFile.spec.js b/modules/client/back/methods/client-dms/specs/removeFile.spec.js index 6dac71293..61a00a610 100644 --- a/modules/client/back/methods/client-dms/specs/removeFile.spec.js +++ b/modules/client/back/methods/client-dms/specs/removeFile.spec.js @@ -1,6 +1,7 @@ const models = require('vn-loopback/server/server').models; -describe('ClientDms removeFile()', () => { +// f +fdescribe('ClientDms removeFile()', () => { it(`should return an error for a user without enough privileges`, async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket-dms/removeFile.js b/modules/ticket/back/methods/ticket-dms/removeFile.js index f48dc7fef..2e3ccd149 100644 --- a/modules/ticket/back/methods/ticket-dms/removeFile.js +++ b/modules/ticket/back/methods/ticket-dms/removeFile.js @@ -19,7 +19,6 @@ module.exports = Self => { }); Self.removeFile = async(ctx, id, options) => { - const models = Self.app.models; const myOptions = {}; let tx; @@ -32,14 +31,15 @@ module.exports = Self => { } try { - const targetTicketDms = await models.TicketDms.findById(id, null, myOptions); - const targetDms = await models.Dms.findById(targetTicketDms.dmsFk, null, myOptions); - const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}}, myOptions); + // const targetTicketDms = await models.TicketDms.findById(id, null, myOptions); + myOptions.model = 'TicketDms'; + // await models.Dms.findById(targetTicketDms.dmsFk, null, myOptions); + // const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}}, myOptions); - await models.Dms.removeFile(ctx, targetTicketDms.dmsFk, myOptions); - await targetTicketDms.destroy(myOptions); + const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions); + // await targetTicketDms.destroy(myOptions); - await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions); + // await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions); if (tx) await tx.commit(); diff --git a/modules/ticket/back/methods/ticket-dms/specs/removeFile.spec.js b/modules/ticket/back/methods/ticket-dms/specs/removeFile.spec.js index 9296984c3..ca4cb5bc3 100644 --- a/modules/ticket/back/methods/ticket-dms/specs/removeFile.spec.js +++ b/modules/ticket/back/methods/ticket-dms/specs/removeFile.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -describe('TicketDms removeFile()', () => { +fdescribe('TicketDms removeFile()', () => { const ticketDmsId = 1; it(`should return an error for a user without enough privileges`, async() => { const tx = await models.TicketDms.beginTransaction({}); diff --git a/modules/worker/back/methods/worker-dms/removeFile.js b/modules/worker/back/methods/worker-dms/removeFile.js index b441c56ce..397255bb2 100644 --- a/modules/worker/back/methods/worker-dms/removeFile.js +++ b/modules/worker/back/methods/worker-dms/removeFile.js @@ -18,13 +18,30 @@ module.exports = Self => { } }); - Self.removeFile = async(ctx, id) => { + Self.removeFile = async(ctx, id, options) => { const models = Self.app.models; - const workerDms = await Self.findById(id); + let tx; + try { + const myOptions = {}; - await models.Dms.removeFile(ctx, workerDms.dmsFk); + if (typeof options == 'object') + Object.assign(myOptions, options); - return workerDms.destroy(); + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + // const workerDms = await Self.findById(id); + myOptions.model = 'WorkerDms'; + await models.Dms.removeFile(ctx, id, myOptions); + // await workerDms.destroy(); + if (tx) await tx.commit(); + + return workerDms; + } catch (e) { + await tx.rollback(); + throw e; + } }; }; diff --git a/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js b/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js index 3efd09464..e66628656 100644 --- a/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js +++ b/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js @@ -1,6 +1,7 @@ const app = require('vn-loopback/server/server'); -describe('WorkerDms removeFile()', () => { +// f +fdescribe('WorkerDms removeFile()', () => { const workerDmsFk = 1; it(`should return an error for a user without enough privileges`, async() => { let clientId = 1101; From 6cefc982e46261dd680e7e1d5797a2d2ffd1daa9 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 12 Dec 2023 13:14:41 +0100 Subject: [PATCH 04/21] refs #6220 add filter address --- modules/client/back/methods/client/filter.js | 81 ++++++++++---------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index d88f15c3f..43310c86b 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -107,17 +107,29 @@ module.exports = Self => { return {or: [ {'c.phone': {like: `%${value}%`}}, {'c.mobile': {like: `%${value}%`}}, + {'a.phone': {like: `%${value}%`}}, ]}; case 'zoneFk': - param = 'a.postalCode'; - return {[param]: {inq: postalCode}}; + return {'a.postalCode': {inq: postalCode}}; + case 'city': + return {or: [ + {'c.city': {like: `%${value}`}}, + {'a.city': {like: `%${value}`}} + ]}; + case 'postcode': + return {or: [ + {'c.postcode': {like: `%${value}`}}, + {'a.postalCode': {like: `%${value}`}} + ]}; + case 'provinceFk': + return {or: [ + {'p.name': {like: `%${value}`}}, + {'a.provinceFk': {like: `%${value}`}} + ]}; case 'name': case 'salesPersonFk': case 'fi': case 'socialName': - case 'city': - case 'postcode': - case 'provinceFk': case 'email': param = `c.${param}`; return {[param]: {like: `%${value}%`}}; @@ -129,47 +141,32 @@ module.exports = Self => { const stmts = []; const stmt = new ParameterizedSQL( `SELECT - DISTINCT c.id, - c.name, - c.fi, - c.socialName, - c.phone, - c.mobile, - c.city, - c.postcode, - c.email, - c.isActive, - c.isFreezed, - p.id, - p.name, - u.id, - u.name, - a.street, - a.city, - a.provinceFk, - a.postalCode, - a.phone, - a.mobile, - a.nickname, - a.isDefaultAddress, - a.agencyModeFk, - a.isActive, - a.longitude, - a.latitude, - a.isEqualizated, - a.customsAgentFk, - a.incotermsFk, - a.isLogifloraAllowed, - a.editorFk - FROM client c - LEFT JOIN account.user u ON u.id = c.salesPersonFk - LEFT JOIN province p ON p.id = c.provinceFk - JOIN vn.address a ON a.clientFk = c.id; - + DISTINCT c.id, + c.name, + c.fi, + c.socialName, + CONCAT(c.phone, ',',GROUP_CONCAT(DISTINCT a.phone)) phone, + c.mobile, + CONCAT(c.city, ',',GROUP_CONCAT(DISTINCT a.city)) city, + c.postcode, + a.postalCode, + c.email, + c.isActive, + c.isFreezed, + p.id AS provinceFk2, + a.provinceFk, + p.name AS province, + u.id AS salesPersonFk, + u.name AS salesPerson + FROM client c + LEFT JOIN account.user u ON u.id = c.salesPersonFk + LEFT JOIN province p ON p.id = c.provinceFk + JOIN address a ON a.clientFk = c.id ` ); stmt.merge(conn.makeWhere(filter.where)); + stmt.merge('GROUP BY c.id'); stmt.merge(conn.makePagination(filter)); const clientsIndex = stmts.push(stmt) - 1; From 78aa25d74fe7b34c58d9dc0224db3b47312a73d0 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 12 Dec 2023 13:21:08 +0100 Subject: [PATCH 05/21] refs #6220 fix testback --- modules/client/back/methods/client/specs/filter.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/client/back/methods/client/specs/filter.spec.js b/modules/client/back/methods/client/specs/filter.spec.js index 679585050..4a61f8aaf 100644 --- a/modules/client/back/methods/client/specs/filter.spec.js +++ b/modules/client/back/methods/client/specs/filter.spec.js @@ -146,7 +146,7 @@ describe('client filter()', () => { const randomResultClient = result[randomIndex]; expect(result.length).toBeGreaterThanOrEqual(20); - expect(randomResultClient.city.toLowerCase()).toEqual('gotham'); + expect(randomResultClient.city.toLowerCase()).toEqual('gotham,gotham'); await tx.rollback(); } catch (e) { From 6b70f8b3eb0c5d5111adf0df1f2af77dc1083382 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 12 Dec 2023 13:49:14 +0100 Subject: [PATCH 06/21] refs #2051 feat: uploadFile approach --- .../claim/back/methods/claim/uploadFile.js | 116 +++++++----------- .../client/back/methods/client/uploadFile.js | 24 ++-- .../methods/ticket/specs/uploadFile.spec.js | 27 +++- .../ticket/back/methods/ticket/uploadFile.js | 10 +- .../methods/worker/specs/uploadFile.spec.js | 4 +- .../worker/back/methods/worker/uploadFile.js | 32 +++-- 6 files changed, 113 insertions(+), 100 deletions(-) diff --git a/modules/claim/back/methods/claim/uploadFile.js b/modules/claim/back/methods/claim/uploadFile.js index 3d0737cf8..7e4798fef 100644 --- a/modules/claim/back/methods/claim/uploadFile.js +++ b/modules/claim/back/methods/claim/uploadFile.js @@ -1,6 +1,3 @@ -const UserError = require('vn-loopback/util/user-error'); -const fs = require('fs-extra'); -const path = require('path'); module.exports = Self => { Self.remoteMethodCtx('uploadFile', { @@ -57,96 +54,75 @@ module.exports = Self => { }); Self.uploadFile = async(ctx, id, options) => { - const tx = await Self.beginTransaction({}); + const models = Self.app.models; const myOptions = {}; + let tx; if (typeof options == 'object') Object.assign(myOptions, options); - if (!myOptions.transaction) + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); myOptions.transaction = tx; + } - const models = Self.app.models; - const promises = []; - const TempContainer = models.TempContainer; - const ClaimContainer = models.ClaimContainer; - const fileOptions = {}; - const args = ctx.args; + // const promises = []; + // const TempContainer = models.TempContainer; + // const ClaimContainer = models.ClaimContainer; + // const fileOptions = {}; + // const args = ctx.args; - let srcFile; + // let srcFile; try { - const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId, myOptions); - if (!hasWriteRole) - throw new UserError(`You don't have enough privileges`); + myOptions.model = 'ClaimDms'; + myOptions.create = {claimFk: id}; + const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions); - // Upload file to temporary path - const tempContainer = await TempContainer.container('dms'); - const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions); - const files = Object.values(uploaded.files).map(file => { - return file[0]; - }); + // const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId, myOptions); + // if (!hasWriteRole) + // throw new UserError(`You don't have enough privileges`); - const addedDms = []; - for (const uploadedFile of files) { - const newDms = await createDms(ctx, uploadedFile, myOptions); - const pathHash = ClaimContainer.getHash(newDms.id); + // // Upload file to temporary path + // const tempContainer = await TempContainer.container('dms'); + // const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions); + // const files = Object.values(uploaded.files).map(file => { + // return file[0]; + // }); - const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name); - srcFile = path.join(file.client.root, file.container, file.name); + // const addedDms = []; + // for (const uploadedFile of files) { + // const newDms = await createDms(ctx, uploadedFile, myOptions); + // const pathHash = ClaimContainer.getHash(newDms.id); - const claimContainer = await ClaimContainer.container(pathHash); - const dstFile = path.join(claimContainer.client.root, pathHash, newDms.file); + // const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name); + // srcFile = path.join(file.client.root, file.container, file.name); - await fs.move(srcFile, dstFile, { - overwrite: true - }); + // const claimContainer = await ClaimContainer.container(pathHash); + // const dstFile = path.join(claimContainer.client.root, pathHash, newDms.file); - addedDms.push(newDms); - } + // await fs.move(srcFile, dstFile, { + // overwrite: true + // }); - addedDms.forEach(dms => { - const newClaimDms = models.ClaimDms.create({ - claimFk: id, - dmsFk: dms.id - }, myOptions); + // addedDms.push(newDms); + // } - promises.push(newClaimDms); - }); - const resolvedPromises = await Promise.all(promises); + // addedDms.forEach(dms => { + // const newClaimDms = models.ClaimDms.create({ + // claimFk: id, + // dmsFk: dms.id + // }, myOptions); + + // promises.push(newClaimDms); + // }); + // const resolvedPromises = await Promise.all(promises); if (tx) await tx.commit(); - return resolvedPromises; + return uploadedFiles; } catch (e) { if (tx) await tx.rollback(); - - if (fs.existsSync(srcFile)) - await fs.unlink(srcFile); - throw e; } }; - - async function createDms(ctx, file, myOptions) { - const models = Self.app.models; - const myUserId = ctx.req.accessToken.userId; - const args = ctx.args; - - const newDms = await models.Dms.create({ - workerFk: myUserId, - dmsTypeFk: args.dmsTypeId, - companyFk: args.companyId, - warehouseFk: args.warehouseId, - reference: args.reference, - description: args.description, - contentType: file.type, - hasFile: args.hasFile - }, myOptions); - - let fileName = file.name; - const extension = models.DmsContainer.getFileExtension(fileName); - fileName = `${newDms.id}.${extension}`; - - return newDms.updateAttribute('file', fileName, myOptions); - } }; diff --git a/modules/client/back/methods/client/uploadFile.js b/modules/client/back/methods/client/uploadFile.js index 99ede27c6..8f471f1b6 100644 --- a/modules/client/back/methods/client/uploadFile.js +++ b/modules/client/back/methods/client/uploadFile.js @@ -56,8 +56,8 @@ module.exports = Self => { Self.uploadFile = async(ctx, id, options) => { const models = Self.app.models; - let tx; const myOptions = {}; + let tx; if (typeof options == 'object') Object.assign(myOptions, options); @@ -67,23 +67,25 @@ module.exports = Self => { myOptions.transaction = tx; } - const promises = []; + // const promises = []; try { + myOptions.model = 'ClientDms'; + myOptions.create = {clientFk: id}; const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions); - uploadedFiles.forEach(dms => { - const newClientDms = models.ClientDms.create({ - clientFk: id, - dmsFk: dms.id - }, myOptions); + // uploadedFiles.forEach(dms => { + // const newClientDms = models.ClientDms.create({ + // clientFk: id, + // dmsFk: dms.id + // }, myOptions); - promises.push(newClientDms); - }); - const resolvedPromises = await Promise.all(promises); + // promises.push(newClientDms); + // }); + // const resolvedPromises = await Promise.all(promises); if (tx) await tx.commit(); - return resolvedPromises; + return uploadedFiles; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js b/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js index 133c13265..8c01133e6 100644 --- a/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js +++ b/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; - -describe('Ticket uploadFile()', () => { +// f +fdescribe('Ticket uploadFile()', () => { it(`should return an error for a user without enough privileges`, async() => { const tx = await models.Ticket.beginTransaction({}); @@ -23,4 +23,27 @@ describe('Ticket uploadFile()', () => { expect(error.message).toEqual(`You don't have enough privileges`); }); + + // fit(`should uploadFile`, async() => { + // const tx = await models.Ticket.beginTransaction({}); + + // let error; + // try { + // const options = {transaction: tx}; + + // const ticketId = 15; + // const currentUserId = 9; + // const ticketTypeId = 14; + // const ctx = {req: {accessToken: {userId: currentUserId}}, args: {dmsTypeId: ticketTypeId}, result: new ArrayBuffer(20000)}; + + // await models.Ticket.uploadFile(ctx, ticketId, options); + + // await tx.rollback(); + // } catch (e) { + // await tx.rollback(); + // error = e; + // } + + // expect(error.message).toEqual(`You don't have enough privileges`); + // }); }); diff --git a/modules/ticket/back/methods/ticket/uploadFile.js b/modules/ticket/back/methods/ticket/uploadFile.js index 4de9904e1..63bbe845a 100644 --- a/modules/ticket/back/methods/ticket/uploadFile.js +++ b/modules/ticket/back/methods/ticket/uploadFile.js @@ -59,10 +59,12 @@ module.exports = Self => { myOptions.transaction = tx; } - const promises = []; + // const promises = []; try { + myOptions.model = 'TicketDms'; + myOptions.create = {ticketFk: id}; const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions); - uploadedFiles.forEach(dms => { + /* uploadedFiles.forEach(dms => { const newTicketDms = models.TicketDms.create({ ticketFk: id, dmsFk: dms.id @@ -71,10 +73,10 @@ module.exports = Self => { promises.push(newTicketDms); }); const resolvedPromises = await Promise.all(promises); - +*/ if (tx) await tx.commit(); - return resolvedPromises; + return uploadedFiles; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/worker/back/methods/worker/specs/uploadFile.spec.js b/modules/worker/back/methods/worker/specs/uploadFile.spec.js index 7a929cd2b..34426c6a0 100644 --- a/modules/worker/back/methods/worker/specs/uploadFile.spec.js +++ b/modules/worker/back/methods/worker/specs/uploadFile.spec.js @@ -1,6 +1,6 @@ const app = require('vn-loopback/server/server'); - -describe('Worker uploadFile()', () => { +// f +fdescribe('Worker uploadFile()', () => { it(`should return an error for a user without enough privileges`, async() => { let workerId = 1106; let currentUserId = 1102; diff --git a/modules/worker/back/methods/worker/uploadFile.js b/modules/worker/back/methods/worker/uploadFile.js index 588cfe4bd..e624dc904 100644 --- a/modules/worker/back/methods/worker/uploadFile.js +++ b/modules/worker/back/methods/worker/uploadFile.js @@ -48,14 +48,24 @@ module.exports = Self => { Self.uploadFile = async(ctx, id) => { const models = Self.app.models; - const promises = []; - const tx = await Self.beginTransaction({}); + const myOptions = {}; + let tx; + // const promises = []; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } try { - const options = {transaction: tx}; + myOptions.model = 'WorkerDms'; + myOptions.create = {workerFk: id}; - const uploadedFiles = await models.Dms.uploadFile(ctx, options); - uploadedFiles.forEach(dms => { + const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions); + /* uploadedFiles.forEach(dms => { const newWorkerDms = models.WorkerDms.create({ workerFk: id, dmsFk: dms.id @@ -64,13 +74,13 @@ module.exports = Self => { promises.push(newWorkerDms); }); const resolvedPromises = await Promise.all(promises); +*/ + if (tx) await tx.commit(); - await tx.commit(); - - return resolvedPromises; - } catch (err) { - await tx.rollback(); - throw err; + return uploadedFiles; + } catch (e) { + if (tx) await tx.rollback(); + throw e; } }; }; From 6334431d2b01ba0bbfc559ac69c30719e8d48c10 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 12 Dec 2023 14:00:35 +0100 Subject: [PATCH 07/21] refs #2051 feat: uploadFile approach --- back/methods/dms/uploadFile.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index a4212b804..abed95a3a 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -96,8 +96,21 @@ module.exports = Self => { } if (tx) await tx.commit(); + const promises = []; + const {model, create} = myOptions; + addedDms.forEach(dms => { + const newDms = models[model].create({ + ...create, + dmsFk: dms.id + }, myOptions); - return addedDms; + promises.push(newDms); + }); + const resolvedPromises = await Promise.all(promises); + + // if (tx) await tx.commit(); + + return resolvedPromises; } catch (e) { if (tx) await tx.rollback(); From d206c93305e490024b12751d90fcd335668dafdb Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 12 Dec 2023 15:03:00 +0100 Subject: [PATCH 08/21] refs #2051 feat: getAllowedContentTypes approach --- front/salix/components/index.js | 1 + front/salix/components/section-dms/index.js | 24 +++++++++ front/salix/components/section-dms/style.scss | 0 modules/client/front/dms/create/index.js | 54 ++++++++----------- modules/client/front/dms/edit/index.js | 41 ++++++-------- modules/invoiceIn/front/basic-data/index.js | 15 ++---- .../agency-term/createInvoiceIn/index.js | 45 ++++++---------- modules/ticket/front/dms/create/index.js | 53 ++++++++---------- modules/ticket/front/dms/edit/index.js | 41 ++++++-------- .../travel/front/thermograph/create/index.js | 8 +-- .../travel/front/thermograph/edit/index.js | 13 ++--- modules/worker/front/dms/create/index.js | 11 ++-- modules/worker/front/dms/edit/index.js | 42 ++++++--------- 13 files changed, 142 insertions(+), 206 deletions(-) create mode 100644 front/salix/components/section-dms/index.js create mode 100644 front/salix/components/section-dms/style.scss diff --git a/front/salix/components/index.js b/front/salix/components/index.js index 38b0d0e1f..e843f2f5e 100644 --- a/front/salix/components/index.js +++ b/front/salix/components/index.js @@ -15,6 +15,7 @@ import './module-card'; import './module-main'; import './side-menu/side-menu'; import './section'; +import './section-dms'; import './summary'; import './topbar/topbar'; import './user-popover'; diff --git a/front/salix/components/section-dms/index.js b/front/salix/components/section-dms/index.js new file mode 100644 index 000000000..ae7d496cd --- /dev/null +++ b/front/salix/components/section-dms/index.js @@ -0,0 +1,24 @@ +import ngModule from '../../module'; +import Component from 'core/lib/component'; +import './style.scss'; + +export default class SectionDms extends Component { + getAllowedContentTypes() { + return this.$http.get('DmsContainers/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + return contentTypes; + }); + } + + getDms(dmsId) { + return this.$http.get(`Dms/${dmsId}`).then(res => res); + } + getDmsTypes(params) { + return this.$http.get('DmsTypes/findOne', params).then(res => res); + } +} + +ngModule.vnComponent('vnSectionDms', { + controller: SectionDms +}); diff --git a/front/salix/components/section-dms/style.scss b/front/salix/components/section-dms/style.scss new file mode 100644 index 000000000..e69de29bb diff --git a/modules/client/front/dms/create/index.js b/modules/client/front/dms/create/index.js index 461d0aa36..ec8837981 100644 --- a/modules/client/front/dms/create/index.js +++ b/modules/client/front/dms/create/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import Section from 'salix/components/section'; +import SectionDms from 'salix/components/section-dms'; import './style.scss'; -class Controller extends Section { +class Controller extends SectionDms { constructor($element, $) { super($element, $); this.dms = { @@ -20,46 +20,36 @@ class Controller extends Section { this._client = value; if (value) { - this.setDefaultParams(); - this.getAllowedContentTypes(); + const params = {filter: { + where: {code: 'paymentsLaw'} + }}; + this.getDmsTypes(params).then(res => this.handleDefaultParams(res)); + this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); } } - getAllowedContentTypes() { - this.$http.get('DmsContainers/allowedContentTypes').then(res => { - const contentTypes = res.data.join(', '); - this.allowedContentTypes = contentTypes; - }); - } - get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } - setDefaultParams() { - const params = {filter: { - where: {code: 'paymentsLaw'} - }}; - this.$http.get('DmsTypes/findOne', {params}).then(res => { - const dmsType = res.data && res.data; - const companyId = this.vnConfig.companyFk; - const warehouseId = this.vnConfig.warehouseFk; - const defaultParams = { - reference: this.client.id, - warehouseId: warehouseId, - companyId: companyId, - dmsTypeId: dmsType.id, - description: this.$t('ClientFileDescription', { - dmsTypeName: dmsType.name, - clientId: this.client.id, - clientName: this.client.name - }).toUpperCase() - }; + handleDefaultParams({data: dmsType}) { + const companyId = this.vnConfig.companyFk; + const warehouseId = this.vnConfig.warehouseFk; + const defaultParams = { + reference: this.client.id, + warehouseId: warehouseId, + companyId: companyId, + dmsTypeId: dmsType.id, + description: this.$t('ClientFileDescription', { + dmsTypeName: dmsType.name, + clientId: this.client.id, + clientName: this.client.name + }).toUpperCase() + }; - this.dms = Object.assign(this.dms, defaultParams); - }); + this.dms = Object.assign(this.dms, defaultParams); } onSubmit() { diff --git a/modules/client/front/dms/edit/index.js b/modules/client/front/dms/edit/index.js index 8765eeff2..36c1a9672 100644 --- a/modules/client/front/dms/edit/index.js +++ b/modules/client/front/dms/edit/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import Section from 'salix/components/section'; +import SectionDms from 'salix/components/section-dms'; import './style.scss'; -class Controller extends Section { +class Controller extends SectionDms { get client() { return this._client; } @@ -11,39 +11,28 @@ class Controller extends Section { this._client = value; if (value) { - this.setDefaultParams(); - this.getAllowedContentTypes(); + this.getDms(this.$params.dmsId).then(handleDefaultParams); + this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); } } - getAllowedContentTypes() { - this.$http.get('DmsContainers/allowedContentTypes').then(res => { - const contentTypes = res.data.join(', '); - this.allowedContentTypes = contentTypes; - }); - } - get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } - setDefaultParams() { - const path = `Dms/${this.$params.dmsId}`; - this.$http.get(path).then(res => { - const dms = res.data && res.data; - this.dms = { - reference: dms.reference, - warehouseId: dms.warehouseFk, - companyId: dms.companyFk, - dmsTypeId: dms.dmsTypeFk, - description: dms.description, - hasFile: dms.hasFile, - hasFileAttached: false, - files: [] - }; - }); + handleDefaultParams({data: dms}) { + this.dms = { + reference: dms.reference, + warehouseId: dms.warehouseFk, + companyId: dms.companyFk, + dmsTypeId: dms.dmsTypeFk, + description: dms.description, + hasFile: dms.hasFile, + hasFileAttached: false, + files: [] + }; } onSubmit() { diff --git a/modules/invoiceIn/front/basic-data/index.js b/modules/invoiceIn/front/basic-data/index.js index 246f1b16f..797fda59d 100644 --- a/modules/invoiceIn/front/basic-data/index.js +++ b/modules/invoiceIn/front/basic-data/index.js @@ -1,8 +1,8 @@ import ngModule from '../module'; -import Section from 'salix/components/section'; +import SectionDms from 'salix/components/section-dms'; import UserError from 'core/lib/user-error'; -class Controller extends Section { +class Controller extends SectionDms { constructor($element, $, vnFile) { super($element, $, vnFile); this.dms = { @@ -11,7 +11,7 @@ class Controller extends Section { hasFileAttached: false }; this.vnFile = vnFile; - this.getAllowedContentTypes(); + this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); this._editDownloadDisabled = false; } @@ -53,15 +53,6 @@ class Controller extends Section { }); } - getAllowedContentTypes() { - this.$http.get('DmsContainers/allowedContentTypes').then(res => { - if (res.data.length > 0) { - const contentTypes = res.data.join(', '); - this.allowedContentTypes = contentTypes; - } - }); - } - openEditDialog(dmsId) { this.getFile(dmsId).then(() => this.$.dmsEditDialog.show()); } diff --git a/modules/route/front/agency-term/createInvoiceIn/index.js b/modules/route/front/agency-term/createInvoiceIn/index.js index 0198ab80f..5e54f7929 100644 --- a/modules/route/front/agency-term/createInvoiceIn/index.js +++ b/modules/route/front/agency-term/createInvoiceIn/index.js @@ -1,9 +1,9 @@ import ngModule from '../../module'; -import Section from 'salix/components/section'; +import SectionDms from 'salix/components/section-dms'; import './style.scss'; import UserError from 'core/lib/user-error'; -class Controller extends Section { +class Controller extends SectionDms { constructor($element, $) { super($element, $); this.dms = { @@ -19,9 +19,11 @@ class Controller extends Section { set route(value) { this._route = value; - - this.setDefaultParams(); - this.getAllowedContentTypes(); + const params = {filter: { + where: {code: 'invoiceIn'} + }}; + this.getDmsTypes(params).then(res => this.handleDefaultParams(res)); + this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); } $onChanges() { @@ -29,36 +31,23 @@ class Controller extends Section { this.params = JSON.parse(this.$params.q); } - getAllowedContentTypes() { - this.$http.get('DmsContainers/allowedContentTypes').then(res => { - const contentTypes = res.data.join(', '); - this.allowedContentTypes = contentTypes; - }); - } - get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } - setDefaultParams() { - const params = {filter: { - where: {code: 'invoiceIn'} - }}; - this.$http.get('DmsTypes/findOne', {params}).then(res => { - const dmsType = res.data && res.data; - const companyId = this.vnConfig.companyFk; - const warehouseId = this.vnConfig.warehouseFk; - const defaultParams = { - warehouseId: warehouseId, - companyId: companyId, - dmsTypeId: dmsType.id, - description: this.params.supplierName - }; + handleDefaultParams({data: dmsType}) { + const companyId = this.vnConfig.companyFk; + const warehouseId = this.vnConfig.warehouseFk; + const defaultParams = { + warehouseId: warehouseId, + companyId: companyId, + dmsTypeId: dmsType.id, + description: this.params.supplierName + }; - this.dms = Object.assign(this.dms, defaultParams); - }); + this.dms = Object.assign(this.dms, defaultParams); } onSubmit() { diff --git a/modules/ticket/front/dms/create/index.js b/modules/ticket/front/dms/create/index.js index b25abf17c..7b25e4665 100644 --- a/modules/ticket/front/dms/create/index.js +++ b/modules/ticket/front/dms/create/index.js @@ -1,7 +1,7 @@ import ngModule from '../../module'; -import Section from 'salix/components/section'; +import SectionDms from 'salix/components/section-dms'; -class Controller extends Section { +class Controller extends SectionDms { constructor($element, $) { super($element, $); this.dms = { @@ -19,45 +19,36 @@ class Controller extends Section { this._ticket = value; if (value) { - this.setDefaultParams(); - this.getAllowedContentTypes(); + const params = {filter: { + where: {code: 'ticket'} + }}; + this.getDmsTypes(params).then(res => this.handleDefaultParams(res)); + this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); } } - getAllowedContentTypes() { - this.$http.get('DmsContainers/allowedContentTypes').then(res => { - const contentTypes = res.data.join(', '); - this.allowedContentTypes = contentTypes; - }); - } - get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } - setDefaultParams() { - const params = {filter: { - where: {code: 'ticket'} - }}; - this.$http.get('DmsTypes/findOne', {params}).then(res => { - const dmsTypeId = res.data && res.data.id; - const warehouseId = this.vnConfig.warehouseFk; - const defaultParams = { - reference: this.ticket.id, - warehouseId: warehouseId, - companyId: this.ticket.companyFk, - dmsTypeId: dmsTypeId, - description: this.$t('FileDescription', { - ticketId: this.ticket.id, - clientId: this.ticket.client.id, - clientName: this.ticket.client.name - }).toUpperCase() - }; + handleDefaultParams(data) { + const dmsTypeId = res?.data?.id; + const warehouseId = this.vnConfig.warehouseFk; + const defaultParams = { + reference: this.ticket.id, + warehouseId: warehouseId, + companyId: this.ticket.companyFk, + dmsTypeId: dmsTypeId, + description: this.$t('FileDescription', { + ticketId: this.ticket.id, + clientId: this.ticket.client.id, + clientName: this.ticket.client.name + }).toUpperCase() + }; - this.dms = Object.assign(this.dms, defaultParams); - }); + this.dms = Object.assign(this.dms, defaultParams); } onSubmit() { diff --git a/modules/ticket/front/dms/edit/index.js b/modules/ticket/front/dms/edit/index.js index 808ca6a6a..9b64f5906 100644 --- a/modules/ticket/front/dms/edit/index.js +++ b/modules/ticket/front/dms/edit/index.js @@ -1,7 +1,7 @@ import ngModule from '../../module'; -import Section from 'salix/components/section'; +import SectionDms from 'salix/components/section-dms'; -class Controller extends Section { +class Controller extends SectionDms { get ticket() { return this._ticket; } @@ -10,39 +10,28 @@ class Controller extends Section { this._ticket = value; if (value) { - this.setDefaultParams(); - this.getAllowedContentTypes(); + this.getDms(this.$params.dmsId).then(handleDefaultParams); + this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); } } - getAllowedContentTypes() { - this.$http.get('DmsContainers/allowedContentTypes').then(res => { - const contentTypes = res.data.join(', '); - this.allowedContentTypes = contentTypes; - }); - } - get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } - setDefaultParams() { - const path = `Dms/${this.$params.dmsId}`; - this.$http.get(path).then(res => { - const dms = res.data && res.data; - this.dms = { - reference: dms.reference, - warehouseId: dms.warehouseFk, - companyId: dms.companyFk, - dmsTypeId: dms.dmsTypeFk, - description: dms.description, - hasFile: dms.hasFile, - hasFileAttached: false, - files: [] - }; - }); + handleDefaultParams({data: dms}) { + this.dms = { + reference: dms.reference, + warehouseId: dms.warehouseFk, + companyId: dms.companyFk, + dmsTypeId: dms.dmsTypeFk, + description: dms.description, + hasFile: dms.hasFile, + hasFileAttached: false, + files: [] + }; } onSubmit() { diff --git a/modules/travel/front/thermograph/create/index.js b/modules/travel/front/thermograph/create/index.js index fa2c1261a..e51d23124 100644 --- a/modules/travel/front/thermograph/create/index.js +++ b/modules/travel/front/thermograph/create/index.js @@ -17,16 +17,10 @@ class Controller extends Section { if (value) { this.setDefaultParams(); - this.getAllowedContentTypes(); + this.allowedContentTypes = this.getAllowedContentTypes(); } } - getAllowedContentTypes() { - this.$http.get('DmsContainers/allowedContentTypes').then(res => { - const contentTypes = res.data.join(', '); - this.allowedContentTypes = contentTypes; - }); - } get contentTypesInfo() { return this.$t('ContentTypesInfo', { diff --git a/modules/travel/front/thermograph/edit/index.js b/modules/travel/front/thermograph/edit/index.js index a8df3142d..1678643b2 100644 --- a/modules/travel/front/thermograph/edit/index.js +++ b/modules/travel/front/thermograph/edit/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import Section from 'salix/components/section'; +import SectionDms from 'salix/components/section-dms'; import './style.scss'; -class Controller extends Section { +class Controller extends SectionDms { get travel() { return this._travel; } @@ -12,17 +12,10 @@ class Controller extends Section { if (value) { this.setDefaultParams(); - this.getAllowedContentTypes(); + this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); } } - getAllowedContentTypes() { - this.$http.get('DmsContainers/allowedContentTypes').then(res => { - const contentTypes = res.data.join(', '); - this.allowedContentTypes = contentTypes; - }); - } - get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes diff --git a/modules/worker/front/dms/create/index.js b/modules/worker/front/dms/create/index.js index ff6112211..2f06128b5 100644 --- a/modules/worker/front/dms/create/index.js +++ b/modules/worker/front/dms/create/index.js @@ -21,17 +21,12 @@ class Controller extends Section { if (value) { this.setDefaultParams(); - this.getAllowedContentTypes(); + this.getAllowedContentTypes().then(data => { + this.allowedContentTypes = data; + }); } } - getAllowedContentTypes() { - this.$http.get('DmsContainers/allowedContentTypes').then(res => { - const contentTypes = res.data.join(', '); - this.allowedContentTypes = contentTypes; - }); - } - get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes diff --git a/modules/worker/front/dms/edit/index.js b/modules/worker/front/dms/edit/index.js index 31d4c2853..8a1790563 100644 --- a/modules/worker/front/dms/edit/index.js +++ b/modules/worker/front/dms/edit/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import Section from 'salix/components/section'; +import SectionDms from 'salix/components/section-dms'; import './style.scss'; -class Controller extends Section { +class Controller extends SectionDms { get worker() { return this._worker; } @@ -11,16 +11,10 @@ class Controller extends Section { this._worker = value; if (value) { - this.setDefaultParams(); - this.getAllowedContentTypes(); - } - } + this.getDms(this.$params.dmsId).then(handleDefaultParams); - getAllowedContentTypes() { - this.$http.get('DmsContainers/allowedContentTypes').then(res => { - const contentTypes = res.data.join(', '); - this.allowedContentTypes = contentTypes; - }); + this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); + } } get contentTypesInfo() { @@ -29,21 +23,17 @@ class Controller extends Section { }); } - setDefaultParams() { - const path = `Dms/${this.$params.dmsId}`; - this.$http.get(path).then(res => { - const dms = res.data && res.data; - this.dms = { - reference: dms.reference, - warehouseId: dms.warehouseFk, - companyId: dms.companyFk, - dmsTypeId: dms.dmsTypeFk, - description: dms.description, - hasFile: dms.hasFile, - hasFileAttached: false, - files: [] - }; - }); + handleDefaultParams({data: dms}) { + this.dms = { + reference: dms.reference, + warehouseId: dms.warehouseFk, + companyId: dms.companyFk, + dmsTypeId: dms.dmsTypeFk, + description: dms.description, + hasFile: dms.hasFile, + hasFileAttached: false, + files: [] + }; } onSubmit() { From a5ecec960351372d518a3d8f4fd5e8d7d3c6d2ce Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 13 Dec 2023 13:47:30 +0100 Subject: [PATCH 09/21] refs #2051 feat: remove front methods refactor --- front/salix/components/index.js | 1 - front/salix/components/section-dms/index.js | 24 --------- front/salix/components/section-dms/style.scss | 0 modules/client/front/dms/create/index.js | 54 +++++++++++-------- modules/client/front/dms/edit/index.js | 41 ++++++++------ modules/invoiceIn/front/basic-data/index.js | 15 ++++-- .../agency-term/createInvoiceIn/index.js | 45 ++++++++++------ modules/ticket/front/dms/create/index.js | 53 ++++++++++-------- modules/ticket/front/dms/edit/index.js | 41 ++++++++------ modules/ticket/front/tracking/index/index.js | 10 +--- .../travel/front/thermograph/create/index.js | 8 ++- .../travel/front/thermograph/edit/index.js | 13 +++-- modules/worker/front/dms/create/index.js | 11 ++-- 13 files changed, 182 insertions(+), 134 deletions(-) delete mode 100644 front/salix/components/section-dms/index.js delete mode 100644 front/salix/components/section-dms/style.scss diff --git a/front/salix/components/index.js b/front/salix/components/index.js index e843f2f5e..38b0d0e1f 100644 --- a/front/salix/components/index.js +++ b/front/salix/components/index.js @@ -15,7 +15,6 @@ import './module-card'; import './module-main'; import './side-menu/side-menu'; import './section'; -import './section-dms'; import './summary'; import './topbar/topbar'; import './user-popover'; diff --git a/front/salix/components/section-dms/index.js b/front/salix/components/section-dms/index.js deleted file mode 100644 index ae7d496cd..000000000 --- a/front/salix/components/section-dms/index.js +++ /dev/null @@ -1,24 +0,0 @@ -import ngModule from '../../module'; -import Component from 'core/lib/component'; -import './style.scss'; - -export default class SectionDms extends Component { - getAllowedContentTypes() { - return this.$http.get('DmsContainers/allowedContentTypes').then(res => { - const contentTypes = res.data.join(', '); - this.allowedContentTypes = contentTypes; - return contentTypes; - }); - } - - getDms(dmsId) { - return this.$http.get(`Dms/${dmsId}`).then(res => res); - } - getDmsTypes(params) { - return this.$http.get('DmsTypes/findOne', params).then(res => res); - } -} - -ngModule.vnComponent('vnSectionDms', { - controller: SectionDms -}); diff --git a/front/salix/components/section-dms/style.scss b/front/salix/components/section-dms/style.scss deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/client/front/dms/create/index.js b/modules/client/front/dms/create/index.js index ec8837981..461d0aa36 100644 --- a/modules/client/front/dms/create/index.js +++ b/modules/client/front/dms/create/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import SectionDms from 'salix/components/section-dms'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends SectionDms { +class Controller extends Section { constructor($element, $) { super($element, $); this.dms = { @@ -20,36 +20,46 @@ class Controller extends SectionDms { this._client = value; if (value) { - const params = {filter: { - where: {code: 'paymentsLaw'} - }}; - this.getDmsTypes(params).then(res => this.handleDefaultParams(res)); - this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); + this.setDefaultParams(); + this.getAllowedContentTypes(); } } + getAllowedContentTypes() { + this.$http.get('DmsContainers/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } - handleDefaultParams({data: dmsType}) { - const companyId = this.vnConfig.companyFk; - const warehouseId = this.vnConfig.warehouseFk; - const defaultParams = { - reference: this.client.id, - warehouseId: warehouseId, - companyId: companyId, - dmsTypeId: dmsType.id, - description: this.$t('ClientFileDescription', { - dmsTypeName: dmsType.name, - clientId: this.client.id, - clientName: this.client.name - }).toUpperCase() - }; + setDefaultParams() { + const params = {filter: { + where: {code: 'paymentsLaw'} + }}; + this.$http.get('DmsTypes/findOne', {params}).then(res => { + const dmsType = res.data && res.data; + const companyId = this.vnConfig.companyFk; + const warehouseId = this.vnConfig.warehouseFk; + const defaultParams = { + reference: this.client.id, + warehouseId: warehouseId, + companyId: companyId, + dmsTypeId: dmsType.id, + description: this.$t('ClientFileDescription', { + dmsTypeName: dmsType.name, + clientId: this.client.id, + clientName: this.client.name + }).toUpperCase() + }; - this.dms = Object.assign(this.dms, defaultParams); + this.dms = Object.assign(this.dms, defaultParams); + }); } onSubmit() { diff --git a/modules/client/front/dms/edit/index.js b/modules/client/front/dms/edit/index.js index 36c1a9672..8765eeff2 100644 --- a/modules/client/front/dms/edit/index.js +++ b/modules/client/front/dms/edit/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import SectionDms from 'salix/components/section-dms'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends SectionDms { +class Controller extends Section { get client() { return this._client; } @@ -11,28 +11,39 @@ class Controller extends SectionDms { this._client = value; if (value) { - this.getDms(this.$params.dmsId).then(handleDefaultParams); - this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); + this.setDefaultParams(); + this.getAllowedContentTypes(); } } + getAllowedContentTypes() { + this.$http.get('DmsContainers/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } - handleDefaultParams({data: dms}) { - this.dms = { - reference: dms.reference, - warehouseId: dms.warehouseFk, - companyId: dms.companyFk, - dmsTypeId: dms.dmsTypeFk, - description: dms.description, - hasFile: dms.hasFile, - hasFileAttached: false, - files: [] - }; + setDefaultParams() { + const path = `Dms/${this.$params.dmsId}`; + this.$http.get(path).then(res => { + const dms = res.data && res.data; + this.dms = { + reference: dms.reference, + warehouseId: dms.warehouseFk, + companyId: dms.companyFk, + dmsTypeId: dms.dmsTypeFk, + description: dms.description, + hasFile: dms.hasFile, + hasFileAttached: false, + files: [] + }; + }); } onSubmit() { diff --git a/modules/invoiceIn/front/basic-data/index.js b/modules/invoiceIn/front/basic-data/index.js index 797fda59d..246f1b16f 100644 --- a/modules/invoiceIn/front/basic-data/index.js +++ b/modules/invoiceIn/front/basic-data/index.js @@ -1,8 +1,8 @@ import ngModule from '../module'; -import SectionDms from 'salix/components/section-dms'; +import Section from 'salix/components/section'; import UserError from 'core/lib/user-error'; -class Controller extends SectionDms { +class Controller extends Section { constructor($element, $, vnFile) { super($element, $, vnFile); this.dms = { @@ -11,7 +11,7 @@ class Controller extends SectionDms { hasFileAttached: false }; this.vnFile = vnFile; - this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); + this.getAllowedContentTypes(); this._editDownloadDisabled = false; } @@ -53,6 +53,15 @@ class Controller extends SectionDms { }); } + getAllowedContentTypes() { + this.$http.get('DmsContainers/allowedContentTypes').then(res => { + if (res.data.length > 0) { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + } + }); + } + openEditDialog(dmsId) { this.getFile(dmsId).then(() => this.$.dmsEditDialog.show()); } diff --git a/modules/route/front/agency-term/createInvoiceIn/index.js b/modules/route/front/agency-term/createInvoiceIn/index.js index 5e54f7929..0198ab80f 100644 --- a/modules/route/front/agency-term/createInvoiceIn/index.js +++ b/modules/route/front/agency-term/createInvoiceIn/index.js @@ -1,9 +1,9 @@ import ngModule from '../../module'; -import SectionDms from 'salix/components/section-dms'; +import Section from 'salix/components/section'; import './style.scss'; import UserError from 'core/lib/user-error'; -class Controller extends SectionDms { +class Controller extends Section { constructor($element, $) { super($element, $); this.dms = { @@ -19,11 +19,9 @@ class Controller extends SectionDms { set route(value) { this._route = value; - const params = {filter: { - where: {code: 'invoiceIn'} - }}; - this.getDmsTypes(params).then(res => this.handleDefaultParams(res)); - this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); + + this.setDefaultParams(); + this.getAllowedContentTypes(); } $onChanges() { @@ -31,23 +29,36 @@ class Controller extends SectionDms { this.params = JSON.parse(this.$params.q); } + getAllowedContentTypes() { + this.$http.get('DmsContainers/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } - handleDefaultParams({data: dmsType}) { - const companyId = this.vnConfig.companyFk; - const warehouseId = this.vnConfig.warehouseFk; - const defaultParams = { - warehouseId: warehouseId, - companyId: companyId, - dmsTypeId: dmsType.id, - description: this.params.supplierName - }; + setDefaultParams() { + const params = {filter: { + where: {code: 'invoiceIn'} + }}; + this.$http.get('DmsTypes/findOne', {params}).then(res => { + const dmsType = res.data && res.data; + const companyId = this.vnConfig.companyFk; + const warehouseId = this.vnConfig.warehouseFk; + const defaultParams = { + warehouseId: warehouseId, + companyId: companyId, + dmsTypeId: dmsType.id, + description: this.params.supplierName + }; - this.dms = Object.assign(this.dms, defaultParams); + this.dms = Object.assign(this.dms, defaultParams); + }); } onSubmit() { diff --git a/modules/ticket/front/dms/create/index.js b/modules/ticket/front/dms/create/index.js index 7b25e4665..b25abf17c 100644 --- a/modules/ticket/front/dms/create/index.js +++ b/modules/ticket/front/dms/create/index.js @@ -1,7 +1,7 @@ import ngModule from '../../module'; -import SectionDms from 'salix/components/section-dms'; +import Section from 'salix/components/section'; -class Controller extends SectionDms { +class Controller extends Section { constructor($element, $) { super($element, $); this.dms = { @@ -19,36 +19,45 @@ class Controller extends SectionDms { this._ticket = value; if (value) { - const params = {filter: { - where: {code: 'ticket'} - }}; - this.getDmsTypes(params).then(res => this.handleDefaultParams(res)); - this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); + this.setDefaultParams(); + this.getAllowedContentTypes(); } } + getAllowedContentTypes() { + this.$http.get('DmsContainers/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } - handleDefaultParams(data) { - const dmsTypeId = res?.data?.id; - const warehouseId = this.vnConfig.warehouseFk; - const defaultParams = { - reference: this.ticket.id, - warehouseId: warehouseId, - companyId: this.ticket.companyFk, - dmsTypeId: dmsTypeId, - description: this.$t('FileDescription', { - ticketId: this.ticket.id, - clientId: this.ticket.client.id, - clientName: this.ticket.client.name - }).toUpperCase() - }; + setDefaultParams() { + const params = {filter: { + where: {code: 'ticket'} + }}; + this.$http.get('DmsTypes/findOne', {params}).then(res => { + const dmsTypeId = res.data && res.data.id; + const warehouseId = this.vnConfig.warehouseFk; + const defaultParams = { + reference: this.ticket.id, + warehouseId: warehouseId, + companyId: this.ticket.companyFk, + dmsTypeId: dmsTypeId, + description: this.$t('FileDescription', { + ticketId: this.ticket.id, + clientId: this.ticket.client.id, + clientName: this.ticket.client.name + }).toUpperCase() + }; - this.dms = Object.assign(this.dms, defaultParams); + this.dms = Object.assign(this.dms, defaultParams); + }); } onSubmit() { diff --git a/modules/ticket/front/dms/edit/index.js b/modules/ticket/front/dms/edit/index.js index 9b64f5906..808ca6a6a 100644 --- a/modules/ticket/front/dms/edit/index.js +++ b/modules/ticket/front/dms/edit/index.js @@ -1,7 +1,7 @@ import ngModule from '../../module'; -import SectionDms from 'salix/components/section-dms'; +import Section from 'salix/components/section'; -class Controller extends SectionDms { +class Controller extends Section { get ticket() { return this._ticket; } @@ -10,28 +10,39 @@ class Controller extends SectionDms { this._ticket = value; if (value) { - this.getDms(this.$params.dmsId).then(handleDefaultParams); - this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); + this.setDefaultParams(); + this.getAllowedContentTypes(); } } + getAllowedContentTypes() { + this.$http.get('DmsContainers/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } - handleDefaultParams({data: dms}) { - this.dms = { - reference: dms.reference, - warehouseId: dms.warehouseFk, - companyId: dms.companyFk, - dmsTypeId: dms.dmsTypeFk, - description: dms.description, - hasFile: dms.hasFile, - hasFileAttached: false, - files: [] - }; + setDefaultParams() { + const path = `Dms/${this.$params.dmsId}`; + this.$http.get(path).then(res => { + const dms = res.data && res.data; + this.dms = { + reference: dms.reference, + warehouseId: dms.warehouseFk, + companyId: dms.companyFk, + dmsTypeId: dms.dmsTypeFk, + description: dms.description, + hasFile: dms.hasFile, + hasFileAttached: false, + files: [] + }; + }); } onSubmit() { diff --git a/modules/ticket/front/tracking/index/index.js b/modules/ticket/front/tracking/index/index.js index 95665b071..ff3dc881b 100644 --- a/modules/ticket/front/tracking/index/index.js +++ b/modules/ticket/front/tracking/index/index.js @@ -7,15 +7,9 @@ class Controller extends Section { this.filter = { include: [ { - relation: 'worker', + relation: 'user', scope: { - fields: ['id'], - include: { - relation: 'user', - scope: { - fields: ['name'] - } - } + fields: ['name'] } }, { relation: 'state', diff --git a/modules/travel/front/thermograph/create/index.js b/modules/travel/front/thermograph/create/index.js index e51d23124..fa2c1261a 100644 --- a/modules/travel/front/thermograph/create/index.js +++ b/modules/travel/front/thermograph/create/index.js @@ -17,10 +17,16 @@ class Controller extends Section { if (value) { this.setDefaultParams(); - this.allowedContentTypes = this.getAllowedContentTypes(); + this.getAllowedContentTypes(); } } + getAllowedContentTypes() { + this.$http.get('DmsContainers/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } get contentTypesInfo() { return this.$t('ContentTypesInfo', { diff --git a/modules/travel/front/thermograph/edit/index.js b/modules/travel/front/thermograph/edit/index.js index 1678643b2..a8df3142d 100644 --- a/modules/travel/front/thermograph/edit/index.js +++ b/modules/travel/front/thermograph/edit/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import SectionDms from 'salix/components/section-dms'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends SectionDms { +class Controller extends Section { get travel() { return this._travel; } @@ -12,10 +12,17 @@ class Controller extends SectionDms { if (value) { this.setDefaultParams(); - this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); + this.getAllowedContentTypes(); } } + getAllowedContentTypes() { + this.$http.get('DmsContainers/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes diff --git a/modules/worker/front/dms/create/index.js b/modules/worker/front/dms/create/index.js index 2f06128b5..ff6112211 100644 --- a/modules/worker/front/dms/create/index.js +++ b/modules/worker/front/dms/create/index.js @@ -21,12 +21,17 @@ class Controller extends Section { if (value) { this.setDefaultParams(); - this.getAllowedContentTypes().then(data => { - this.allowedContentTypes = data; - }); + this.getAllowedContentTypes(); } } + getAllowedContentTypes() { + this.$http.get('DmsContainers/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes From bdf5dd6e3c4e334b44a65a254220cdf239eab0f6 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 13 Dec 2023 13:48:22 +0100 Subject: [PATCH 10/21] refs #2051 feat: restore dms methods --- back/methods/dms/removeFile.js | 15 +++++---------- back/methods/dms/uploadFile.js | 15 +-------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/back/methods/dms/removeFile.js b/back/methods/dms/removeFile.js index cb81ff322..a9ff36883 100644 --- a/back/methods/dms/removeFile.js +++ b/back/methods/dms/removeFile.js @@ -34,25 +34,20 @@ module.exports = Self => { } try { - let modelDms = null; - if (myOptions.model) { - modelDms = await models[myOptions.model].findById(id, null, myOptions); - id = modelDms.dmsFk; - } - const targetDms = await models.Dms.findById(id, null, myOptions); + const dms = await models.Dms.findById(id, null, myOptions); const trashDmsType = await models.DmsType.findOne({ where: {code: 'trash'} }, myOptions); - const hasWriteRole = await models.DmsType.hasWriteRole(ctx, targetDms.dmsTypeFk, myOptions); + const hasWriteRole = await models.DmsType.hasWriteRole(ctx, dms.dmsTypeFk, myOptions); if (!hasWriteRole) throw new UserError(`You don't have enough privileges`); - await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions); + await dms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions); if (tx) await tx.commit(); - if (modelDms) modelDms.destroy(myOptions); - return targetDms; + + return dms; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/back/methods/dms/uploadFile.js b/back/methods/dms/uploadFile.js index abed95a3a..a4212b804 100644 --- a/back/methods/dms/uploadFile.js +++ b/back/methods/dms/uploadFile.js @@ -96,21 +96,8 @@ module.exports = Self => { } if (tx) await tx.commit(); - const promises = []; - const {model, create} = myOptions; - addedDms.forEach(dms => { - const newDms = models[model].create({ - ...create, - dmsFk: dms.id - }, myOptions); - promises.push(newDms); - }); - const resolvedPromises = await Promise.all(promises); - - // if (tx) await tx.commit(); - - return resolvedPromises; + return addedDms; } catch (e) { if (tx) await tx.rollback(); From 7b9e3b0985f55a35e326a54680930ff4da410cba Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 13 Dec 2023 14:24:05 +0100 Subject: [PATCH 11/21] refs #2051 perf: removeFile after review --- back/methods/dms/removeFile.js | 2 +- .../back/methods/claim-dms/removeFile.js | 21 +++++++------- .../back/methods/client-dms/removeFile.js | 12 ++++---- .../back/methods/ticket-dms/removeFile.js | 15 +++++----- .../back/methods/worker-dms/removeFile.js | 29 ++++++++++--------- 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/back/methods/dms/removeFile.js b/back/methods/dms/removeFile.js index a9ff36883..dc55b4d38 100644 --- a/back/methods/dms/removeFile.js +++ b/back/methods/dms/removeFile.js @@ -22,8 +22,8 @@ module.exports = Self => { Self.removeFile = async(ctx, id, options) => { const models = Self.app.models; - let tx; const myOptions = {}; + let tx; if (typeof options == 'object') Object.assign(myOptions, options); diff --git a/modules/claim/back/methods/claim-dms/removeFile.js b/modules/claim/back/methods/claim-dms/removeFile.js index 257b09cf2..0f1da626c 100644 --- a/modules/claim/back/methods/claim-dms/removeFile.js +++ b/modules/claim/back/methods/claim-dms/removeFile.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { Self.remoteMethodCtx('removeFile', { description: 'Removes a claim document', @@ -19,8 +21,8 @@ module.exports = Self => { }); Self.removeFile = async(ctx, id, options) => { - let tx; const myOptions = {}; + let tx; if (typeof options == 'object') Object.assign(myOptions, options); @@ -31,19 +33,18 @@ module.exports = Self => { } try { - // const {models: ClaimDms, Dms} = Self.app.models; - // const targetClaimDms = await ClaimDms.findById(id, null, myOptions); - // await Dms.findById(targetClaimDms.dmsFk, null, myOptions); - // const trashDmsType = await DmsType.findOne({where: {code: 'trash'}}, myOptions); - myOptions.model = 'ClaimDms'; - const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions); - // await targetClaimDms.destroy(myOptions); + const claimDms = await Self.findById(id, null, myOptions); - // await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions); + const targetDms = await Self.app.models.Dms.removeFile(ctx, claimDms.dmsFk, myOptions); + + if (!targetDms || ! claimDms) + throw new UserError('Try again'); + + const claimDestroyed = await claimDms.destroy(myOptions); if (tx) await tx.commit(); - return targetDms; + return claimDestroyed; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/client/back/methods/client-dms/removeFile.js b/modules/client/back/methods/client-dms/removeFile.js index 786a32928..5bd34adcf 100644 --- a/modules/client/back/methods/client-dms/removeFile.js +++ b/modules/client/back/methods/client-dms/removeFile.js @@ -19,9 +19,8 @@ module.exports = Self => { }); Self.removeFile = async(ctx, id, options) => { - const models = Self.app.models; - let tx; const myOptions = {}; + let tx; if (typeof options == 'object') Object.assign(myOptions, options); @@ -34,13 +33,16 @@ module.exports = Self => { try { const clientDms = await Self.findById(id, null, myOptions); - await models.Dms.removeFile(ctx, clientDms.dmsFk, myOptions); + const targetDms = await Self.app.models.Dms.removeFile(ctx, clientDms.dmsFk, myOptions); - const destroyedClient = await clientDms.destroy(myOptions); + if (!targetDms || !clientDms) + throw new UserError('Try again'); + + const clientDestroyed = await clientDms.destroy(myOptions); if (tx) await tx.commit(); - return destroyedClient; + return clientDestroyed; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/ticket/back/methods/ticket-dms/removeFile.js b/modules/ticket/back/methods/ticket-dms/removeFile.js index 2e3ccd149..2f6426fbb 100644 --- a/modules/ticket/back/methods/ticket-dms/removeFile.js +++ b/modules/ticket/back/methods/ticket-dms/removeFile.js @@ -31,19 +31,18 @@ module.exports = Self => { } try { - // const targetTicketDms = await models.TicketDms.findById(id, null, myOptions); - myOptions.model = 'TicketDms'; - // await models.Dms.findById(targetTicketDms.dmsFk, null, myOptions); - // const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}}, myOptions); + const ticketDms = await Self.findById(id, null, myOptions); - const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions); - // await targetTicketDms.destroy(myOptions); + const targetDms = await Self.app.models.Dms.removeFile(ctx, ticketDms.dmsFk, myOptions); - // await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions); + if (!targetDms || !ticketDms) + throw new UserError('Try again'); + + const ticketDestroyed = await ticketDms.destroy(myOptions); if (tx) await tx.commit(); - return targetDms; + return ticketDestroyed; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/worker/back/methods/worker-dms/removeFile.js b/modules/worker/back/methods/worker-dms/removeFile.js index 397255bb2..6c7b6b850 100644 --- a/modules/worker/back/methods/worker-dms/removeFile.js +++ b/modules/worker/back/methods/worker-dms/removeFile.js @@ -19,25 +19,28 @@ module.exports = Self => { }); Self.removeFile = async(ctx, id, options) => { - const models = Self.app.models; + const myOptions = {}; let tx; + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + try { - const myOptions = {}; + const WorkerDms = await Self.findById(id, null, myOptions); - if (typeof options == 'object') - Object.assign(myOptions, options); + const targetDms = await Self.app.models.Dms.removeFile(ctx, WorkerDms.dmsFk, myOptions); - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - // const workerDms = await Self.findById(id); - myOptions.model = 'WorkerDms'; - await models.Dms.removeFile(ctx, id, myOptions); - // await workerDms.destroy(); + if (!targetDms || !WorkerDms) + throw new UserError('Try again'); + + const workerDestroyed = await WorkerDms.destroy(myOptions); if (tx) await tx.commit(); - return workerDms; + return workerDestroyed; } catch (e) { await tx.rollback(); throw e; From 40499e44cf8d38dbaadb8501c8829d23ec5f7008 Mon Sep 17 00:00:00 2001 From: carlossa Date: Wed, 13 Dec 2023 15:05:41 +0100 Subject: [PATCH 12/21] refs #6220 remove concat --- modules/client/back/methods/client/filter.js | 10 ++++++---- .../client/back/methods/client/specs/filter.spec.js | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index 43310c86b..e703ce53d 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -145,16 +145,18 @@ module.exports = Self => { c.name, c.fi, c.socialName, - CONCAT(c.phone, ',',GROUP_CONCAT(DISTINCT a.phone)) phone, + c.phone, + a.phone, c.mobile, - CONCAT(c.city, ',',GROUP_CONCAT(DISTINCT a.city)) city, + c.city, + a.city, c.postcode, a.postalCode, c.email, c.isActive, c.isFreezed, - p.id AS provinceFk2, - a.provinceFk, + p.id AS provinceClientFk, + a.provinceFk AS provinceAddressFk, p.name AS province, u.id AS salesPersonFk, u.name AS salesPerson diff --git a/modules/client/back/methods/client/specs/filter.spec.js b/modules/client/back/methods/client/specs/filter.spec.js index 4a61f8aaf..679585050 100644 --- a/modules/client/back/methods/client/specs/filter.spec.js +++ b/modules/client/back/methods/client/specs/filter.spec.js @@ -146,7 +146,7 @@ describe('client filter()', () => { const randomResultClient = result[randomIndex]; expect(result.length).toBeGreaterThanOrEqual(20); - expect(randomResultClient.city.toLowerCase()).toEqual('gotham,gotham'); + expect(randomResultClient.city.toLowerCase()).toEqual('gotham'); await tx.rollback(); } catch (e) { From 06bae4482495653d63c30762bc7dcc1a3b84b6cc Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 13 Dec 2023 15:38:46 +0100 Subject: [PATCH 13/21] refs #2051 perf: uploadFile after review --- .../claim/back/methods/claim/uploadFile.js | 56 +++---------------- .../client/back/methods/client/uploadFile.js | 23 +++----- .../ticket/back/methods/ticket/uploadFile.js | 22 +++----- .../back/methods/worker-dms/removeFile.js | 10 +++- .../worker/back/methods/worker/uploadFile.js | 19 ++----- modules/worker/front/dms/edit/index.js | 42 ++++++++------ 6 files changed, 64 insertions(+), 108 deletions(-) diff --git a/modules/claim/back/methods/claim/uploadFile.js b/modules/claim/back/methods/claim/uploadFile.js index 7e4798fef..4fd041456 100644 --- a/modules/claim/back/methods/claim/uploadFile.js +++ b/modules/claim/back/methods/claim/uploadFile.js @@ -54,7 +54,7 @@ module.exports = Self => { }); Self.uploadFile = async(ctx, id, options) => { - const models = Self.app.models; + const {Dms, ClaimDms} = Self.app.models; const myOptions = {}; let tx; @@ -66,56 +66,14 @@ module.exports = Self => { myOptions.transaction = tx; } - // const promises = []; - // const TempContainer = models.TempContainer; - // const ClaimContainer = models.ClaimContainer; - // const fileOptions = {}; - // const args = ctx.args; - - // let srcFile; try { - myOptions.model = 'ClaimDms'; - myOptions.create = {claimFk: id}; - const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions); + const uploadedFiles = await Dms.uploadFile(ctx, myOptions); - // const hasWriteRole = await models.DmsType.hasWriteRole(ctx, args.dmsTypeId, myOptions); - // if (!hasWriteRole) - // throw new UserError(`You don't have enough privileges`); - - // // Upload file to temporary path - // const tempContainer = await TempContainer.container('dms'); - // const uploaded = await TempContainer.upload(tempContainer.name, ctx.req, ctx.result, fileOptions); - // const files = Object.values(uploaded.files).map(file => { - // return file[0]; - // }); - - // const addedDms = []; - // for (const uploadedFile of files) { - // const newDms = await createDms(ctx, uploadedFile, myOptions); - // const pathHash = ClaimContainer.getHash(newDms.id); - - // const file = await TempContainer.getFile(tempContainer.name, uploadedFile.name); - // srcFile = path.join(file.client.root, file.container, file.name); - - // const claimContainer = await ClaimContainer.container(pathHash); - // const dstFile = path.join(claimContainer.client.root, pathHash, newDms.file); - - // await fs.move(srcFile, dstFile, { - // overwrite: true - // }); - - // addedDms.push(newDms); - // } - - // addedDms.forEach(dms => { - // const newClaimDms = models.ClaimDms.create({ - // claimFk: id, - // dmsFk: dms.id - // }, myOptions); - - // promises.push(newClaimDms); - // }); - // const resolvedPromises = await Promise.all(promises); + const promises = uploadedFiles.map(dms => ClaimDms.create({ + claimFk: id, + dmsFk: dms.id + }, myOptions)); + await Promise.all(promises); if (tx) await tx.commit(); diff --git a/modules/client/back/methods/client/uploadFile.js b/modules/client/back/methods/client/uploadFile.js index 8f471f1b6..1a5965955 100644 --- a/modules/client/back/methods/client/uploadFile.js +++ b/modules/client/back/methods/client/uploadFile.js @@ -55,7 +55,7 @@ module.exports = Self => { }); Self.uploadFile = async(ctx, id, options) => { - const models = Self.app.models; + const {Dms, ClientDms} = Self.app.models; const myOptions = {}; let tx; @@ -67,21 +67,16 @@ module.exports = Self => { myOptions.transaction = tx; } - // const promises = []; - try { - myOptions.model = 'ClientDms'; - myOptions.create = {clientFk: id}; - const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions); - // uploadedFiles.forEach(dms => { - // const newClientDms = models.ClientDms.create({ - // clientFk: id, - // dmsFk: dms.id - // }, myOptions); + const uploadedFiles = await Dms.uploadFile(ctx, myOptions); + const promises = uploadedFiles.map(dms => + ClientDms.create({ + clientFk: id, + dmsFk: dms.id + }, myOptions) - // promises.push(newClientDms); - // }); - // const resolvedPromises = await Promise.all(promises); + ); + await Promise.all(promises); if (tx) await tx.commit(); diff --git a/modules/ticket/back/methods/ticket/uploadFile.js b/modules/ticket/back/methods/ticket/uploadFile.js index 63bbe845a..eb563783c 100644 --- a/modules/ticket/back/methods/ticket/uploadFile.js +++ b/modules/ticket/back/methods/ticket/uploadFile.js @@ -47,7 +47,7 @@ module.exports = Self => { }); Self.uploadFile = async(ctx, id, options) => { - const models = Self.app.models; + const {Dms, TicketDms} = Self.app.models; const myOptions = {}; let tx; @@ -59,21 +59,15 @@ module.exports = Self => { myOptions.transaction = tx; } - // const promises = []; try { - myOptions.model = 'TicketDms'; - myOptions.create = {ticketFk: id}; - const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions); - /* uploadedFiles.forEach(dms => { - const newTicketDms = models.TicketDms.create({ - ticketFk: id, - dmsFk: dms.id - }, myOptions); + const uploadedFiles = await Dms.uploadFile(ctx, myOptions); + const promises = uploadedFiles.map(dms => TicketDms.create({ + ticketFk: id, + dmsFk: dms.id + }, myOptions)); + + await Promise.all(promises); - promises.push(newTicketDms); - }); - const resolvedPromises = await Promise.all(promises); -*/ if (tx) await tx.commit(); return uploadedFiles; diff --git a/modules/worker/back/methods/worker-dms/removeFile.js b/modules/worker/back/methods/worker-dms/removeFile.js index 6c7b6b850..9fddc8b4b 100644 --- a/modules/worker/back/methods/worker-dms/removeFile.js +++ b/modules/worker/back/methods/worker-dms/removeFile.js @@ -30,9 +30,15 @@ module.exports = Self => { } try { - const WorkerDms = await Self.findById(id, null, myOptions); + // const dms = await Self.app.models.Dms.findById(id, null, myOptions); + const WorkerDms = await Self.findOne({ + where: {document: id} + }, myOptions); - const targetDms = await Self.app.models.Dms.removeFile(ctx, WorkerDms.dmsFk, myOptions); + // const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions); + // const WorkerDms = await Self.findById(+targetDms.reference, null, myOptions); + + const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions); if (!targetDms || !WorkerDms) throw new UserError('Try again'); diff --git a/modules/worker/back/methods/worker/uploadFile.js b/modules/worker/back/methods/worker/uploadFile.js index e624dc904..c3526cbb1 100644 --- a/modules/worker/back/methods/worker/uploadFile.js +++ b/modules/worker/back/methods/worker/uploadFile.js @@ -47,10 +47,9 @@ module.exports = Self => { }); Self.uploadFile = async(ctx, id) => { - const models = Self.app.models; + const {Dms, WorkerDms} = Self.app.models; const myOptions = {}; let tx; - // const promises = []; if (typeof options == 'object') Object.assign(myOptions, options); @@ -61,20 +60,14 @@ module.exports = Self => { } try { - myOptions.model = 'WorkerDms'; - myOptions.create = {workerFk: id}; - - const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions); - /* uploadedFiles.forEach(dms => { - const newWorkerDms = models.WorkerDms.create({ + const uploadedFiles = await Dms.uploadFile(ctx, myOptions); + const promises = uploadedFiles.map(dms => + WorkerDms.create({ workerFk: id, dmsFk: dms.id - }, options); + }, myOptions)); + await Promise.all(promises); - promises.push(newWorkerDms); - }); - const resolvedPromises = await Promise.all(promises); -*/ if (tx) await tx.commit(); return uploadedFiles; diff --git a/modules/worker/front/dms/edit/index.js b/modules/worker/front/dms/edit/index.js index 8a1790563..31d4c2853 100644 --- a/modules/worker/front/dms/edit/index.js +++ b/modules/worker/front/dms/edit/index.js @@ -1,8 +1,8 @@ import ngModule from '../../module'; -import SectionDms from 'salix/components/section-dms'; +import Section from 'salix/components/section'; import './style.scss'; -class Controller extends SectionDms { +class Controller extends Section { get worker() { return this._worker; } @@ -11,29 +11,39 @@ class Controller extends SectionDms { this._worker = value; if (value) { - this.getDms(this.$params.dmsId).then(handleDefaultParams); - - this.getAllowedContentTypes().then(data => this.allowedContentTypes = data); + this.setDefaultParams(); + this.getAllowedContentTypes(); } } + getAllowedContentTypes() { + this.$http.get('DmsContainers/allowedContentTypes').then(res => { + const contentTypes = res.data.join(', '); + this.allowedContentTypes = contentTypes; + }); + } + get contentTypesInfo() { return this.$t('ContentTypesInfo', { allowedContentTypes: this.allowedContentTypes }); } - handleDefaultParams({data: dms}) { - this.dms = { - reference: dms.reference, - warehouseId: dms.warehouseFk, - companyId: dms.companyFk, - dmsTypeId: dms.dmsTypeFk, - description: dms.description, - hasFile: dms.hasFile, - hasFileAttached: false, - files: [] - }; + setDefaultParams() { + const path = `Dms/${this.$params.dmsId}`; + this.$http.get(path).then(res => { + const dms = res.data && res.data; + this.dms = { + reference: dms.reference, + warehouseId: dms.warehouseFk, + companyId: dms.companyFk, + dmsTypeId: dms.dmsTypeFk, + description: dms.description, + hasFile: dms.hasFile, + hasFileAttached: false, + files: [] + }; + }); } onSubmit() { From d0af29c0c57d9c19270ddbd502170201219ef1d8 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 14 Dec 2023 12:28:41 +0100 Subject: [PATCH 14/21] refs #6264 test: remove force describe for dms test --- back/methods/dms/specs/removeFile.spec.js | 2 +- modules/claim/back/methods/claim-dms/specs/removeFile.spec.js | 2 +- modules/client/back/methods/client-dms/specs/removeFile.spec.js | 2 +- modules/ticket/back/methods/ticket-dms/specs/removeFile.spec.js | 2 +- modules/ticket/back/methods/ticket/specs/uploadFile.spec.js | 2 +- modules/worker/back/methods/worker-dms/specs/removeFile.spec.js | 2 +- modules/worker/back/methods/worker/specs/uploadFile.spec.js | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/back/methods/dms/specs/removeFile.spec.js b/back/methods/dms/specs/removeFile.spec.js index e0d1dc1e7..59a2acecb 100644 --- a/back/methods/dms/specs/removeFile.spec.js +++ b/back/methods/dms/specs/removeFile.spec.js @@ -1,6 +1,6 @@ const {models} = require('vn-loopback/server/server'); -fdescribe('dms removeFile()', () => { +describe('dms removeFile()', () => { let dmsId = 1; it(`should return an error for a user without enough privileges`, async() => { diff --git a/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js b/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js index 210d805e7..108427b4c 100644 --- a/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js +++ b/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); // f -fdescribe('TicketDms removeFile()', () => { +describe('TicketDms removeFile()', () => { const ticketDmsId = 1; it(`should return an error for a user without enough privileges`, async() => { let clientId = 1101; diff --git a/modules/client/back/methods/client-dms/specs/removeFile.spec.js b/modules/client/back/methods/client-dms/specs/removeFile.spec.js index 61a00a610..95c7d2ac4 100644 --- a/modules/client/back/methods/client-dms/specs/removeFile.spec.js +++ b/modules/client/back/methods/client-dms/specs/removeFile.spec.js @@ -1,7 +1,7 @@ const models = require('vn-loopback/server/server').models; // f -fdescribe('ClientDms removeFile()', () => { +describe('ClientDms removeFile()', () => { it(`should return an error for a user without enough privileges`, async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket-dms/specs/removeFile.spec.js b/modules/ticket/back/methods/ticket-dms/specs/removeFile.spec.js index ca4cb5bc3..9296984c3 100644 --- a/modules/ticket/back/methods/ticket-dms/specs/removeFile.spec.js +++ b/modules/ticket/back/methods/ticket-dms/specs/removeFile.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('TicketDms removeFile()', () => { +describe('TicketDms removeFile()', () => { const ticketDmsId = 1; it(`should return an error for a user without enough privileges`, async() => { const tx = await models.TicketDms.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js b/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js index 8c01133e6..70d532076 100644 --- a/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js +++ b/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; // f -fdescribe('Ticket uploadFile()', () => { +describe('Ticket uploadFile()', () => { it(`should return an error for a user without enough privileges`, async() => { const tx = await models.Ticket.beginTransaction({}); diff --git a/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js b/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js index e66628656..82c6c3edd 100644 --- a/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js +++ b/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js @@ -1,7 +1,7 @@ const app = require('vn-loopback/server/server'); // f -fdescribe('WorkerDms removeFile()', () => { +describe('WorkerDms removeFile()', () => { const workerDmsFk = 1; it(`should return an error for a user without enough privileges`, async() => { let clientId = 1101; diff --git a/modules/worker/back/methods/worker/specs/uploadFile.spec.js b/modules/worker/back/methods/worker/specs/uploadFile.spec.js index 34426c6a0..71145ef5f 100644 --- a/modules/worker/back/methods/worker/specs/uploadFile.spec.js +++ b/modules/worker/back/methods/worker/specs/uploadFile.spec.js @@ -1,6 +1,6 @@ const app = require('vn-loopback/server/server'); // f -fdescribe('Worker uploadFile()', () => { +describe('Worker uploadFile()', () => { it(`should return an error for a user without enough privileges`, async() => { let workerId = 1106; let currentUserId = 1102; From 1939c65fabcdf68ffb351ba5b51bbb3763d8b7e2 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 14 Dec 2023 12:35:54 +0100 Subject: [PATCH 15/21] refs #6264 test: remove force describe for dms test --- .../claim-dms/specs/removeFile.spec.js | 1 - .../client-dms/specs/removeFile.spec.js | 1 - .../methods/ticket/specs/uploadFile.spec.js | 25 +------------------ .../ticket/back/methods/ticket/uploadFile.js | 1 + .../back/methods/worker-dms/removeFile.js | 4 --- .../worker-dms/specs/removeFile.spec.js | 1 - .../methods/worker/specs/uploadFile.spec.js | 2 +- 7 files changed, 3 insertions(+), 32 deletions(-) diff --git a/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js b/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js index 108427b4c..1cd3b16cb 100644 --- a/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js +++ b/modules/claim/back/methods/claim-dms/specs/removeFile.spec.js @@ -1,6 +1,5 @@ const app = require('vn-loopback/server/server'); -// f describe('TicketDms removeFile()', () => { const ticketDmsId = 1; it(`should return an error for a user without enough privileges`, async() => { diff --git a/modules/client/back/methods/client-dms/specs/removeFile.spec.js b/modules/client/back/methods/client-dms/specs/removeFile.spec.js index 95c7d2ac4..6dac71293 100644 --- a/modules/client/back/methods/client-dms/specs/removeFile.spec.js +++ b/modules/client/back/methods/client-dms/specs/removeFile.spec.js @@ -1,6 +1,5 @@ const models = require('vn-loopback/server/server').models; -// f describe('ClientDms removeFile()', () => { it(`should return an error for a user without enough privileges`, async() => { const tx = await models.Client.beginTransaction({}); diff --git a/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js b/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js index 70d532076..133c13265 100644 --- a/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js +++ b/modules/ticket/back/methods/ticket/specs/uploadFile.spec.js @@ -1,5 +1,5 @@ const models = require('vn-loopback/server/server').models; -// f + describe('Ticket uploadFile()', () => { it(`should return an error for a user without enough privileges`, async() => { const tx = await models.Ticket.beginTransaction({}); @@ -23,27 +23,4 @@ describe('Ticket uploadFile()', () => { expect(error.message).toEqual(`You don't have enough privileges`); }); - - // fit(`should uploadFile`, async() => { - // const tx = await models.Ticket.beginTransaction({}); - - // let error; - // try { - // const options = {transaction: tx}; - - // const ticketId = 15; - // const currentUserId = 9; - // const ticketTypeId = 14; - // const ctx = {req: {accessToken: {userId: currentUserId}}, args: {dmsTypeId: ticketTypeId}, result: new ArrayBuffer(20000)}; - - // await models.Ticket.uploadFile(ctx, ticketId, options); - - // await tx.rollback(); - // } catch (e) { - // await tx.rollback(); - // error = e; - // } - - // expect(error.message).toEqual(`You don't have enough privileges`); - // }); }); diff --git a/modules/ticket/back/methods/ticket/uploadFile.js b/modules/ticket/back/methods/ticket/uploadFile.js index eb563783c..5b79aa973 100644 --- a/modules/ticket/back/methods/ticket/uploadFile.js +++ b/modules/ticket/back/methods/ticket/uploadFile.js @@ -61,6 +61,7 @@ module.exports = Self => { try { const uploadedFiles = await Dms.uploadFile(ctx, myOptions); + const promises = uploadedFiles.map(dms => TicketDms.create({ ticketFk: id, dmsFk: dms.id diff --git a/modules/worker/back/methods/worker-dms/removeFile.js b/modules/worker/back/methods/worker-dms/removeFile.js index 9fddc8b4b..343d6d50b 100644 --- a/modules/worker/back/methods/worker-dms/removeFile.js +++ b/modules/worker/back/methods/worker-dms/removeFile.js @@ -30,14 +30,10 @@ module.exports = Self => { } try { - // const dms = await Self.app.models.Dms.findById(id, null, myOptions); const WorkerDms = await Self.findOne({ where: {document: id} }, myOptions); - // const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions); - // const WorkerDms = await Self.findById(+targetDms.reference, null, myOptions); - const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions); if (!targetDms || !WorkerDms) diff --git a/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js b/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js index 82c6c3edd..3efd09464 100644 --- a/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js +++ b/modules/worker/back/methods/worker-dms/specs/removeFile.spec.js @@ -1,6 +1,5 @@ const app = require('vn-loopback/server/server'); -// f describe('WorkerDms removeFile()', () => { const workerDmsFk = 1; it(`should return an error for a user without enough privileges`, async() => { diff --git a/modules/worker/back/methods/worker/specs/uploadFile.spec.js b/modules/worker/back/methods/worker/specs/uploadFile.spec.js index 71145ef5f..7a929cd2b 100644 --- a/modules/worker/back/methods/worker/specs/uploadFile.spec.js +++ b/modules/worker/back/methods/worker/specs/uploadFile.spec.js @@ -1,5 +1,5 @@ const app = require('vn-loopback/server/server'); -// f + describe('Worker uploadFile()', () => { it(`should return an error for a user without enough privileges`, async() => { let workerId = 1106; From 9316c31180da1f26ae30b0642980a8249936a0cc Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Thu, 14 Dec 2023 12:36:36 +0100 Subject: [PATCH 16/21] refs #6264 perf: rename variable when destroy ids --- modules/claim/back/methods/claim-dms/removeFile.js | 4 ++-- modules/client/back/methods/client-dms/removeFile.js | 4 ++-- modules/ticket/back/methods/ticket-dms/removeFile.js | 4 ++-- modules/worker/back/methods/worker-dms/removeFile.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/claim/back/methods/claim-dms/removeFile.js b/modules/claim/back/methods/claim-dms/removeFile.js index 0f1da626c..28e78c9d7 100644 --- a/modules/claim/back/methods/claim-dms/removeFile.js +++ b/modules/claim/back/methods/claim-dms/removeFile.js @@ -40,11 +40,11 @@ module.exports = Self => { if (!targetDms || ! claimDms) throw new UserError('Try again'); - const claimDestroyed = await claimDms.destroy(myOptions); + const claimDmsDestroyed = await claimDms.destroy(myOptions); if (tx) await tx.commit(); - return claimDestroyed; + return claimDmsDestroyed; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/client/back/methods/client-dms/removeFile.js b/modules/client/back/methods/client-dms/removeFile.js index 5bd34adcf..bc9a0f719 100644 --- a/modules/client/back/methods/client-dms/removeFile.js +++ b/modules/client/back/methods/client-dms/removeFile.js @@ -38,11 +38,11 @@ module.exports = Self => { if (!targetDms || !clientDms) throw new UserError('Try again'); - const clientDestroyed = await clientDms.destroy(myOptions); + const clientDmsDestroyed = await clientDms.destroy(myOptions); if (tx) await tx.commit(); - return clientDestroyed; + return clientDmsDestroyed; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/ticket/back/methods/ticket-dms/removeFile.js b/modules/ticket/back/methods/ticket-dms/removeFile.js index 2f6426fbb..6fba4c552 100644 --- a/modules/ticket/back/methods/ticket-dms/removeFile.js +++ b/modules/ticket/back/methods/ticket-dms/removeFile.js @@ -38,11 +38,11 @@ module.exports = Self => { if (!targetDms || !ticketDms) throw new UserError('Try again'); - const ticketDestroyed = await ticketDms.destroy(myOptions); + const ticketDmsDestroyed = await ticketDms.destroy(myOptions); if (tx) await tx.commit(); - return ticketDestroyed; + return ticketDmsDestroyed; } catch (e) { if (tx) await tx.rollback(); throw e; diff --git a/modules/worker/back/methods/worker-dms/removeFile.js b/modules/worker/back/methods/worker-dms/removeFile.js index 343d6d50b..a5a3b6bb8 100644 --- a/modules/worker/back/methods/worker-dms/removeFile.js +++ b/modules/worker/back/methods/worker-dms/removeFile.js @@ -39,10 +39,10 @@ module.exports = Self => { if (!targetDms || !WorkerDms) throw new UserError('Try again'); - const workerDestroyed = await WorkerDms.destroy(myOptions); + const workerDmsDestroyed = await WorkerDms.destroy(myOptions); if (tx) await tx.commit(); - return workerDestroyed; + return workerDmsDestroyed; } catch (e) { await tx.rollback(); throw e; From bbb9f58a9edaa16b442cedbf7bb3226a18651b1d Mon Sep 17 00:00:00 2001 From: carlossa Date: Thu, 14 Dec 2023 14:37:14 +0100 Subject: [PATCH 17/21] refs #6220 fix(client_filter): fix where --- modules/client/back/methods/client/filter.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/client/back/methods/client/filter.js b/modules/client/back/methods/client/filter.js index e703ce53d..f805c4be9 100644 --- a/modules/client/back/methods/client/filter.js +++ b/modules/client/back/methods/client/filter.js @@ -113,18 +113,18 @@ module.exports = Self => { return {'a.postalCode': {inq: postalCode}}; case 'city': return {or: [ - {'c.city': {like: `%${value}`}}, - {'a.city': {like: `%${value}`}} + {'c.city': {like: `%${value}%`}}, + {'a.city': {like: `%${value}%`}} ]}; case 'postcode': return {or: [ - {'c.postcode': {like: `%${value}`}}, - {'a.postalCode': {like: `%${value}`}} + {'c.postcode': value}, + {'a.postalCode': value} ]}; case 'provinceFk': return {or: [ - {'p.name': {like: `%${value}`}}, - {'a.provinceFk': {like: `%${value}`}} + {'p.id': value}, + {'a.provinceFk': value} ]}; case 'name': case 'salesPersonFk': From dc98436b85cc52dfd09bb5b2138c442ae60b411d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 15 Dec 2023 13:01:44 +0100 Subject: [PATCH 18/21] refs #2051 perf: rename variable --- modules/worker/back/methods/worker-dms/removeFile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker-dms/removeFile.js b/modules/worker/back/methods/worker-dms/removeFile.js index a5a3b6bb8..8eb6c05fd 100644 --- a/modules/worker/back/methods/worker-dms/removeFile.js +++ b/modules/worker/back/methods/worker-dms/removeFile.js @@ -18,7 +18,7 @@ module.exports = Self => { } }); - Self.removeFile = async(ctx, id, options) => { + Self.removeFile = async(ctx, dmsFk, options) => { const myOptions = {}; let tx; if (typeof options == 'object') @@ -31,10 +31,10 @@ module.exports = Self => { try { const WorkerDms = await Self.findOne({ - where: {document: id} + where: {document: dmsFk} }, myOptions); - const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions); + const targetDms = await Self.app.models.Dms.removeFile(ctx, dmsFk, myOptions); if (!targetDms || !WorkerDms) throw new UserError('Try again'); From d60f2a7f88f44906f300e9c5c060ed4b5ec82f1e Mon Sep 17 00:00:00 2001 From: davidd Date: Tue, 19 Dec 2023 09:43:09 +0100 Subject: [PATCH 19/21] fix: refs #6398 Changed alias of views --- db/changes/235201/02-views.sql | 4 ++-- modules/ticket/back/methods/ticket/state.js | 4 ++-- modules/ticket/back/models/ticket-state.json | 8 ++++---- modules/ticket/back/models/ticket-tracking.json | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/db/changes/235201/02-views.sql b/db/changes/235201/02-views.sql index a0f41594d..af190f596 100644 --- a/db/changes/235201/02-views.sql +++ b/db/changes/235201/02-views.sql @@ -3,7 +3,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` VIEW `vn`.`ticketState` AS SELECT `tt`.`created` AS `updated`, `tt`.`stateFk` AS `stateFk`, - `tt`.`userFk` AS `userFk`, + `tt`.`userFk` AS `workerFk`, `tls`.`ticketFk` AS `ticketFk`, `s`.`id` AS `state`, `s`.`order` AS `productionOrder`, @@ -40,7 +40,7 @@ SELECT `ts`.`state` AS `state`, `ts`.`productionOrder` AS `productionOrder`, `ts`.`alertLevel` AS `alertLevel`, - `ts`.`userFk` AS `userFk`, + `ts`.`userFk` AS `worker`, `ts`.`code` AS `code`, `ts`.`updated` AS `updated`, `ts`.`isPicked` AS `isPicked` diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index adac2e42f..01bfbba20 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -51,12 +51,12 @@ module.exports = Self => { params.stateFk = state.id; } - if (!params.userFk) { + if (!params.workerFk) { const worker = await models.Worker.findOne({ where: {id: userId} }, myOptions); - params.userFk = worker.id; + params.workerFk = worker.id; } const ticketState = await models.TicketState.findById(params.ticketFk, { diff --git a/modules/ticket/back/models/ticket-state.json b/modules/ticket/back/models/ticket-state.json index 3ee50fac0..3dd322939 100644 --- a/modules/ticket/back/models/ticket-state.json +++ b/modules/ticket/back/models/ticket-state.json @@ -34,9 +34,9 @@ "foreignKey": "stateFk" }, "user": { - "type": "belongsTo", - "model": "VnUser", - "foreignKey": "userFk" - } + "type": "belongsTo", + "model": "VnUser", + "foreignKey": "workerFk" + } } } diff --git a/modules/ticket/back/models/ticket-tracking.json b/modules/ticket/back/models/ticket-tracking.json index 8b0617145..4b5a4d473 100644 --- a/modules/ticket/back/models/ticket-tracking.json +++ b/modules/ticket/back/models/ticket-tracking.json @@ -37,9 +37,9 @@ "foreignKey": "stateFk" }, "user": { - "type": "belongsTo", - "model": "VnUser", - "foreignKey": "userFk" - } + "type": "belongsTo", + "model": "VnUser", + "foreignKey": "userFk" + } } } From 17e177b7888adf882683876d75f20d6d79b64799 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 19 Dec 2023 10:12:03 +0100 Subject: [PATCH 20/21] fix: refs #6398 Fix tests back --- modules/ticket/back/methods/ticket/state.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket/state.js b/modules/ticket/back/methods/ticket/state.js index 01bfbba20..adac2e42f 100644 --- a/modules/ticket/back/methods/ticket/state.js +++ b/modules/ticket/back/methods/ticket/state.js @@ -51,12 +51,12 @@ module.exports = Self => { params.stateFk = state.id; } - if (!params.workerFk) { + if (!params.userFk) { const worker = await models.Worker.findOne({ where: {id: userId} }, myOptions); - params.workerFk = worker.id; + params.userFk = worker.id; } const ticketState = await models.TicketState.findById(params.ticketFk, { From 5936a129dad5caa678e5d276b1cec7ac22beccfa Mon Sep 17 00:00:00 2001 From: davidd Date: Tue, 19 Dec 2023 12:58:20 +0100 Subject: [PATCH 21/21] refs #6398 --- db/changes/235201/02-views.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/changes/235201/02-views.sql b/db/changes/235201/02-views.sql index af190f596..1d031c38d 100644 --- a/db/changes/235201/02-views.sql +++ b/db/changes/235201/02-views.sql @@ -40,7 +40,7 @@ SELECT `ts`.`state` AS `state`, `ts`.`productionOrder` AS `productionOrder`, `ts`.`alertLevel` AS `alertLevel`, - `ts`.`userFk` AS `worker`, + `ts`.`worker` AS `worker`, `ts`.`code` AS `code`, `ts`.`updated` AS `updated`, `ts`.`isPicked` AS `isPicked`