From b60cd2539a205433a24e41d38ae19d0ca81922e3 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 29 May 2023 15:21:37 +0200 Subject: [PATCH 01/10] refs #5712 feat(workerDms): docuware integration --- back/methods/docuware/checkFile.js | 50 ++++---- back/methods/docuware/core.js | 113 ++++++++++++++---- back/methods/docuware/download.js | 4 +- db/changes/232401/00-workerDocuware.sql | 3 + .../back/methods/worker-dms/docuware.js | 46 +++++++ .../worker/back/methods/worker-dms/filter.js | 39 +++++- modules/worker/back/models/worker-dms.js | 1 + modules/worker/front/dms/index/index.html | 12 +- modules/worker/front/dms/index/index.js | 3 +- 9 files changed, 219 insertions(+), 52 deletions(-) create mode 100644 db/changes/232401/00-workerDocuware.sql create mode 100644 modules/worker/back/methods/worker-dms/docuware.js diff --git a/back/methods/docuware/checkFile.js b/back/methods/docuware/checkFile.js index c0a4e8ef3..447efa760 100644 --- a/back/methods/docuware/checkFile.js +++ b/back/methods/docuware/checkFile.js @@ -1,7 +1,7 @@ const axios = require('axios'); module.exports = Self => { - Self.remoteMethodCtx('checkFile', { + Self.remoteMethod('checkFile', { description: 'Check if exist docuware file', accessType: 'READ', accepts: [ @@ -20,8 +20,14 @@ module.exports = Self => { { arg: 'signed', type: 'boolean', - required: true, + required: false, description: 'If pdf is necessary to be signed' + }, + { + arg: 'filter', + type: 'object', + required: false, + description: 'The filter' } ], returns: { @@ -34,7 +40,7 @@ module.exports = Self => { } }); - Self.checkFile = async function(ctx, id, fileCabinet, signed) { + Self.checkFile = async function(id, fileCabinet, signed, filter) { const models = Self.app.models; const action = 'find'; @@ -44,35 +50,39 @@ module.exports = Self => { action: action } }); - - const searchFilter = { - condition: [ - { - DBName: docuwareInfo.findById, - - Value: [id] - } - ], - sortOrder: [ - { - Field: 'FILENAME', - Direction: 'Desc' - } - ] - }; + console.log(id, fileCabinet, signed, filter); + if (!filter) { + filter = { + condition: [ + { + DBName: docuwareInfo.findById, + Value: [id] + } + ], + sortOrder: [ + { + Field: 'FILENAME', + Direction: 'Desc' + } + ] + }; + } try { const options = await Self.getOptions(); const fileCabinetId = await Self.getFileCabinet(fileCabinet); const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId); + console.log('FILTER', filter); const response = await axios.post( `${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, - searchFilter, + filter, options.headers ); const [documents] = response.data.Items; + console.log(response); + console.log(response.data); if (!documents) return false; const state = documents.Fields.find(field => field.FieldName == 'ESTADO'); diff --git a/back/methods/docuware/core.js b/back/methods/docuware/core.js index 2053ddf85..ac04c1958 100644 --- a/back/methods/docuware/core.js +++ b/back/methods/docuware/core.js @@ -1,6 +1,28 @@ const axios = require('axios'); module.exports = Self => { + /** + * Returns basic headers + * + * @param {string} cookie - The docuware cookie + * @return {object} - The headers + */ + Self.getOptions = async() => { + const docuwareConfig = await Self.app.models.DocuwareConfig.findOne(); + const headers = { + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json', + 'Cookie': docuwareConfig.cookie + } + }; + + return { + url: docuwareConfig.url, + headers + }; + }; + /** * Returns the dialog id * @@ -20,9 +42,6 @@ module.exports = Self => { const options = await Self.getOptions(); - if (!process.env.NODE_ENV) - return Math.round(); - const response = await axios.get(`${options.url}/FileCabinets/${fileCabinetId}/dialogs`, options.headers); const dialogs = response.data.Dialog; const dialogId = dialogs.find(dialogs => dialogs.DisplayName === docuwareInfo.dialogName).Id; @@ -44,9 +63,6 @@ module.exports = Self => { } }); - if (!process.env.NODE_ENV) - return Math.round(); - const fileCabinetResponse = await axios.get(`${options.url}/FileCabinets`, options.headers); const fileCabinets = fileCabinetResponse.data.FileCabinet; const fileCabinetId = fileCabinets.find(fileCabinet => fileCabinet.Name === docuwareInfo.fileCabinetName).Id; @@ -55,24 +71,81 @@ module.exports = Self => { }; /** - * Returns basic headers + * Returns docuware data * - * @param {string} cookie - The docuware cookie - * @return {object} - The headers + * @param {string} code - The fileCabinet code + * @param {object} filter - The filter for docuware + * @param {object} parse - The fields parsed + * @return {object} - The data */ - Self.getOptions = async() => { - const docuwareConfig = await Self.app.models.DocuwareConfig.findOne(); - const headers = { - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - 'Cookie': docuwareConfig.cookie + Self.get = async(code, filter, parse) => { + const options = await Self.getOptions(); + const fileCabinetId = await Self.getFileCabinet(code); + const dialogId = await Self.getDialog(code, 'find', fileCabinetId); + + const {data} = await axios.post( + `${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, + filter, + options.headers + ); + + return parser(data, parse); + }; + + /** + * Returns docuware data + * + * @param {string} code - The fileCabinet code + * @param {any} id - The id of docuware + * @param {object} parse - The fields parsed + * @return {object} - The data + */ + Self.getById = async(code, id, parse) => { + const docuwareInfo = await Self.app.models.Docuware.findOne({ + fields: ['findById'], + where: { + code: code, + action: 'find' } + }); + const filter = { + condition: [ + { + DBName: docuwareInfo.findById, + Value: [id] + } + ] }; - return { - url: docuwareConfig.url, - headers - }; + return Self.get(code, filter, parse); }; + + /** + * Returns docuware data filtered + * + * @param {array} data - The data + * @param {object} parse - The fields parsed + * @return {object} - The data parsed + */ + function parser(data, parse) { + if (!(data && data.Items)) return data; + + const parsed = []; + for (item of data.Items) { + const itemParsed = {}; + item.Fields.map(field => { + if (field.ItemElementName.includes('Date')) field.Item = toDate(field.Item); + if (!parse) return itemParsed[field.FieldLabel] = field.Item; + if (parse[field.FieldLabel]) + itemParsed[parse[field.FieldLabel]] = field.Item; + }); + parsed.push(itemParsed); + } + return parsed; + } + + function toDate(value) { + if (!value) return; + return new Date(Number(value.substring(6, 19))); + } }; diff --git a/back/methods/docuware/download.js b/back/methods/docuware/download.js index 56d006ee7..b9c646adb 100644 --- a/back/methods/docuware/download.js +++ b/back/methods/docuware/download.js @@ -41,8 +41,10 @@ module.exports = Self => { } }); - Self.download = async function(ctx, id, fileCabinet) { + Self.download = async function(ctx, id, fileCabinet, filter) { const models = Self.app.models; + + // REVIEW const docuwareFile = await models.Docuware.checkFile(ctx, id, fileCabinet, true); if (!docuwareFile) throw new UserError('The DOCUWARE PDF document does not exists'); diff --git a/db/changes/232401/00-workerDocuware.sql b/db/changes/232401/00-workerDocuware.sql new file mode 100644 index 000000000..45d64bd78 --- /dev/null +++ b/db/changes/232401/00-workerDocuware.sql @@ -0,0 +1,3 @@ +INSERT INTO `vn`.`docuware` +(code, fileCabinetName, `action`, dialogName, findById) +VALUES('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO'); diff --git a/modules/worker/back/methods/worker-dms/docuware.js b/modules/worker/back/methods/worker-dms/docuware.js new file mode 100644 index 000000000..ff5902e8f --- /dev/null +++ b/modules/worker/back/methods/worker-dms/docuware.js @@ -0,0 +1,46 @@ +module.exports = Self => { + Self.remoteMethodCtx('docuwareDownload', { + description: 'Download a worker document', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'Number', + description: 'The document id', + http: {source: 'path'} + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: `/:id/docuwareDownload`, + verb: 'GET' + } + }); + + Self.docuwareDownload = async function(ctx, id) { + // CHECK ROLE? + const filter = { + condition: [ + { + DBName: 'FILENAME', + Value: [id] + } + ] + }; + return await Self.app.models.Docuware.download(ctx, id, 'hr', false, filter); + }; +}; diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index c16b2bbb1..7de838311 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -5,6 +5,12 @@ module.exports = Self => { description: 'Find all instances of the model matched by filter from the data source.', accessType: 'READ', accepts: [ + { + arg: 'id', + type: 'Number', + description: 'The worker id', + http: {source: 'path'} + }, { arg: 'filter', type: 'Object', @@ -17,16 +23,17 @@ module.exports = Self => { root: true }, http: { - path: `/filter`, + path: `/:id/filter`, verb: 'GET' } }); - Self.filter = async(ctx, filter) => { + Self.filter = async(ctx, id, filter) => { const conn = Self.dataSource.connector; const userId = ctx.req.accessToken.userId; + const models = Self.app.models; - const account = await Self.app.models.VnUser.findById(userId); + 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 FROM workerDocument wd @@ -47,7 +54,31 @@ module.exports = Self => { }] }, oldWhere]}; stmt.merge(conn.makeSuffix(filter)); + const workerDms = await conn.executeStmt(stmt); - return await conn.executeStmt(stmt); + // Get docuware info + const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']}); + const docuwareParse = { + 'Document ID': 'dmsFk', + 'Tipo Documento': 'description', + 'Stored on': 'created', + }; + const workerDocuware = await models.Docuware.getById('hr', 'BONO MOLA XAVIER', docuwareParse);// worker.lastName + worker.firstName); + + for (document of workerDocuware) { + const defaultData = { + file: document.dmsFk + '.png', + isDocuware: true, + hardCopyNumber: null, + hasFile: false, + reference: worker.fi + }; + + document = Object.assign(document, defaultData); + } + console.log(workerDocuware); + console.log(workerDms); + + return workerDms.concat(workerDocuware); }; }; diff --git a/modules/worker/back/models/worker-dms.js b/modules/worker/back/models/worker-dms.js index b9d6f9a77..1712383b3 100644 --- a/modules/worker/back/models/worker-dms.js +++ b/modules/worker/back/models/worker-dms.js @@ -2,6 +2,7 @@ module.exports = Self => { require('../methods/worker-dms/downloadFile')(Self); require('../methods/worker-dms/removeFile')(Self); require('../methods/worker-dms/filter')(Self); + require('../methods/worker-dms/docuware')(Self); Self.isMine = async function(ctx, dmsId) { const myUserId = ctx.req.accessToken.userId; diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index 1404336a2..6ed3a6f15 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -1,6 +1,6 @@ - + ng-click="$ctrl.downloadFile(document.dmsFk, document.isDocuware)"> {{::document.file}} @@ -63,7 +63,7 @@ + ng-click="$ctrl.downloadFile(document.dmsFk, document.isDocuware)"> @@ -91,9 +91,9 @@ fixed-bottom-right> - - \ No newline at end of file + diff --git a/modules/worker/front/dms/index/index.js b/modules/worker/front/dms/index/index.js index 9bb3c896a..ae2d51a17 100644 --- a/modules/worker/front/dms/index/index.js +++ b/modules/worker/front/dms/index/index.js @@ -17,7 +17,8 @@ class Controller extends Component { }); } - downloadFile(dmsId) { + downloadFile(dmsId, isDocuware) { + if (isDocuware) return this.vnFile.download(`api/workerDms/${dmsId}/docuwareDownload`); this.vnFile.download(`api/workerDms/${dmsId}/downloadFile`); } } From c23d8282ebf9433d69e75ad45c12323128349f9f Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 30 May 2023 15:34:11 +0200 Subject: [PATCH 02/10] refs #5712 feat(workerDms): docuware download --- back/methods/docuware/checkFile.js | 31 +++++------ back/methods/docuware/core.js | 6 +- back/methods/docuware/download.js | 17 +++--- back/methods/docuware/upload.js | 5 -- db/changes/232401/00-workerDocuware.sql | 6 +- .../back/methods/ticket/docuwareDownload.js | 55 +++++++++++++++++++ .../ticket/front/descriptor-menu/index.html | 7 +-- modules/ticket/front/descriptor-menu/index.js | 4 ++ .../back/methods/worker-dms/docuware.js | 3 +- .../worker/back/methods/worker-dms/filter.js | 3 +- modules/worker/front/dms/index/index.html | 20 +++++-- 11 files changed, 111 insertions(+), 46 deletions(-) create mode 100644 modules/ticket/back/methods/ticket/docuwareDownload.js diff --git a/back/methods/docuware/checkFile.js b/back/methods/docuware/checkFile.js index 447efa760..803755d09 100644 --- a/back/methods/docuware/checkFile.js +++ b/back/methods/docuware/checkFile.js @@ -17,18 +17,16 @@ module.exports = Self => { required: true, description: 'The fileCabinet name' }, - { - arg: 'signed', - type: 'boolean', - required: false, - description: 'If pdf is necessary to be signed' - }, { arg: 'filter', type: 'object', - required: false, description: 'The filter' - } + }, + { + arg: 'signed', + type: 'boolean', + description: 'If pdf is necessary to be signed' + }, ], returns: { type: 'object', @@ -40,7 +38,7 @@ module.exports = Self => { } }); - Self.checkFile = async function(id, fileCabinet, signed, filter) { + Self.checkFile = async function(id, fileCabinet, filter, signed) { const models = Self.app.models; const action = 'find'; @@ -50,7 +48,8 @@ module.exports = Self => { action: action } }); - console.log(id, fileCabinet, signed, filter); + console.log('ENTRY'); + console.log(filter, signed); if (!filter) { filter = { condition: [ @@ -67,13 +66,18 @@ module.exports = Self => { ] }; } + if (signed) { + filter.condition.push({ + DBName: 'ESTADO', + Value: ['Firmado'] + }); + } try { const options = await Self.getOptions(); const fileCabinetId = await Self.getFileCabinet(fileCabinet); const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId); - console.log('FILTER', filter); const response = await axios.post( `${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, @@ -81,13 +85,8 @@ module.exports = Self => { options.headers ); const [documents] = response.data.Items; - console.log(response); - console.log(response.data); if (!documents) return false; - const state = documents.Fields.find(field => field.FieldName == 'ESTADO'); - if (signed && state.Item != 'Firmado') return false; - return {id: documents.Id}; } catch (error) { return false; diff --git a/back/methods/docuware/core.js b/back/methods/docuware/core.js index ac04c1958..f13b69b13 100644 --- a/back/methods/docuware/core.js +++ b/back/methods/docuware/core.js @@ -83,13 +83,13 @@ module.exports = Self => { const fileCabinetId = await Self.getFileCabinet(code); const dialogId = await Self.getDialog(code, 'find', fileCabinetId); - const {data} = await axios.post( + const data = await axios.post( `${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, filter, options.headers ); - - return parser(data, parse); + console.log(data.data); + return parser(data.data, parse); }; /** diff --git a/back/methods/docuware/download.js b/back/methods/docuware/download.js index b9c646adb..a0d72ce01 100644 --- a/back/methods/docuware/download.js +++ b/back/methods/docuware/download.js @@ -3,7 +3,7 @@ const axios = require('axios'); const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { - Self.remoteMethodCtx('download', { + Self.remoteMethod('download', { description: 'Download an docuware PDF', accessType: 'READ', accepts: [ @@ -16,8 +16,12 @@ module.exports = Self => { { arg: 'fileCabinet', type: 'string', - description: 'The file cabinet', - http: {source: 'path'} + description: 'The file cabinet' + }, + { + arg: 'filter', + type: 'object', + description: 'The filter' } ], returns: [ @@ -36,16 +40,15 @@ module.exports = Self => { } ], http: { - path: `/:id/download/:fileCabinet`, + path: `/:id/download`, verb: 'GET' } }); - Self.download = async function(ctx, id, fileCabinet, filter) { + Self.download = async function(id, fileCabinet, filter) { const models = Self.app.models; - // REVIEW - const docuwareFile = await models.Docuware.checkFile(ctx, id, fileCabinet, true); + const docuwareFile = await models.Docuware.checkFile(id, fileCabinet, filter); if (!docuwareFile) throw new UserError('The DOCUWARE PDF document does not exists'); const fileCabinetId = await Self.getFileCabinet(fileCabinet); diff --git a/back/methods/docuware/upload.js b/back/methods/docuware/upload.js index ea9ee3622..9dd1f2103 100644 --- a/back/methods/docuware/upload.js +++ b/back/methods/docuware/upload.js @@ -16,11 +16,6 @@ module.exports = Self => { arg: 'fileCabinet', type: 'string', description: 'The file cabinet' - }, - { - arg: 'dialog', - type: 'string', - description: 'The dialog' } ], returns: [], diff --git a/db/changes/232401/00-workerDocuware.sql b/db/changes/232401/00-workerDocuware.sql index 45d64bd78..fbacb23f9 100644 --- a/db/changes/232401/00-workerDocuware.sql +++ b/db/changes/232401/00-workerDocuware.sql @@ -1,3 +1,3 @@ -INSERT INTO `vn`.`docuware` -(code, fileCabinetName, `action`, dialogName, findById) -VALUES('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO'); +INSERT INTO `vn`.`docuware` (code, fileCabinetName, `action`, dialogName, findById) + VALUES + ('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO'); diff --git a/modules/ticket/back/methods/ticket/docuwareDownload.js b/modules/ticket/back/methods/ticket/docuwareDownload.js new file mode 100644 index 000000000..bc74e0d21 --- /dev/null +++ b/modules/ticket/back/methods/ticket/docuwareDownload.js @@ -0,0 +1,55 @@ +module.exports = Self => { + Self.remoteMethodCtx('docuwareDownload', { + description: 'Download a ticket delivery note document', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'Number', + description: 'The document id', + http: {source: 'path'} + } + ], + returns: [ + { + arg: 'body', + type: 'file', + root: true + }, { + arg: 'Content-Type', + type: 'String', + http: {target: 'header'} + }, { + arg: 'Content-Disposition', + type: 'String', + http: {target: 'header'} + } + ], + http: { + path: `/:id/docuwareDownload`, + verb: 'GET' + } + }); + + Self.docuwareDownload = async function(ctx, id) { + const filter = { + condition: [ + { + DBName: docuwareInfo.findById, + Value: [id] + }, + { + DBName: 'ESTADO', + Value: ['Firmado'] + } + ], + sortOrder: [ + { + Field: 'FILENAME', + Direction: 'Desc' + } + ] + }; + return await Self.app.models.Docuware.download(id, 'deliveryNote', filter); + }; +}; diff --git a/modules/ticket/front/descriptor-menu/index.html b/modules/ticket/front/descriptor-menu/index.html index c2ebc3e3a..b645005be 100644 --- a/modules/ticket/front/descriptor-menu/index.html +++ b/modules/ticket/front/descriptor-menu/index.html @@ -36,13 +36,12 @@ translate> as PDF without prices - as PDF signed - + diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 987d6a3f1..bcb08c565 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -336,6 +336,10 @@ class Controller extends Section { this.vnApp.showSuccess(this.$t('PDF sent!')); }); } + + docuwareDownload() { + this.vnFile.download(`api/Ticket/${this.ticket.id}/docuwareDownload`); + } } Controller.$inject = ['$element', '$scope', 'vnReport', 'vnEmail']; diff --git a/modules/worker/back/methods/worker-dms/docuware.js b/modules/worker/back/methods/worker-dms/docuware.js index ff5902e8f..764b7633c 100644 --- a/modules/worker/back/methods/worker-dms/docuware.js +++ b/modules/worker/back/methods/worker-dms/docuware.js @@ -32,7 +32,6 @@ module.exports = Self => { }); Self.docuwareDownload = async function(ctx, id) { - // CHECK ROLE? const filter = { condition: [ { @@ -41,6 +40,6 @@ module.exports = Self => { } ] }; - return await Self.app.models.Docuware.download(ctx, id, 'hr', false, filter); + return await Self.app.models.Docuware.download(id, 'hr', filter); }; }; diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index 7de838311..eaefe67d3 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -59,12 +59,11 @@ module.exports = Self => { // Get docuware info const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']}); const docuwareParse = { - 'Document ID': 'dmsFk', + 'Filename': 'dmsFk', 'Tipo Documento': 'description', 'Stored on': 'created', }; const workerDocuware = await models.Docuware.getById('hr', 'BONO MOLA XAVIER', docuwareParse);// worker.lastName + worker.firstName); - for (document of workerDocuware) { const defaultData = { file: document.dmsFk + '.png', diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index 6ed3a6f15..9d2d5b25d 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -60,19 +60,31 @@ {{::document.created | date:'dd/MM/yyyy HH:mm'}} - + - - + + - + + + + + Date: Wed, 31 May 2023 11:32:37 +0200 Subject: [PATCH 03/10] refs #5712 openDocuware --- back/methods/docuware/checkFile.js | 3 +-- back/methods/docuware/core.js | 1 - db/changes/232401/00-workerDocuware.sql | 4 ++++ front/core/services/app.js | 6 +++++- front/core/services/locale/es.yml | 3 ++- .../worker/back/methods/worker-dms/filter.js | 4 +--- modules/worker/front/dms/index/index.html | 20 +++++++------------ modules/worker/front/dms/index/index.js | 5 +++++ 8 files changed, 25 insertions(+), 21 deletions(-) diff --git a/back/methods/docuware/checkFile.js b/back/methods/docuware/checkFile.js index 803755d09..18d169085 100644 --- a/back/methods/docuware/checkFile.js +++ b/back/methods/docuware/checkFile.js @@ -48,8 +48,7 @@ module.exports = Self => { action: action } }); - console.log('ENTRY'); - console.log(filter, signed); + if (!filter) { filter = { condition: [ diff --git a/back/methods/docuware/core.js b/back/methods/docuware/core.js index f13b69b13..7bb3e617a 100644 --- a/back/methods/docuware/core.js +++ b/back/methods/docuware/core.js @@ -88,7 +88,6 @@ module.exports = Self => { filter, options.headers ); - console.log(data.data); return parser(data.data, parse); }; diff --git a/db/changes/232401/00-workerDocuware.sql b/db/changes/232401/00-workerDocuware.sql index fbacb23f9..c8d4e4f23 100644 --- a/db/changes/232401/00-workerDocuware.sql +++ b/db/changes/232401/00-workerDocuware.sql @@ -1,3 +1,7 @@ INSERT INTO `vn`.`docuware` (code, fileCabinetName, `action`, dialogName, findById) VALUES ('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO'); + +INSERT INTO `salix`.`url` (appName, environment, url) + VALUES + ('docuware', 'production', 'https://verdnatura.docuware.cloud/DocuWare/Platform/'); diff --git a/front/core/services/app.js b/front/core/services/app.js index fb0a08777..6c80fafcc 100644 --- a/front/core/services/app.js +++ b/front/core/services/app.js @@ -66,7 +66,11 @@ export default class App { return this.logger.$http.get('Urls/findOne', {filter}) .then(res => { - return res.data.url + route; + if (res && res.data) + return res.data.url + route; + }) + .catch(() => { + this.showError('Direction not found'); }); } } diff --git a/front/core/services/locale/es.yml b/front/core/services/locale/es.yml index cf8801b52..e9811e38f 100644 --- a/front/core/services/locale/es.yml +++ b/front/core/services/locale/es.yml @@ -3,4 +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 \ No newline at end of file +Access denied: Acción no permitida +Direction not found: Dirección no encontrada diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index eaefe67d3..0b89cc883 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -63,7 +63,7 @@ module.exports = Self => { 'Tipo Documento': 'description', 'Stored on': 'created', }; - const workerDocuware = await models.Docuware.getById('hr', 'BONO MOLA XAVIER', docuwareParse);// worker.lastName + worker.firstName); + const workerDocuware = await models.Docuware.getById('hr', worker.lastName + worker.firstName, docuwareParse); for (document of workerDocuware) { const defaultData = { file: document.dmsFk + '.png', @@ -75,8 +75,6 @@ module.exports = Self => { document = Object.assign(document, defaultData); } - console.log(workerDocuware); - console.log(workerDms); return workerDms.concat(workerDocuware); }; diff --git a/modules/worker/front/dms/index/index.html b/modules/worker/front/dms/index/index.html index 9d2d5b25d..aefbbcf34 100644 --- a/modules/worker/front/dms/index/index.html +++ b/modules/worker/front/dms/index/index.html @@ -60,11 +60,13 @@ {{::document.created | date:'dd/MM/yyyy HH:mm'}} - + + + @@ -76,19 +78,11 @@ tabindex="-1"> - - - - - + diff --git a/modules/worker/front/dms/index/index.js b/modules/worker/front/dms/index/index.js index ae2d51a17..489fe1732 100644 --- a/modules/worker/front/dms/index/index.js +++ b/modules/worker/front/dms/index/index.js @@ -21,6 +21,11 @@ class Controller extends Component { if (isDocuware) return this.vnFile.download(`api/workerDms/${dmsId}/docuwareDownload`); this.vnFile.download(`api/workerDms/${dmsId}/downloadFile`); } + + async openDocuware() { + const url = await this.vnApp.getUrl(`WebClient`, 'docuware'); + if (url) window.open(url).focus(); + } } Controller.$inject = ['$element', '$scope', 'vnFile']; From 4f616397a2d1c513f5e051872fb7468de28e5978 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 3 Jul 2023 15:05:39 +0200 Subject: [PATCH 04/10] refs #5712 use dmsType readRole --- db/changes/232401/00-workerDocuware.sql | 7 ---- db/changes/232801/00-workerDocuware.sql | 10 +++++ .../{docuware.js => docuwareDownload.js} | 0 .../worker/back/methods/worker-dms/filter.js | 38 +++++++++++-------- modules/worker/back/models/worker-dms.js | 2 +- 5 files changed, 34 insertions(+), 23 deletions(-) delete mode 100644 db/changes/232401/00-workerDocuware.sql create mode 100644 db/changes/232801/00-workerDocuware.sql rename modules/worker/back/methods/worker-dms/{docuware.js => docuwareDownload.js} (100%) diff --git a/db/changes/232401/00-workerDocuware.sql b/db/changes/232401/00-workerDocuware.sql deleted file mode 100644 index c8d4e4f23..000000000 --- a/db/changes/232401/00-workerDocuware.sql +++ /dev/null @@ -1,7 +0,0 @@ -INSERT INTO `vn`.`docuware` (code, fileCabinetName, `action`, dialogName, findById) - VALUES - ('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO'); - -INSERT INTO `salix`.`url` (appName, environment, url) - VALUES - ('docuware', 'production', 'https://verdnatura.docuware.cloud/DocuWare/Platform/'); diff --git a/db/changes/232801/00-workerDocuware.sql b/db/changes/232801/00-workerDocuware.sql new file mode 100644 index 000000000..2d0ce3c33 --- /dev/null +++ b/db/changes/232801/00-workerDocuware.sql @@ -0,0 +1,10 @@ +ALTER TABLE `vn`.`docuware` ADD dmsTypeFk INT(11) DEFAULT NULL NULL; +ALTER TABLE `vn`.`docuware` ADD CONSTRAINT docuware_FK FOREIGN KEY (dmsTypeFk) REFERENCES `vn`.`dmsType`(id) ON DELETE RESTRICT ON UPDATE CASCADE; +INSERT INTO `vn`.`docuware` (code, fileCabinetName, `action`, dialogName, findById, dmsTypeFk) + VALUES + ('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO', NULL); + +INSERT INTO `salix`.`url` (appName, environment, url) + VALUES + ('docuware', 'production', 'https://verdnatura.docuware.cloud/DocuWare/Platform/'); + diff --git a/modules/worker/back/methods/worker-dms/docuware.js b/modules/worker/back/methods/worker-dms/docuwareDownload.js similarity index 100% rename from modules/worker/back/methods/worker-dms/docuware.js rename to modules/worker/back/methods/worker-dms/docuwareDownload.js diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index 0b89cc883..1343038b7 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -57,23 +57,31 @@ module.exports = Self => { const workerDms = await conn.executeStmt(stmt); // Get docuware info - const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']}); - const docuwareParse = { - 'Filename': 'dmsFk', - 'Tipo Documento': 'description', - 'Stored on': 'created', - }; - const workerDocuware = await models.Docuware.getById('hr', worker.lastName + worker.firstName, docuwareParse); - for (document of workerDocuware) { - const defaultData = { - file: document.dmsFk + '.png', - isDocuware: true, - hardCopyNumber: null, - hasFile: false, - reference: worker.fi + const docuware = await models.Docuware.findOne({ + fields: ['dmsTypeFk'], + where: {code: 'hr', action: 'find'} + }); + const docuwareDmsType = docuware.dmsTypeFk; + if (!(docuwareDmsType && !await models.DmsType.hasReadRole(ctx, docuwareDmsType))) { + const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']}); + const docuwareParse = { + 'Filename': 'dmsFk', + 'Tipo Documento': 'description', + 'Stored on': 'created', }; + const workerDocuware = + await models.Docuware.getById('hr', worker.lastName + worker.firstName, docuwareParse); + for (document of workerDocuware) { + const defaultData = { + file: document.dmsFk + '.png', + isDocuware: true, + hardCopyNumber: null, + hasFile: false, + reference: worker.fi + }; - document = Object.assign(document, defaultData); + document = Object.assign(document, defaultData); + } } return workerDms.concat(workerDocuware); diff --git a/modules/worker/back/models/worker-dms.js b/modules/worker/back/models/worker-dms.js index 1712383b3..6343e902e 100644 --- a/modules/worker/back/models/worker-dms.js +++ b/modules/worker/back/models/worker-dms.js @@ -2,7 +2,7 @@ module.exports = Self => { require('../methods/worker-dms/downloadFile')(Self); require('../methods/worker-dms/removeFile')(Self); require('../methods/worker-dms/filter')(Self); - require('../methods/worker-dms/docuware')(Self); + require('../methods/worker-dms/docuwareDownload')(Self); Self.isMine = async function(ctx, dmsId) { const myUserId = ctx.req.accessToken.userId; From 1a18ba66a940959bdae82335289ccd1a39a1fac8 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 4 Jul 2023 15:18:57 +0200 Subject: [PATCH 05/10] refs #5712 fix(workerDms): filter --- back/models/docuware.json | 7 +++++++ modules/worker/back/methods/worker-dms/filter.js | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/back/models/docuware.json b/back/models/docuware.json index dec20eede..b1a6a8bce 100644 --- a/back/models/docuware.json +++ b/back/models/docuware.json @@ -28,5 +28,12 @@ "findById": { "type": "string" } + }, + "relations": { + "dmsType": { + "type": "belongsTo", + "model": "DmsType", + "foreignKey": "dmsTypeFk" + } } } diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index 1343038b7..e19010988 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -62,22 +62,25 @@ module.exports = Self => { where: {code: 'hr', action: 'find'} }); const docuwareDmsType = docuware.dmsTypeFk; + let workerDocuware; if (!(docuwareDmsType && !await models.DmsType.hasReadRole(ctx, docuwareDmsType))) { const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']}); const docuwareParse = { 'Filename': 'dmsFk', 'Tipo Documento': 'description', 'Stored on': 'created', + 'Document ID': 'id' }; - const workerDocuware = + workerDocuware = await models.Docuware.getById('hr', worker.lastName + worker.firstName, docuwareParse); for (document of workerDocuware) { const defaultData = { - file: document.dmsFk + '.png', + file: 'dw' + document.id + '.png', isDocuware: true, hardCopyNumber: null, hasFile: false, - reference: worker.fi + reference: worker.fi, + dmsFk: 'DW' + document.id }; document = Object.assign(document, defaultData); From 444b08c566c18e0b716b38ff4f6f45b76116f921 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 5 Jul 2023 12:09:52 +0200 Subject: [PATCH 06/10] refs #5712 test(docuware) --- back/methods/docuware/checkFile.js | 15 +- back/methods/docuware/core.js | 18 ++- back/methods/docuware/specs/checkFile.spec.js | 74 ++-------- back/methods/docuware/specs/core.spec.js | 135 ++++++++++++++++++ back/methods/docuware/specs/download.spec.js | 2 +- db/changes/232801/00-workerDocuware.sql | 2 +- .../back/methods/ticket/docuwareDownload.js | 6 +- .../methods/worker-dms/docuwareDownload.js | 6 +- .../worker/back/methods/worker-dms/filter.js | 5 +- 9 files changed, 176 insertions(+), 87 deletions(-) create mode 100644 back/methods/docuware/specs/core.spec.js diff --git a/back/methods/docuware/checkFile.js b/back/methods/docuware/checkFile.js index 18d169085..19224057c 100644 --- a/back/methods/docuware/checkFile.js +++ b/back/methods/docuware/checkFile.js @@ -1,5 +1,3 @@ -const axios = require('axios'); - module.exports = Self => { Self.remoteMethod('checkFile', { description: 'Check if exist docuware file', @@ -73,17 +71,8 @@ module.exports = Self => { } try { - const options = await Self.getOptions(); - - const fileCabinetId = await Self.getFileCabinet(fileCabinet); - const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId); - - const response = await axios.post( - `${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, - filter, - options.headers - ); - const [documents] = response.data.Items; + const response = await Self.get(fileCabinet, filter); + const [documents] = response.Items; if (!documents) return false; return {id: documents.Id}; diff --git a/back/methods/docuware/core.js b/back/methods/docuware/core.js index 7bb3e617a..74d922236 100644 --- a/back/methods/docuware/core.js +++ b/back/methods/docuware/core.js @@ -32,10 +32,13 @@ module.exports = Self => { * @return {number} - The fileCabinet id */ Self.getDialog = async(code, action, fileCabinetId) => { + if (!process.env.NODE_ENV) + return Math.floor(Math.random() + 100); + const docuwareInfo = await Self.app.models.Docuware.findOne({ where: { - code: code, - action: action + code, + action } }); if (!fileCabinetId) fileCabinetId = await Self.getFileCabinet(code); @@ -56,10 +59,13 @@ module.exports = Self => { * @return {number} - The fileCabinet id */ Self.getFileCabinet = async code => { + if (!process.env.NODE_ENV) + return Math.floor(Math.random() + 100); + const options = await Self.getOptions(); const docuwareInfo = await Self.app.models.Docuware.findOne({ where: { - code: code + code } }); @@ -79,6 +85,8 @@ module.exports = Self => { * @return {object} - The data */ Self.get = async(code, filter, parse) => { + if (!process.env.NODE_ENV) return; + const options = await Self.getOptions(); const fileCabinetId = await Self.getFileCabinet(code); const dialogId = await Self.getDialog(code, 'find', fileCabinetId); @@ -100,10 +108,12 @@ module.exports = Self => { * @return {object} - The data */ Self.getById = async(code, id, parse) => { + if (!process.env.NODE_ENV) return; + const docuwareInfo = await Self.app.models.Docuware.findOne({ fields: ['findById'], where: { - code: code, + code, action: 'find' } }); diff --git a/back/methods/docuware/specs/checkFile.spec.js b/back/methods/docuware/specs/checkFile.spec.js index dd11951cc..8460bb561 100644 --- a/back/methods/docuware/specs/checkFile.spec.js +++ b/back/methods/docuware/specs/checkFile.spec.js @@ -1,57 +1,15 @@ const models = require('vn-loopback/server/server').models; -const axios = require('axios'); describe('docuware download()', () => { const ticketId = 1; - const userId = 9; - const ctx = { - req: { - - accessToken: {userId: userId}, - headers: {origin: 'http://localhost:5000'}, - } - }; const docuwareModel = models.Docuware; const fileCabinetName = 'deliveryNote'; - beforeAll(() => { - spyOn(docuwareModel, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); - spyOn(docuwareModel, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); - }); - it('should return false if there are no documents', async() => { - const response = { - data: { - Items: [] - } - }; - spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response))); + spyOn(docuwareModel, 'get').and.returnValue((new Promise(resolve => resolve({Items: []})))); - const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true); - - expect(result).toEqual(false); - }); - - it('should return false if the document is unsigned', async() => { - const response = { - data: { - Items: [ - { - Id: 1, - Fields: [ - { - FieldName: 'ESTADO', - Item: 'Unsigned' - } - ] - } - ] - } - }; - spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response))); - - const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true); + const result = await models.Docuware.checkFile(ticketId, fileCabinetName, null, true); expect(result).toEqual(false); }); @@ -59,23 +17,21 @@ describe('docuware download()', () => { it('should return the document data', async() => { const docuwareId = 1; const response = { - data: { - Items: [ - { - Id: docuwareId, - Fields: [ - { - FieldName: 'ESTADO', - Item: 'Firmado' - } - ] - } - ] - } + Items: [ + { + Id: docuwareId, + Fields: [ + { + FieldName: 'ESTADO', + Item: 'Firmado' + } + ] + } + ] }; - spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(response))); + spyOn(docuwareModel, 'get').and.returnValue((new Promise(resolve => resolve(response)))); - const result = await models.Docuware.checkFile(ctx, ticketId, fileCabinetName, true); + const result = await models.Docuware.checkFile(ticketId, fileCabinetName, null, true); expect(result.id).toEqual(docuwareId); }); diff --git a/back/methods/docuware/specs/core.spec.js b/back/methods/docuware/specs/core.spec.js new file mode 100644 index 000000000..cdf8a3b62 --- /dev/null +++ b/back/methods/docuware/specs/core.spec.js @@ -0,0 +1,135 @@ +const axios = require('axios'); +const models = require('vn-loopback/server/server').models; + +describe('Docuware core', () => { + beforeAll(() => { + process.env.NODE_ENV = 'testing'; + }); + + afterAll(() => { + delete process.env.NODE_ENV; + }); + + describe('getOptions()', () => { + it('should return url and headers', async() => { + const result = await models.Docuware.getOptions(); + + expect(result.url).toBeDefined(); + expect(result.headers).toBeDefined(); + }); + }); + + describe('getDialog()', () => { + it('should return dialogId', async() => { + const dialogs = { + data: { + Dialog: [ + { + DisplayName: 'find', + Id: 'getDialogTest' + } + ] + } + }; + spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs))); + const result = await models.Docuware.getDialog('deliveryNote', 'find', 'randomFileCabinetId'); + + expect(result).toEqual('getDialogTest'); + }); + }); + + describe('getFileCabinet()', () => { + it('should return fileCabinetId', async() => { + const code = 'deliveryNote'; + const docuwareInfo = await models.Docuware.findOne({ + where: { + code + } + }); + const dialogs = { + data: { + FileCabinet: [ + { + Name: docuwareInfo.fileCabinetName, + Id: 'getFileCabinetTest' + } + ] + } + }; + spyOn(axios, 'get').and.returnValue(new Promise(resolve => resolve(dialogs))); + const result = await models.Docuware.getFileCabinet(code); + + expect(result).toEqual('getFileCabinetTest'); + }); + }); + + describe('get()', () => { + it('should return data without parse', async() => { + spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); + spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); + const data = { + data: { + id: 1 + } + }; + spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); + const result = await models.Docuware.get('deliveryNote'); + + expect(result.id).toEqual(1); + }); + + it('should return data with parse', async() => { + spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); + spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); + const data = { + data: { + Items: [{ + Fields: [ + { + ItemElementName: 'integer', + FieldLabel: 'firstRequiredField', + Item: 1 + }, + { + ItemElementName: 'string', + FieldLabel: 'secondRequiredField', + Item: 'myName' + }, + { + ItemElementName: 'integer', + FieldLabel: 'notRequiredField', + Item: 2 + } + ] + }] + } + }; + const parse = { + 'firstRequiredField': 'id', + 'secondRequiredField': 'name', + }; + spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); + const [result] = await models.Docuware.get('deliveryNote', null, parse); + + expect(result.id).toEqual(1); + expect(result.name).toEqual('myName'); + expect(result.notRequiredField).not.toBeDefined(); + }); + }); + + describe('getById()', () => { + it('should return data', async() => { + spyOn(models.Docuware, 'getFileCabinet').and.returnValue((new Promise(resolve => resolve(Math.random())))); + spyOn(models.Docuware, 'getDialog').and.returnValue((new Promise(resolve => resolve(Math.random())))); + const data = { + data: { + id: 1 + } + }; + spyOn(axios, 'post').and.returnValue(new Promise(resolve => resolve(data))); + const result = await models.Docuware.getById('deliveryNote', 1); + + expect(result.id).toEqual(1); + }); + }); +}); diff --git a/back/methods/docuware/specs/download.spec.js b/back/methods/docuware/specs/download.spec.js index fcc1671a6..bc580a079 100644 --- a/back/methods/docuware/specs/download.spec.js +++ b/back/methods/docuware/specs/download.spec.js @@ -39,7 +39,7 @@ describe('docuware download()', () => { spyOn(docuwareModel, 'checkFile').and.returnValue({}); spyOn(axios, 'get').and.returnValue(new stream.PassThrough({objectMode: true})); - const result = await models.Docuware.download(ctx, ticketId, fileCabinetName); + const result = await models.Docuware.download(ticketId, fileCabinetName); expect(result[1]).toEqual('application/pdf'); expect(result[2]).toEqual(`filename="${ticketId}.pdf"`); diff --git a/db/changes/232801/00-workerDocuware.sql b/db/changes/232801/00-workerDocuware.sql index 2d0ce3c33..2f2c4a1cd 100644 --- a/db/changes/232801/00-workerDocuware.sql +++ b/db/changes/232801/00-workerDocuware.sql @@ -2,7 +2,7 @@ ALTER TABLE `vn`.`docuware` ADD dmsTypeFk INT(11) DEFAULT NULL NULL; ALTER TABLE `vn`.`docuware` ADD CONSTRAINT docuware_FK FOREIGN KEY (dmsTypeFk) REFERENCES `vn`.`dmsType`(id) ON DELETE RESTRICT ON UPDATE CASCADE; INSERT INTO `vn`.`docuware` (code, fileCabinetName, `action`, dialogName, findById, dmsTypeFk) VALUES - ('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO', NULL); + ('hr', 'RRHH', 'find', 'Búsqueda', 'N__DOCUMENTO', NULL); -- set dmsTypeFk 3 when deploy in production INSERT INTO `salix`.`url` (appName, environment, url) VALUES diff --git a/modules/ticket/back/methods/ticket/docuwareDownload.js b/modules/ticket/back/methods/ticket/docuwareDownload.js index bc74e0d21..e9b74b1a9 100644 --- a/modules/ticket/back/methods/ticket/docuwareDownload.js +++ b/modules/ticket/back/methods/ticket/docuwareDownload.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethodCtx('docuwareDownload', { + Self.remoteMethod('docuwareDownload', { description: 'Download a ticket delivery note document', accessType: 'READ', accepts: [ @@ -31,7 +31,7 @@ module.exports = Self => { } }); - Self.docuwareDownload = async function(ctx, id) { + Self.docuwareDownload = async id => { const filter = { condition: [ { @@ -50,6 +50,6 @@ module.exports = Self => { } ] }; - return await Self.app.models.Docuware.download(id, 'deliveryNote', filter); + return Self.app.models.Docuware.download(id, 'deliveryNote', filter); }; }; diff --git a/modules/worker/back/methods/worker-dms/docuwareDownload.js b/modules/worker/back/methods/worker-dms/docuwareDownload.js index 764b7633c..c64c159ed 100644 --- a/modules/worker/back/methods/worker-dms/docuwareDownload.js +++ b/modules/worker/back/methods/worker-dms/docuwareDownload.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethodCtx('docuwareDownload', { + Self.remoteMethod('docuwareDownload', { description: 'Download a worker document', accessType: 'READ', accepts: [ @@ -31,7 +31,7 @@ module.exports = Self => { } }); - Self.docuwareDownload = async function(ctx, id) { + Self.docuwareDownload = async id => { const filter = { condition: [ { @@ -40,6 +40,6 @@ module.exports = Self => { } ] }; - return await Self.app.models.Docuware.download(id, 'hr', filter); + return Self.app.models.Docuware.download(id, 'hr', filter); }; }; diff --git a/modules/worker/back/methods/worker-dms/filter.js b/modules/worker/back/methods/worker-dms/filter.js index e19010988..55db68d5d 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -62,8 +62,8 @@ module.exports = Self => { where: {code: 'hr', action: 'find'} }); const docuwareDmsType = docuware.dmsTypeFk; - let workerDocuware; - if (!(docuwareDmsType && !await models.DmsType.hasReadRole(ctx, docuwareDmsType))) { + let workerDocuware = []; + if (!docuwareDmsType || (docuwareDmsType && await models.DmsType.hasReadRole(ctx, docuwareDmsType))) { const worker = await models.Worker.findById(id, {fields: ['fi', 'firstName', 'lastName']}); const docuwareParse = { 'Filename': 'dmsFk', @@ -86,7 +86,6 @@ module.exports = Self => { document = Object.assign(document, defaultData); } } - return workerDms.concat(workerDocuware); }; }; From 5d933da28af0c03b33095375748664c9424b7612 Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 5 Jul 2023 12:14:26 +0200 Subject: [PATCH 07/10] refs #5712 fix empty data --- 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 55db68d5d..5f55f1bd7 100644 --- a/modules/worker/back/methods/worker-dms/filter.js +++ b/modules/worker/back/methods/worker-dms/filter.js @@ -72,7 +72,7 @@ module.exports = Self => { 'Document ID': 'id' }; workerDocuware = - await models.Docuware.getById('hr', worker.lastName + worker.firstName, docuwareParse); + await models.Docuware.getById('hr', worker.lastName + worker.firstName, docuwareParse) ?? []; for (document of workerDocuware) { const defaultData = { file: 'dw' + document.id + '.png', From 203f6a5659f6fdead03c013a43f2b59ec881e5f8 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 21 Jul 2023 12:41:16 +0200 Subject: [PATCH 08/10] refs #5712 correct sql folder --- db/changes/{232801 => 233201}/00-workerDocuware.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/{232801 => 233201}/00-workerDocuware.sql (100%) diff --git a/db/changes/232801/00-workerDocuware.sql b/db/changes/233201/00-workerDocuware.sql similarity index 100% rename from db/changes/232801/00-workerDocuware.sql rename to db/changes/233201/00-workerDocuware.sql From ade7303a6fd6878bac8d3de5bd88af0c61991254 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 21 Jul 2023 13:05:55 +0200 Subject: [PATCH 09/10] refs #6047 added editable-td component --- e2e/helpers/selectors.js | 2 +- e2e/paths/08-route/04_tickets.spec.js | 3 +-- modules/route/front/tickets/index.html | 21 +++++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 977c8a837..93288efa7 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -875,7 +875,7 @@ export default { }, routeTickets: { - firstTicketPriority: 'vn-route-tickets vn-tr:nth-child(1) vn-input-number[ng-model="ticket.priority"]', + firstTicketPriority: 'vn-route-tickets vn-tr:nth-child(1) vn-td-editable', firstTicketCheckbox: 'vn-route-tickets vn-tr:nth-child(1) vn-check', buscamanButton: 'vn-route-tickets vn-button[icon="icon-buscaman"]', firstTicketDeleteButton: 'vn-route-tickets vn-tr:nth-child(1) vn-icon[icon="delete"]', diff --git a/e2e/paths/08-route/04_tickets.spec.js b/e2e/paths/08-route/04_tickets.spec.js index ccd5562c2..c890162a1 100644 --- a/e2e/paths/08-route/04_tickets.spec.js +++ b/e2e/paths/08-route/04_tickets.spec.js @@ -18,8 +18,7 @@ describe('Route tickets path', () => { }); it('should modify the first ticket priority', async() => { - await page.clearInput(selectors.routeTickets.firstTicketPriority); - await page.type(selectors.routeTickets.firstTicketPriority, '9'); + await page.writeOnEditableTD(selectors.routeTickets.firstTicketPriority, '9'); await page.keyboard.press('Enter'); const message = await page.waitForSnackbar(); diff --git a/modules/route/front/tickets/index.html b/modules/route/front/tickets/index.html index 32a4a2d7c..453eb0517 100644 --- a/modules/route/front/tickets/index.html +++ b/modules/route/front/tickets/index.html @@ -84,14 +84,27 @@ tabindex="-1"> - - + + {{ticket.priority}} + + + + + + + {{::ticket.street}} Date: Fri, 21 Jul 2023 13:13:44 +0200 Subject: [PATCH 10/10] removed unnecesary comments --- modules/route/front/tickets/index.html | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/route/front/tickets/index.html b/modules/route/front/tickets/index.html index 453eb0517..ea6755cca 100644 --- a/modules/route/front/tickets/index.html +++ b/modules/route/front/tickets/index.html @@ -98,12 +98,6 @@ vn-focus> - {{::ticket.street}}