From ae767762451137bb58fcaee927f8b401cfe18284 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 12 Dec 2023 12:09:06 +0100 Subject: [PATCH 01/13] 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 6b70f8b3eb0c5d5111adf0df1f2af77dc1083382 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 12 Dec 2023 13:49:14 +0100 Subject: [PATCH 02/13] 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 03/13] 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 04/13] 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 05/13] 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 06/13] 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 07/13] 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 06bae4482495653d63c30762bc7dcc1a3b84b6cc Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 13 Dec 2023 15:38:46 +0100 Subject: [PATCH 08/13] 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 09/13] 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 10/13] 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 11/13] 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 e89ec55839e065aaabb34d4df3a4472cb20c452d Mon Sep 17 00:00:00 2001 From: guillermo Date: Thu, 14 Dec 2023 15:09:07 +0100 Subject: [PATCH 12/13] fix: refs #6172 --- e2e/paths/08-route/03_create_and_clone.spec.js | 2 +- front/core/services/locale/en.yml | 2 +- front/core/services/locale/es.yml | 2 +- front/salix/module.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/e2e/paths/08-route/03_create_and_clone.spec.js b/e2e/paths/08-route/03_create_and_clone.spec.js index 0b8da98b4..31c0cfc18 100644 --- a/e2e/paths/08-route/03_create_and_clone.spec.js +++ b/e2e/paths/08-route/03_create_and_clone.spec.js @@ -26,7 +26,7 @@ describe('Route create path', () => { await page.waitToClick(selectors.createRouteView.submitButton); const message = await page.waitForSnackbar(); - expect(message.text).toContain('Access denied'); + expect(message.text).toContain('Access Denied'); }); }); diff --git a/front/core/services/locale/en.yml b/front/core/services/locale/en.yml index 2be73e696..8eb8a6f0d 100644 --- a/front/core/services/locale/en.yml +++ b/front/core/services/locale/en.yml @@ -3,4 +3,4 @@ Could not contact the server: Could not contact the server, make sure you have a Please enter your username: Please enter your username It seems that the server has fall down: It seems that the server has fall down, wait a few minutes and try again Session has expired: Your session has expired, please login again -Access denied: Access denied \ No newline at end of file +Access Denied: Access Denied \ No newline at end of file diff --git a/front/core/services/locale/es.yml b/front/core/services/locale/es.yml index e9811e38f..2c43ca3b2 100644 --- a/front/core/services/locale/es.yml +++ b/front/core/services/locale/es.yml @@ -3,5 +3,5 @@ Could not contact the server: No se ha podido contactar con el servidor, asegura Please enter your username: Por favor introduce tu nombre de usuario It seems that the server has fall down: Parece que el servidor se ha caído, espera unos minutos e inténtalo de nuevo Session has expired: Tu sesión ha expirado, por favor vuelve a iniciar sesión -Access denied: Acción no permitida +Access Denied: Acción no permitida Direction not found: Dirección no encontrada diff --git a/front/salix/module.js b/front/salix/module.js index 62d6cac98..0ce855308 100644 --- a/front/salix/module.js +++ b/front/salix/module.js @@ -120,7 +120,7 @@ function $exceptionHandler(vnApp, $window, $state, $injector) { messageT = 'Invalid login'; break; case 403: - messageT = exception.data?.error?.message || 'Access denied'; + messageT = exception.data?.error?.message || 'Access Denied'; break; case 502: messageT = 'It seems that the server has fall down'; From dc98436b85cc52dfd09bb5b2138c442ae60b411d Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 15 Dec 2023 13:01:44 +0100 Subject: [PATCH 13/13] 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');