From 913421633267930233cd3614736c78084ad4c00b Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 8 Apr 2024 14:46:35 +0200 Subject: [PATCH 1/2] refactor(workerDms): adapat to lilium --- back/methods/url/getUrl.js | 4 +- db/dump/fixtures.before.sql | 3 +- .../worker/back/methods/worker-dms/filter.js | 67 ++++++++++++------- modules/worker/front/dms/index/index.html | 27 ++++---- modules/worker/front/dms/index/index.js | 39 +++++++++++ 5 files changed, 100 insertions(+), 40 deletions(-) diff --git a/back/methods/url/getUrl.js b/back/methods/url/getUrl.js index ef741e5a0..fa3f7fdad 100644 --- a/back/methods/url/getUrl.js +++ b/back/methods/url/getUrl.js @@ -19,12 +19,12 @@ module.exports = Self => { } }); Self.getUrl = async(appName = 'salix') => { - const {url} = await Self.app.models.Url.findOne({ + const url = await Self.app.models.Url.findOne({ where: { appName, environment: process.env.NODE_ENV || 'development' } }); - return url; + return url?.url; }; }; diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 4ed91e1c0..32791f1b7 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2913,7 +2913,8 @@ INSERT INTO `salix`.`url` (`appName`, `environment`, `url`) VALUES ('lilium', 'development', 'http://localhost:9000/#/'), ('hedera', 'development', 'http://localhost:9090/'), - ('salix', 'development', 'http://localhost:5000/#!/'); + ('salix', 'development', 'http://localhost:5000/#!/'), + ('docuware', 'development', 'http://docuware'); INSERT INTO `vn`.`report` (`id`, `name`, `paperSizeFk`, `method`) VALUES diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index 9d8554484..69e470a21 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -1,4 +1,5 @@ const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const {mergeFilters, mergeWhere} = require('vn-loopback/util/filter'); module.exports = Self => { Self.remoteMethodCtx('filter', { @@ -33,28 +34,31 @@ module.exports = Self => { const userId = ctx.req.accessToken.userId; const models = Self.app.models; + // Get ids alloweds const account = await models.VnUser.findById(userId); const stmt = new ParameterizedSQL( - `SELECT d.id dmsFk, d.reference, d.description, d.file, d.created, d.hardCopyNumber, d.hasFile + `SELECT d.id, d.id dmsFk FROM workerDocument wd JOIN dms d ON d.id = wd.document JOIN dmsType dt ON dt.id = d.dmsTypeFk LEFT JOIN account.roleRole rr ON rr.inheritsFrom = dt.readRoleFk AND rr.role = ? `, [account.roleFk] ); - const oldWhere = filter.where; const yourOwnDms = {and: [{isReadableByWorker: true}, {worker: userId}]}; + const where = { + or: [yourOwnDms, { + role: { + neq: null + } + }] + }; + stmt.merge(conn.makeSuffix(mergeWhere(filter.where, where))); - filter.where = { - and: [{ - or: [yourOwnDms, { - role: { - neq: null - } - }] - }, oldWhere]}; - stmt.merge(conn.makeSuffix(filter)); - const workerDms = await conn.executeStmt(stmt); + // Get workerDms alloweds + const dmsIds = await conn.executeStmt(stmt); + const allowedIds = dmsIds.map(dms => dms.id); + const allowedFilter = mergeFilters(filter, {where: {dmsFk: {inq: allowedIds}, workerFk: id}}); + let workerDms = await models.WorkerDms.find(allowedFilter); // Get docuware info const docuware = await models.Docuware.findOne({ @@ -63,28 +67,43 @@ module.exports = Self => { }); const docuwareDmsType = docuware.dmsTypeFk; let workerDocuware = []; - if (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType))) { - const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']}); + if (!filter.skip && (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType)))) { + const worker = await models.Worker.findById(36471, {fields: ['fi', 'firstName', 'lastName']}); const docuwareParse = { 'Filename': 'dmsFk', 'Tipo Documento': 'description', 'Stored on': 'created', - 'Document ID': 'id' + 'Document ID': 'id', + 'URL': 'download', + 'Stored by': 'name', + 'Estado': 'state' }; workerDocuware = - await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? []; + await models.Docuware.getById('hr', worker.lastName + ' ' + worker.firstName, docuwareParse) ?? []; + const url = (await Self.app.models.Url.getUrl('docuware')) + 'WebClient'; for (document of workerDocuware) { + const docuwareId = document.id; const defaultData = { - file: 'dw' + document.id + '.png', - isDocuware: true, - hardCopyNumber: null, - hasFile: false, - reference: worker.fi, - dmsFk: 'DW' + document.id + id: docuwareId, + workerFk: id, + dmsFk: docuwareId, + dms: { + id: docuwareId, + file: docuwareId + '.pdf', + isDocuware: true, + hasFile: false, + reference: worker.fi, + dmsFk: docuwareId, + url, + description: document.description + ' - ' + document.state, + download: document.download, + created: document.created, + dmsType: {name: 'Docuware'}, + worker: {id: null, user: {name: document.name}}, + } }; - - document = Object.assign(document, defaultData); + Object.assign(document, defaultData); } } return workerDms.concat(workerDocuware); diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index aefbbcf34..e4cec8002 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -2,6 +2,7 @@ vn-id="model" url="WorkerDms/{{$ctrl.$params.id}}/filter" link="{worker: $ctrl.$params.id}" + filter="$ctrl.filter" limit="20" data="$ctrl.workerDms" order="dmsFk DESC" @@ -28,37 +29,37 @@ - {{::document.dmsFk}} + {{::document.id}} - - {{::document.hardCopyNumber}} + {{::document.dms.hardCopyNumber}} - - {{::document.reference}} + + {{::document.dms.reference}} - - {{::document.description}} + + {{::document.dms.description}} - {{::document.file}} + ng-click="$ctrl.downloadFile(document.dmsFk, document.dms.isDocuware)"> + {{::document.dms.file}} - {{::document.created | date:'dd/MM/yyyy HH:mm'}} + {{::document.dms.created | date:'dd/MM/yyyy HH:mm'}} - + @@ -78,7 +79,7 @@ tabindex="-1"> - + Date: Tue, 9 Apr 2024 07:51:57 +0200 Subject: [PATCH 2/2] fix id --- modules/worker/back/methods/worker-dms/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index 69e470a21..b7802a689 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -68,7 +68,7 @@ module.exports = Self => { const docuwareDmsType = docuware.dmsTypeFk; let workerDocuware = []; if (!filter.skip && (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType)))) { - const worker = await models.Worker.findById(36471, {fields: ['fi', 'firstName', 'lastName']}); + const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']}); const docuwareParse = { 'Filename': 'dmsFk', 'Tipo Documento': 'description', -- 2.40.1