From b60cd2539a205433a24e41d38ae19d0ca81922e3 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 29 May 2023 15:21:37 +0200 Subject: [PATCH 01/46] 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/46] 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/46] 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 0cc5781f3fc2b562ee1fd617a40f35402be2fd6d Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 13 Jun 2023 15:05:37 +0200 Subject: [PATCH 04/46] =?UTF-8?q?refs=20#4734=20feat:=20a=C3=B1adido=20m?= =?UTF-8?q?=C3=A9todo=20putExpedicionInternacional=20de=20viaexpress?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../putExpedicionInternacional.js | 135 ++++++++++++++++++ back/model-config.json | 3 + back/models/viaexpress-config.js | 3 + back/models/viaexpress-config.json | 34 +++++ db/changes/232601/00-acl_viaexpressConfig.sql | 3 + db/changes/232601/00-viaexpress.sql | 13 ++ db/dump/fixtures.sql | 12 +- 7 files changed, 197 insertions(+), 6 deletions(-) create mode 100644 back/methods/viaexpress-config/putExpedicionInternacional.js create mode 100644 back/models/viaexpress-config.js create mode 100644 back/models/viaexpress-config.json create mode 100644 db/changes/232601/00-acl_viaexpressConfig.sql create mode 100644 db/changes/232601/00-viaexpress.sql diff --git a/back/methods/viaexpress-config/putExpedicionInternacional.js b/back/methods/viaexpress-config/putExpedicionInternacional.js new file mode 100644 index 000000000..dc1df3218 --- /dev/null +++ b/back/methods/viaexpress-config/putExpedicionInternacional.js @@ -0,0 +1,135 @@ +const axios = require('axios'); + +module.exports = Self => { + Self.remoteMethod('putExpedicionInternacional', { + description: 'Returns the lastest campaigns', + accessType: 'WRITE', + accepts: [{ + arg: 'expeditionFk', + type: 'number', + required: true + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/putExpedicionInternacional`, + verb: 'POST' + } + }); + + Self.putExpedicionInternacional = async(expeditionFk, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const [data] = await Self.rawSql(` + SELECT urlAccess, + clientViaexpress, + userViaexpress, + passwordViaexpress, + defaultWeight, + DATE_FORMAT(t.shipped, '%Y-%m-%d') shipped, + deliveryType, + cv.socialName senderName, + av.street senderStreet, + av.postalCode senderPostalCode, + av.city senderCity, + pv.name senderProvince, + IFNULL(av.mobile, IFNULL(av.phone, IFNULL(cv.mobile, cv.phone))) senderPhone, + SUBSTRING_INDEX(cv.email, ',', 1) senderEmail, + a.nickname receiverName, + a.street receiverStreet, + a.postalCode receiverPostalCode, + a.city receiverCity, + p.name receiverProvince, + IFNULL(a.mobile, IFNULL(a.phone, IFNULL(c.mobile, c.phone))) receiverPhone, + SUBSTRING_INDEX(c.email, ',', 1) receiverEmail, + c2.code receiverCountry + FROM vn.viaexpressConfig + JOIN vn.expedition e ON e.id = ? + JOIN vn.ticket t ON t.id = e.ticketFk + JOIN vn.address a ON a.id = t.addressFk + JOIN vn.province p ON p.id = a.provinceFk + JOIN vn.client c ON c.id = t.clientFk + JOIN vn.company co ON co.id = t.companyFk + JOIN vn.client cv ON cv.id = co.clientFk + JOIN vn.address av ON av.id = cv.defaultAddressFk + JOIN vn.province pv ON pv.id = av.provinceFk + JOIN vn.country c2 ON c2.id = p.countryFk`, [expeditionFk], myOptions); + + const xmlData = ` + + + + + ${data.defaultWeight} + 1 + 0 + ${data.shipped} + 0 + ${data.deliveryType} + 0 + 0 + 0 + 0 + 0 + + + 0 + + + + ${data.senderName} + ${data.senderStreet} + ${data.senderPostalCode} + ${data.senderCity} + ${data.senderProvince} + + ${data.senderPhone} + ${data.senderEmail} + + + ${data.receiverName} + ${data.receiverStreet} + ${data.receiverPostalCode} + ${data.receiverCity} + + ${data.receiverProvince} + + ${data.receiverPhone} + ${data.receiverEmail} + ${data.receiverCountry} + + + ${data.clientViaexpress} + ${data.userViaexpress} + ${data.passwordViaexpress} + + + + + `; + + const url = 'http://82.223.6.71:82/ServicioVxClientes.asmx'; + try { + const response = await axios.post(url, xmlData, { + headers: { + 'Content-Type': 'application/soap+xml; charset=utf-8' + } + }); + + const startTag = ''; + const endTag = ''; + const startIndex = response.data.indexOf(startTag) + startTag.length; + const endIndex = response.data.indexOf(endTag); + const referenciaVx = response.data.substring(startIndex, endIndex); + + return referenciaVx; + } catch (error) { + throw Error(error.response.data); + } + }; +}; diff --git a/back/model-config.json b/back/model-config.json index ff2bf5850..ec126455b 100644 --- a/back/model-config.json +++ b/back/model-config.json @@ -139,6 +139,9 @@ }, "PrintConfig": { "dataSource": "vn" + }, + "ViaexpressConfig": { + "dataSource": "vn" } } diff --git a/back/models/viaexpress-config.js b/back/models/viaexpress-config.js new file mode 100644 index 000000000..712bde60d --- /dev/null +++ b/back/models/viaexpress-config.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/viaexpress-config/putExpedicionInternacional')(Self); +}; diff --git a/back/models/viaexpress-config.json b/back/models/viaexpress-config.json new file mode 100644 index 000000000..ed150a448 --- /dev/null +++ b/back/models/viaexpress-config.json @@ -0,0 +1,34 @@ +{ + "name": "ViaexpressConfig", + "base": "VnModel", + "options": { + "mysql": { + "table": "viaexpressConfig" + } + }, + "properties": { + "id": { + "type": "number", + "required": true + }, + "urlAccess": { + "type": "string", + "required": true + }, + "clientViaexpress": { + "type": "date" + }, + "userViaexpress": { + "type": "number" + }, + "passwordViaexpress": { + "type": "number" + }, + "defaultWeight": { + "type": "number" + }, + "deliveryType": { + "type": "number" + } + } +} diff --git a/db/changes/232601/00-acl_viaexpressConfig.sql b/db/changes/232601/00-acl_viaexpressConfig.sql new file mode 100644 index 000000000..837185262 --- /dev/null +++ b/db/changes/232601/00-acl_viaexpressConfig.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('ViaexpressConfig', 'putExpedicionInternacional', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/232601/00-viaexpress.sql b/db/changes/232601/00-viaexpress.sql new file mode 100644 index 000000000..1313135f9 --- /dev/null +++ b/db/changes/232601/00-viaexpress.sql @@ -0,0 +1,13 @@ +CREATE TABLE `vn`.`viaexpressConfig` ( + id int auto_increment NOT NULL, + urlAccess varchar(100) NOT NULL, + clientViaexpress varchar(100) NOT NULL, + userViaexpress varchar(100) NOT NULL, + passwordViaexpress varchar(100) NOT NULL, + defaultWeight decimal(10,2) NOT NULL, + deliveryType varchar(5) NOT NULL, + CONSTRAINT viaexpressConfig_PK PRIMARY KEY (id) +) +ENGINE=InnoDB +DEFAULT CHARSET=utf8mb3 +COLLATE=utf8mb3_unicode_ci; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index a6557ff89..eddb1f6a9 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -566,13 +566,13 @@ INSERT INTO `vn`.`supplierAccount`(`id`, `supplierFk`, `iban`, `bankEntityFk`) VALUES (241, 442, 'ES111122333344111122221111', 128); -INSERT INTO `vn`.`company`(`id`, `code`, `supplierAccountFk`, `workerManagerFk`, `companyCode`, `sage200Company`, `expired`, `companyGroupFk`, `phytosanitary`) +INSERT INTO `vn`.`company`(`id`, `code`, `supplierAccountFk`, `workerManagerFk`, `companyCode`, `sage200Company`, `expired`, `companyGroupFk`, `phytosanitary` , `clientFk`) VALUES - (69 , 'CCs', NULL, 30, NULL, 0, NULL, 1, NULL), - (442 , 'VNL', 241, 30, 2 , 1, NULL, 2, 'VNL Company - Plant passport'), - (567 , 'VNH', NULL, 30, NULL, 4, NULL, 1, 'VNH Company - Plant passport'), - (791 , 'FTH', NULL, 30, NULL, 3, '2015-11-30', 1, NULL), - (1381, 'ORN', NULL, 30, NULL, 7, NULL, 1, 'ORN Company - Plant passport'); + (69 , 'CCs', NULL, 30, NULL, 0, NULL, 1, NULL , NULL), + (442 , 'VNL', 241, 30, 2 , 1, NULL, 2, 'VNL Company - Plant passport' , 1101), + (567 , 'VNH', NULL, 30, NULL, 4, NULL, 1, 'VNH Company - Plant passport' , NULL), + (791 , 'FTH', NULL, 30, NULL, 3, '2015-11-30', 1, NULL , NULL), + (1381, 'ORN', NULL, 30, NULL, 7, NULL, 1, 'ORN Company - Plant passport' , NULL); INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`) VALUES From 0a9bdc6f891b050c95f1806857681c4119dd5ff8 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 16 Jun 2023 13:25:45 +0200 Subject: [PATCH 05/46] test: jenkins test secuenciales --- Jenkinsfile | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cf9b8cd67..1fe2cfc9b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,19 +54,17 @@ pipeline { NODE_ENV = "" TZ = 'Europe/Madrid' } - parallel { - stage('Frontend') { - steps { - nodejs('node-v20') { - sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2' - } + stage('Frontend') { + steps { + nodejs('node-v20') { + sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2' } } - stage('Backend') { - steps { - nodejs('node-v20') { - sh 'npm run test:back:ci' - } + } + stage('Backend') { + steps { + nodejs('node-v20') { + sh 'npm run test:back:ci' } } } From 1f4e98075cfa5d36ed309246870b8e6572e97f6b Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 16 Jun 2023 13:27:35 +0200 Subject: [PATCH 06/46] fix: test secuendiales --- Jenkinsfile | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1fe2cfc9b..72d70dc97 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,17 +54,19 @@ pipeline { NODE_ENV = "" TZ = 'Europe/Madrid' } - stage('Frontend') { - steps { - nodejs('node-v20') { - sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2' + steps { + stage('Frontend') { + steps { + nodejs('node-v20') { + sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2' + } } } - } - stage('Backend') { - steps { - nodejs('node-v20') { - sh 'npm run test:back:ci' + stage('Backend') { + steps { + nodejs('node-v20') { + sh 'npm run test:back:ci' + } } } } From a31b735d3cef087646a8d7ea1d498741cfb942cd Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 16 Jun 2023 13:29:00 +0200 Subject: [PATCH 07/46] fix --- Jenkinsfile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 72d70dc97..5345b6dfe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,17 +55,18 @@ pipeline { TZ = 'Europe/Madrid' } steps { - stage('Frontend') { - steps { - nodejs('node-v20') { - sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2' + script { + if (!env.BRANCH_NAME.equals('test') && !env.BRANCH_NAME.equals('master')) { + stage('Frontend') { + nodejs('node-v20') { + sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2' + } } - } - } - stage('Backend') { - steps { - nodejs('node-v20') { - sh 'npm run test:back:ci' + + stage('Backend') { + nodejs('node-v20') { + sh 'npm run test:back:ci' + } } } } From 2da54ac3d72175c28cb7b11972dcba43fa0e6cc7 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 16 Jun 2023 13:39:05 +0200 Subject: [PATCH 08/46] test secuenciales --- Jenkinsfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5345b6dfe..897bf4f3e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -57,17 +57,17 @@ pipeline { steps { script { if (!env.BRANCH_NAME.equals('test') && !env.BRANCH_NAME.equals('master')) { - stage('Frontend') { - nodejs('node-v20') { - sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2' - } - } - stage('Backend') { nodejs('node-v20') { sh 'npm run test:back:ci' } } + + stage('Frontend') { + nodejs('node-v20') { + sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2' + } + } } } } From 998597dfcc53f90f4fe5bc4334f87045c2d5f05b Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 16 Jun 2023 13:49:21 +0200 Subject: [PATCH 09/46] refs #4734 recator: cambiado nombre ruta --- ...onInternacional.js => internationalExpedition.js} | 12 ++++++------ back/models/viaexpress-config.js | 2 +- back/models/viaexpress-config.json | 2 +- db/changes/232601/00-acl_viaexpressConfig.sql | 2 +- db/changes/232601/00-viaexpress.sql | 7 ++----- 5 files changed, 11 insertions(+), 14 deletions(-) rename back/methods/viaexpress-config/{putExpedicionInternacional.js => internationalExpedition.js} (94%) diff --git a/back/methods/viaexpress-config/putExpedicionInternacional.js b/back/methods/viaexpress-config/internationalExpedition.js similarity index 94% rename from back/methods/viaexpress-config/putExpedicionInternacional.js rename to back/methods/viaexpress-config/internationalExpedition.js index dc1df3218..99a4197c7 100644 --- a/back/methods/viaexpress-config/putExpedicionInternacional.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -1,7 +1,7 @@ const axios = require('axios'); module.exports = Self => { - Self.remoteMethod('putExpedicionInternacional', { + Self.remoteMethod('internationalExpedition', { description: 'Returns the lastest campaigns', accessType: 'WRITE', accepts: [{ @@ -14,19 +14,20 @@ module.exports = Self => { root: true }, http: { - path: `/putExpedicionInternacional`, + path: `/internationalExpedition`, verb: 'POST' } }); - Self.putExpedicionInternacional = async(expeditionFk, options) => { + Self.internationalExpedition = async(expeditionFk, options) => { const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); const [data] = await Self.rawSql(` - SELECT urlAccess, + SELECT + url, clientViaexpress, userViaexpress, passwordViaexpress, @@ -113,9 +114,8 @@ module.exports = Self => { `; - const url = 'http://82.223.6.71:82/ServicioVxClientes.asmx'; try { - const response = await axios.post(url, xmlData, { + const response = await axios.post(`${data.url}ServicioVxClientes.asmx`, xmlData, { headers: { 'Content-Type': 'application/soap+xml; charset=utf-8' } diff --git a/back/models/viaexpress-config.js b/back/models/viaexpress-config.js index 712bde60d..72424f806 100644 --- a/back/models/viaexpress-config.js +++ b/back/models/viaexpress-config.js @@ -1,3 +1,3 @@ module.exports = Self => { - require('../methods/viaexpress-config/putExpedicionInternacional')(Self); + require('../methods/viaexpress-config/internationalExpedition')(Self); }; diff --git a/back/models/viaexpress-config.json b/back/models/viaexpress-config.json index ed150a448..5927cee3f 100644 --- a/back/models/viaexpress-config.json +++ b/back/models/viaexpress-config.json @@ -11,7 +11,7 @@ "type": "number", "required": true }, - "urlAccess": { + "url": { "type": "string", "required": true }, diff --git a/db/changes/232601/00-acl_viaexpressConfig.sql b/db/changes/232601/00-acl_viaexpressConfig.sql index 837185262..91a7e3c5b 100644 --- a/db/changes/232601/00-acl_viaexpressConfig.sql +++ b/db/changes/232601/00-acl_viaexpressConfig.sql @@ -1,3 +1,3 @@ INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES - ('ViaexpressConfig', 'putExpedicionInternacional', 'WRITE', 'ALLOW', 'ROLE', 'employee'); + ('ViaexpressConfig', 'internationalExpedition', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/232601/00-viaexpress.sql b/db/changes/232601/00-viaexpress.sql index 1313135f9..9e3baa9fd 100644 --- a/db/changes/232601/00-viaexpress.sql +++ b/db/changes/232601/00-viaexpress.sql @@ -1,13 +1,10 @@ CREATE TABLE `vn`.`viaexpressConfig` ( id int auto_increment NOT NULL, - urlAccess varchar(100) NOT NULL, + url varchar(100) NOT NULL, clientViaexpress varchar(100) NOT NULL, userViaexpress varchar(100) NOT NULL, passwordViaexpress varchar(100) NOT NULL, defaultWeight decimal(10,2) NOT NULL, deliveryType varchar(5) NOT NULL, CONSTRAINT viaexpressConfig_PK PRIMARY KEY (id) -) -ENGINE=InnoDB -DEFAULT CHARSET=utf8mb3 -COLLATE=utf8mb3_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci; From 1027e0753e399e4e7ed39d35468c1c5197945623 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 16 Jun 2023 14:06:36 +0200 Subject: [PATCH 10/46] test in paralel --- Jenkinsfile | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 897bf4f3e..cf9b8cd67 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,19 +54,18 @@ pipeline { NODE_ENV = "" TZ = 'Europe/Madrid' } - steps { - script { - if (!env.BRANCH_NAME.equals('test') && !env.BRANCH_NAME.equals('master')) { - stage('Backend') { - nodejs('node-v20') { - sh 'npm run test:back:ci' - } + parallel { + stage('Frontend') { + steps { + nodejs('node-v20') { + sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2' } - - stage('Frontend') { - nodejs('node-v20') { - sh 'jest --ci --reporters=default --reporters=jest-junit --maxWorkers=2' - } + } + } + stage('Backend') { + steps { + nodejs('node-v20') { + sh 'npm run test:back:ci' } } } From 90ce0d1c275e1f508bceb8a13224aef97262ada4 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 16 Jun 2023 14:24:47 +0200 Subject: [PATCH 11/46] refs #4734 refactor: consulta con loopback --- .../internationalExpedition.js | 95 +++++++++++++++++-- back/models/company.json | 7 ++ 2 files changed, 96 insertions(+), 6 deletions(-) diff --git a/back/methods/viaexpress-config/internationalExpedition.js b/back/methods/viaexpress-config/internationalExpedition.js index 99a4197c7..fd8d69e6d 100644 --- a/back/methods/viaexpress-config/internationalExpedition.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -20,6 +20,7 @@ module.exports = Self => { }); Self.internationalExpedition = async(expeditionFk, options) => { + const models = Self.app.models; const myOptions = {}; if (typeof options == 'object') @@ -27,13 +28,13 @@ module.exports = Self => { const [data] = await Self.rawSql(` SELECT - url, - clientViaexpress, - userViaexpress, - passwordViaexpress, - defaultWeight, + -- url, + -- clientViaexpress, + -- userViaexpress, + -- passwordViaexpress, + -- defaultWeight, + -- deliveryType, DATE_FORMAT(t.shipped, '%Y-%m-%d') shipped, - deliveryType, cv.socialName senderName, av.street senderStreet, av.postalCode senderPostalCode, @@ -61,6 +62,88 @@ module.exports = Self => { JOIN vn.province pv ON pv.id = av.provinceFk JOIN vn.country c2 ON c2.id = p.countryFk`, [expeditionFk], myOptions); + const expedition = await models.Expedition.findOne({ + fields: ['id', 'ticketFk'], + where: {id: expeditionFk}, + include: [ + { + relation: 'ticket', + scope: { + fields: ['shipped', 'addressFk', 'clientFk', 'companyFk'], + include: [ + { + relation: 'client', + scope: { + fields: ['mobile', 'phone', 'email'] + } + }, + { + relation: 'address', + scope: { + fields: [ + 'nickname', + 'street', + 'postalCode', + 'city', + 'mobile', + 'phone', + 'provinceFk' + ], + include: { + relation: 'province', + scope: { + fields: ['name', 'countryFk'], + include: { + relation: 'country', + scope: { + fields: ['code'], + } + } + + } + } + } + }, + { + relation: 'company', + scope: { + fields: ['clientFk'], + include: { + relation: 'client', + scope: { + fields: ['socialName', 'mobile', 'phone', 'email', 'defaultAddressFk'], + include: { + relation: 'defaultAddress', + scope: { + fields: [ + 'street', + 'postalCode', + 'city', + 'mobile', + 'phone', + 'provinceFk' + ], + include: { + relation: 'province', + scope: { + fields: ['name'] + } + } + } + } + } + } + } + } + ] + } + + } + ] + }, myOptions); + console.log(data); + console.log(expedition); + const xmlData = ` diff --git a/back/models/company.json b/back/models/company.json index f16c5762f..53266e38a 100644 --- a/back/models/company.json +++ b/back/models/company.json @@ -24,5 +24,12 @@ "where" :{ "expired": null } + }, + "relations": { + "client": { + "type": "belongsTo", + "model": "Client", + "foreignKey": "clientFk" + } } } From ab68cb7165a0ae7a34074c6699f716a1476600e1 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 16 Jun 2023 14:27:29 +0200 Subject: [PATCH 12/46] refs #4734 fix: manejo errores --- back/methods/viaexpress-config/internationalExpedition.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/back/methods/viaexpress-config/internationalExpedition.js b/back/methods/viaexpress-config/internationalExpedition.js index fd8d69e6d..dd46ff794 100644 --- a/back/methods/viaexpress-config/internationalExpedition.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -212,7 +212,8 @@ module.exports = Self => { return referenciaVx; } catch (error) { - throw Error(error.response.data); + if (error?.response?.data) throw Error(error.response.data); + throw Error(error); } }; }; From 219ad75172ad57a6e76fa4ae84c718f249f0f3b6 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 16 Jun 2023 14:30:33 +0200 Subject: [PATCH 13/46] a --- .../viaexpress-config/internationalExpedition.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/back/methods/viaexpress-config/internationalExpedition.js b/back/methods/viaexpress-config/internationalExpedition.js index dd46ff794..23b62e845 100644 --- a/back/methods/viaexpress-config/internationalExpedition.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -28,12 +28,12 @@ module.exports = Self => { const [data] = await Self.rawSql(` SELECT - -- url, - -- clientViaexpress, - -- userViaexpress, - -- passwordViaexpress, - -- defaultWeight, - -- deliveryType, + url, + clientViaexpress, + userViaexpress, + passwordViaexpress, + defaultWeight, + deliveryType, DATE_FORMAT(t.shipped, '%Y-%m-%d') shipped, cv.socialName senderName, av.street senderStreet, From 303be74382a9bc38f931e994db15027df9e890f7 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 19 Jun 2023 11:55:07 +0200 Subject: [PATCH 14/46] refs #4734 refactor: use loopback instead of --- .../internationalExpedition.js | 92 +++++++------------ back/models/viaexpress-config.json | 8 +- 2 files changed, 36 insertions(+), 64 deletions(-) diff --git a/back/methods/viaexpress-config/internationalExpedition.js b/back/methods/viaexpress-config/internationalExpedition.js index 23b62e845..70a68acd6 100644 --- a/back/methods/viaexpress-config/internationalExpedition.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -26,42 +26,6 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const [data] = await Self.rawSql(` - SELECT - url, - clientViaexpress, - userViaexpress, - passwordViaexpress, - defaultWeight, - deliveryType, - DATE_FORMAT(t.shipped, '%Y-%m-%d') shipped, - cv.socialName senderName, - av.street senderStreet, - av.postalCode senderPostalCode, - av.city senderCity, - pv.name senderProvince, - IFNULL(av.mobile, IFNULL(av.phone, IFNULL(cv.mobile, cv.phone))) senderPhone, - SUBSTRING_INDEX(cv.email, ',', 1) senderEmail, - a.nickname receiverName, - a.street receiverStreet, - a.postalCode receiverPostalCode, - a.city receiverCity, - p.name receiverProvince, - IFNULL(a.mobile, IFNULL(a.phone, IFNULL(c.mobile, c.phone))) receiverPhone, - SUBSTRING_INDEX(c.email, ',', 1) receiverEmail, - c2.code receiverCountry - FROM vn.viaexpressConfig - JOIN vn.expedition e ON e.id = ? - JOIN vn.ticket t ON t.id = e.ticketFk - JOIN vn.address a ON a.id = t.addressFk - JOIN vn.province p ON p.id = a.provinceFk - JOIN vn.client c ON c.id = t.clientFk - JOIN vn.company co ON co.id = t.companyFk - JOIN vn.client cv ON cv.id = co.clientFk - JOIN vn.address av ON av.id = cv.defaultAddressFk - JOIN vn.province pv ON pv.id = av.provinceFk - JOIN vn.country c2 ON c2.id = p.countryFk`, [expeditionFk], myOptions); - const expedition = await models.Expedition.findOne({ fields: ['id', 'ticketFk'], where: {id: expeditionFk}, @@ -141,20 +105,28 @@ module.exports = Self => { } ] }, myOptions); - console.log(data); - console.log(expedition); + + const viaexpressConfig = await models.ViaexpressConfig.findOne({ + fields: ['url', 'clientViaexpress', 'userViaexpress', 'passwordViaexpress', 'defaultWeight', 'deliveryType'] + }, myOptions); + + const shipped = expedition.ticket().shipped; + const year = shipped.getFullYear(); + const month = shipped.getMonth() + 1; + const day = shipped.getDate(); + const date = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`; const xmlData = ` - ${data.defaultWeight} + ${viaexpressConfig.defaultWeight} 1 0 - ${data.shipped} + ${date} 0 - ${data.deliveryType} + ${viaexpressConfig.deliveryType} 0 0 0 @@ -166,31 +138,31 @@ module.exports = Self => { - ${data.senderName} - ${data.senderStreet} - ${data.senderPostalCode} - ${data.senderCity} - ${data.senderProvince} + ${expedition.ticket().company().client().socialName} + ${expedition.ticket().company().client().defaultAddress().street} + ${expedition.ticket().company().client().defaultAddress().postalCode} + ${expedition.ticket().company().client().defaultAddress().city} + ${expedition.ticket().company().client().defaultAddress().province().name} - ${data.senderPhone} - ${data.senderEmail} + ${expedition.ticket().company().client().defaultAddress().mobile || expedition.ticket().company().client().defaultAddress().phone || expedition.ticket().company().client().mobile || expedition.ticket().company().client().phone} + ${expedition.ticket().company().client().email} - ${data.receiverName} - ${data.receiverStreet} - ${data.receiverPostalCode} - ${data.receiverCity} + ${expedition.ticket().address().nickname} + ${expedition.ticket().address().street} + ${expedition.ticket().address().postalCode} + ${expedition.ticket().address().city} - ${data.receiverProvince} + ${expedition.ticket().address().province().name} - ${data.receiverPhone} - ${data.receiverEmail} - ${data.receiverCountry} + ${expedition.ticket().address().mobile || expedition.ticket().address().phone || expedition.ticket().client().mobile || expedition.ticket().client().phone} + ${expedition.ticket().client().email} + ${expedition.ticket().address().province().country().code} - ${data.clientViaexpress} - ${data.userViaexpress} - ${data.passwordViaexpress} + ${viaexpressConfig.clientViaexpress} + ${viaexpressConfig.userViaexpress} + ${viaexpressConfig.passwordViaexpress} @@ -198,7 +170,7 @@ module.exports = Self => { `; try { - const response = await axios.post(`${data.url}ServicioVxClientes.asmx`, xmlData, { + const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, xmlData, { headers: { 'Content-Type': 'application/soap+xml; charset=utf-8' } diff --git a/back/models/viaexpress-config.json b/back/models/viaexpress-config.json index 5927cee3f..26d6c8e37 100644 --- a/back/models/viaexpress-config.json +++ b/back/models/viaexpress-config.json @@ -16,19 +16,19 @@ "required": true }, "clientViaexpress": { - "type": "date" + "type": "string" }, "userViaexpress": { - "type": "number" + "type": "string" }, "passwordViaexpress": { - "type": "number" + "type": "string" }, "defaultWeight": { "type": "number" }, "deliveryType": { - "type": "number" + "type": "string" } } } From cfe340eeff471d70d188e5f1b5573179b38941b1 Mon Sep 17 00:00:00 2001 From: vicent Date: Mon, 19 Jun 2023 14:27:24 +0200 Subject: [PATCH 15/46] refs #4734 feat: xml en otro archivo --- .../internationalExpedition.js | 232 ++++++------------ back/methods/viaexpress-config/renderer.js | 162 ++++++++++++ back/methods/viaexpress-config/template.xml | 52 ++++ back/models/viaexpress-config.js | 1 + package.json | 1 + 5 files changed, 285 insertions(+), 163 deletions(-) create mode 100644 back/methods/viaexpress-config/renderer.js create mode 100644 back/methods/viaexpress-config/template.xml diff --git a/back/methods/viaexpress-config/internationalExpedition.js b/back/methods/viaexpress-config/internationalExpedition.js index 70a68acd6..cbb1c2c67 100644 --- a/back/methods/viaexpress-config/internationalExpedition.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -1,4 +1,5 @@ const axios = require('axios'); +const fs = require('fs'); module.exports = Self => { Self.remoteMethod('internationalExpedition', { @@ -19,173 +20,78 @@ module.exports = Self => { } }); - Self.internationalExpedition = async(expeditionFk, options) => { + Self.internationalExpedition = async expeditionFk => { const models = Self.app.models; - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - const expedition = await models.Expedition.findOne({ - fields: ['id', 'ticketFk'], - where: {id: expeditionFk}, - include: [ - { - relation: 'ticket', - scope: { - fields: ['shipped', 'addressFk', 'clientFk', 'companyFk'], - include: [ - { - relation: 'client', - scope: { - fields: ['mobile', 'phone', 'email'] - } - }, - { - relation: 'address', - scope: { - fields: [ - 'nickname', - 'street', - 'postalCode', - 'city', - 'mobile', - 'phone', - 'provinceFk' - ], - include: { - relation: 'province', - scope: { - fields: ['name', 'countryFk'], - include: { - relation: 'country', - scope: { - fields: ['code'], - } - } - - } - } - } - }, - { - relation: 'company', - scope: { - fields: ['clientFk'], - include: { - relation: 'client', - scope: { - fields: ['socialName', 'mobile', 'phone', 'email', 'defaultAddressFk'], - include: { - relation: 'defaultAddress', - scope: { - fields: [ - 'street', - 'postalCode', - 'city', - 'mobile', - 'phone', - 'provinceFk' - ], - include: { - relation: 'province', - scope: { - fields: ['name'] - } - } - } - } - } - } - } - } - ] - } - - } - ] - }, myOptions); const viaexpressConfig = await models.ViaexpressConfig.findOne({ - fields: ['url', 'clientViaexpress', 'userViaexpress', 'passwordViaexpress', 'defaultWeight', 'deliveryType'] - }, myOptions); + fields: ['url'] + }); - const shipped = expedition.ticket().shipped; - const year = shipped.getFullYear(); - const month = shipped.getMonth() + 1; - const day = shipped.getDate(); - const date = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`; + const renderedXml = await models.ViaexpressConfig.renderer(expeditionFk); + // const renderedXml = ` + // + // + // + // + // 10 + // 1 + // 0 + // 2023-06-12 + // 0 + // E + // 0 + // 0 + // 0 + // 0 + // 0 + // + // + // 0 + // + // + // + // VERDNATURA LEVANTE SL + // FENOLLARS, 2 + // 46680 + // Algemesi + // Valencia + // + // 963677177 + // pako.natek@gmail.com + // + // + // ROSAMARY FLORISTERIA + // C SANTA ROSA,25 + // 03802 + // ALCOY + // ALCOY + // Alicante + // + // 653967489 + // correo@floristeriarosamary.com + // ES + // + // + // 16092 + // B97367486 + // VERDNA22 + // + // + // + // + // `; + const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, renderedXml, { + headers: { + 'Content-Type': 'application/soap+xml; charset=utf-8' + } + }); + console.log(response); + const startTag = ''; + const endTag = ''; + const startIndex = response.data.indexOf(startTag) + startTag.length; + const endIndex = response.data.indexOf(endTag); + const referenciaVx = response.data.substring(startIndex, endIndex); - const xmlData = ` - - - - - ${viaexpressConfig.defaultWeight} - 1 - 0 - ${date} - 0 - ${viaexpressConfig.deliveryType} - 0 - 0 - 0 - 0 - 0 - - - 0 - - - - ${expedition.ticket().company().client().socialName} - ${expedition.ticket().company().client().defaultAddress().street} - ${expedition.ticket().company().client().defaultAddress().postalCode} - ${expedition.ticket().company().client().defaultAddress().city} - ${expedition.ticket().company().client().defaultAddress().province().name} - - ${expedition.ticket().company().client().defaultAddress().mobile || expedition.ticket().company().client().defaultAddress().phone || expedition.ticket().company().client().mobile || expedition.ticket().company().client().phone} - ${expedition.ticket().company().client().email} - - - ${expedition.ticket().address().nickname} - ${expedition.ticket().address().street} - ${expedition.ticket().address().postalCode} - ${expedition.ticket().address().city} - - ${expedition.ticket().address().province().name} - - ${expedition.ticket().address().mobile || expedition.ticket().address().phone || expedition.ticket().client().mobile || expedition.ticket().client().phone} - ${expedition.ticket().client().email} - ${expedition.ticket().address().province().country().code} - - - ${viaexpressConfig.clientViaexpress} - ${viaexpressConfig.userViaexpress} - ${viaexpressConfig.passwordViaexpress} - - - - - `; - - try { - const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, xmlData, { - headers: { - 'Content-Type': 'application/soap+xml; charset=utf-8' - } - }); - - const startTag = ''; - const endTag = ''; - const startIndex = response.data.indexOf(startTag) + startTag.length; - const endIndex = response.data.indexOf(endTag); - const referenciaVx = response.data.substring(startIndex, endIndex); - - return referenciaVx; - } catch (error) { - if (error?.response?.data) throw Error(error.response.data); - throw Error(error); - } + return referenciaVx; }; }; diff --git a/back/methods/viaexpress-config/renderer.js b/back/methods/viaexpress-config/renderer.js new file mode 100644 index 000000000..79dab21c9 --- /dev/null +++ b/back/methods/viaexpress-config/renderer.js @@ -0,0 +1,162 @@ +const fs = require('fs'); +const handlebars = require('handlebars'); + +module.exports = Self => { + Self.remoteMethod('renderer', { + description: 'Returns the lastest campaigns', + accessType: 'READ', + accepts: [{ + arg: 'expeditionFk', + type: 'number', + required: true + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/renderer`, + verb: 'GET' + } + }); + + Self.renderer = async expeditionFk => { + const models = Self.app.models; + + const viaexpressConfig = await models.ViaexpressConfig.findOne({ + fields: ['clientViaexpress', 'userViaexpress', 'passwordViaexpress', 'defaultWeight', 'deliveryType'] + }); + + const expedition = await models.Expedition.findOne({ + fields: ['id', 'ticketFk'], + where: {id: expeditionFk}, + include: [ + { + relation: 'ticket', + scope: { + fields: ['shipped', 'addressFk', 'clientFk', 'companyFk'], + include: [ + { + relation: 'client', + scope: { + fields: ['mobile', 'phone', 'email'] + } + }, + { + relation: 'address', + scope: { + fields: [ + 'nickname', + 'street', + 'postalCode', + 'city', + 'mobile', + 'phone', + 'provinceFk' + ], + include: { + relation: 'province', + scope: { + fields: ['name', 'countryFk'], + include: { + relation: 'country', + scope: { + fields: ['code'], + } + } + + } + } + } + }, + { + relation: 'company', + scope: { + fields: ['clientFk'], + include: { + relation: 'client', + scope: { + fields: ['socialName', 'mobile', 'phone', 'email', 'defaultAddressFk'], + include: { + relation: 'defaultAddress', + scope: { + fields: [ + 'street', + 'postalCode', + 'city', + 'mobile', + 'phone', + 'provinceFk' + ], + include: { + relation: 'province', + scope: { + fields: ['name'] + } + } + } + } + } + } + } + } + ] + } + + } + ] + }); + + const shipped = expedition.ticket().shipped; + const year = shipped.getFullYear(); + const month = shipped.getMonth() + 1; + const day = shipped.getDate(); + const date = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`; + + const data = { + defaultWeight: viaexpressConfig.defaultWeight, + date: date, // const date = new Date().toISOString(); + deliveryType: viaexpressConfig.deliveryType, + senderName: expedition.ticket().company().client().socialName, + senderStreet: expedition.ticket().company().client().defaultAddress().street, + senderPostalCode: expedition.ticket().company().client().defaultAddress().postalCode, + senderCity: expedition.ticket().company().client().defaultAddress().city, + senderProvince: expedition.ticket().company().client().defaultAddress().province().name, + senderPhone: expedition.ticket().company().client().defaultAddress().mobile + || expedition.ticket().company().client().defaultAddress().phone + || expedition.ticket().company().client().mobile + || expedition.ticket().company().client().phone, + senderEmail: expedition.ticket().company().client().email, + receiverName: expedition.ticket().address().nickname, + receiverStreet: expedition.ticket().address().street, + receiverPostalCode: expedition.ticket().address().postalCode, + receiverCity: expedition.ticket().address().city, + receiverProvince: expedition.ticket().address().province().name, + receiverPhone: expedition.ticket().address().mobile + || expedition.ticket().address().phone + || expedition.ticket().client().mobile + || expedition.ticket().client().phone, + receiverEmail: expedition.ticket().client().email, + receiverCountry: expedition.ticket().address().province().country().code, + clientViaexpress: viaexpressConfig.clientViaexpress, + userViaexpress: viaexpressConfig.userViaexpress, + passwordViaexpress: viaexpressConfig.passwordViaexpress + }; + + const templateXml = fs.readFileSync(__dirname + '/template.xml', 'utf-8'); + + // // Crea una instancia de Vue con los datos + // const vueInstance = new Vue({ + // data: data, + // template: templateXml, + // }); + + // // Renderiza la plantilla con los datos utilizando vue-server-renderer + // const renderer = createRenderer(); + // return renderer.renderToString(vueInstance); + + const compiledTemplate = handlebars.compile(templateXml); + const renderedHtml = compiledTemplate(data); + return renderedHtml; + }; +}; diff --git a/back/methods/viaexpress-config/template.xml b/back/methods/viaexpress-config/template.xml new file mode 100644 index 000000000..141fb939a --- /dev/null +++ b/back/methods/viaexpress-config/template.xml @@ -0,0 +1,52 @@ + + + + + + {{ defaultWeight }} + 1 + 0 + {{ date }} + 0 + {{ deliveryType }} + 0 + 0 + 0 + 0 + 0 + + + 0 + + + + {{ senderName }} + {{ senderStreet }} + {{ senderPostalCode }} + {{ senderCity }} + {{ senderProvince }} + + {{ senderPhone }} + {{ senderEmail }} + + + {{ receiverName }} + {{ receiverStreet }} + {{ receiverPostalCode }} + {{ receiverCity }} + + {{ receiverProvince }} + + {{ receiverPhone }} + {{ receiverEmail }} + {{ receiverCountry }} + + + {{ clientViaexpress }} + {{ userViaexpress }} + {{ passwordViaexpress }} + + + + + diff --git a/back/models/viaexpress-config.js b/back/models/viaexpress-config.js index 72424f806..d0335b28b 100644 --- a/back/models/viaexpress-config.js +++ b/back/models/viaexpress-config.js @@ -1,3 +1,4 @@ module.exports = Self => { require('../methods/viaexpress-config/internationalExpedition')(Self); + require('../methods/viaexpress-config/renderer')(Self); }; diff --git a/package.json b/package.json index 4358c86a7..857a7c172 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "ftps": "^1.2.0", "gm": "^1.25.0", "got": "^10.7.0", + "handlebars": "^4.7.7", "helmet": "^3.21.2", "i18n": "^0.8.4", "image-type": "^4.1.0", From 1ba19714da1d8c14d5ee54ca4cbe044cae8a86d5 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 20 Jun 2023 07:11:45 +0200 Subject: [PATCH 16/46] refs #4734 feat: add acl --- db/changes/232601/00-acl_viaexpressConfig.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/changes/232601/00-acl_viaexpressConfig.sql b/db/changes/232601/00-acl_viaexpressConfig.sql index 91a7e3c5b..d4c186dd4 100644 --- a/db/changes/232601/00-acl_viaexpressConfig.sql +++ b/db/changes/232601/00-acl_viaexpressConfig.sql @@ -1,3 +1,4 @@ INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES - ('ViaexpressConfig', 'internationalExpedition', 'WRITE', 'ALLOW', 'ROLE', 'employee'); + ('ViaexpressConfig', 'internationalExpedition', 'WRITE', 'ALLOW', 'ROLE', 'employee'), + ('ViaexpressConfig', 'renderer', 'READ', 'ALLOW', 'ROLE', 'employee'); From c3af2e3c925186e56f31a0f80f33b4095604770b Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 20 Jun 2023 07:19:32 +0200 Subject: [PATCH 17/46] refs #4734 refactor: actualizada descripcion --- back/methods/viaexpress-config/internationalExpedition.js | 3 +-- back/methods/viaexpress-config/renderer.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/back/methods/viaexpress-config/internationalExpedition.js b/back/methods/viaexpress-config/internationalExpedition.js index cbb1c2c67..75f44401f 100644 --- a/back/methods/viaexpress-config/internationalExpedition.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -1,9 +1,8 @@ const axios = require('axios'); -const fs = require('fs'); module.exports = Self => { Self.remoteMethod('internationalExpedition', { - description: 'Returns the lastest campaigns', + description: 'Create an expedition and return a label', accessType: 'WRITE', accepts: [{ arg: 'expeditionFk', diff --git a/back/methods/viaexpress-config/renderer.js b/back/methods/viaexpress-config/renderer.js index 79dab21c9..7308b482e 100644 --- a/back/methods/viaexpress-config/renderer.js +++ b/back/methods/viaexpress-config/renderer.js @@ -3,7 +3,7 @@ const handlebars = require('handlebars'); module.exports = Self => { Self.remoteMethod('renderer', { - description: 'Returns the lastest campaigns', + description: 'Renders the data from an XML', accessType: 'READ', accepts: [{ arg: 'expeditionFk', From 13e95bcd35920d28fa170b97b2d317cf4cee918d Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 20 Jun 2023 11:25:47 +0200 Subject: [PATCH 18/46] add vue commented code --- back/methods/viaexpress-config/renderer.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/back/methods/viaexpress-config/renderer.js b/back/methods/viaexpress-config/renderer.js index 7308b482e..588733174 100644 --- a/back/methods/viaexpress-config/renderer.js +++ b/back/methods/viaexpress-config/renderer.js @@ -1,5 +1,7 @@ const fs = require('fs'); const handlebars = require('handlebars'); +// const Vue = require('vue'); +// const renderer = require('vue-server-renderer').createRenderer(); module.exports = Self => { Self.remoteMethod('renderer', { From 4444b45b08e5e5427408d15f57b7ff80b87bce1e Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 20 Jun 2023 14:07:36 +0200 Subject: [PATCH 19/46] refs #4734 feat: se utiliza la libreria ejs y xmldom --- .../internationalExpedition.js | 65 ++----------------- back/methods/viaexpress-config/renderer.js | 28 ++------ back/methods/viaexpress-config/template.ejs | 52 +++++++++++++++ back/methods/viaexpress-config/template.xml | 52 --------------- 4 files changed, 64 insertions(+), 133 deletions(-) create mode 100644 back/methods/viaexpress-config/template.ejs delete mode 100644 back/methods/viaexpress-config/template.xml diff --git a/back/methods/viaexpress-config/internationalExpedition.js b/back/methods/viaexpress-config/internationalExpedition.js index 75f44401f..698bb1dac 100644 --- a/back/methods/viaexpress-config/internationalExpedition.js +++ b/back/methods/viaexpress-config/internationalExpedition.js @@ -1,4 +1,5 @@ const axios = require('axios'); +const {DOMParser} = require('xmldom'); module.exports = Self => { Self.remoteMethod('internationalExpedition', { @@ -27,69 +28,17 @@ module.exports = Self => { }); const renderedXml = await models.ViaexpressConfig.renderer(expeditionFk); - // const renderedXml = ` - // - // - // - // - // 10 - // 1 - // 0 - // 2023-06-12 - // 0 - // E - // 0 - // 0 - // 0 - // 0 - // 0 - // - // - // 0 - // - // - // - // VERDNATURA LEVANTE SL - // FENOLLARS, 2 - // 46680 - // Algemesi - // Valencia - // - // 963677177 - // pako.natek@gmail.com - // - // - // ROSAMARY FLORISTERIA - // C SANTA ROSA,25 - // 03802 - // ALCOY - // ALCOY - // Alicante - // - // 653967489 - // correo@floristeriarosamary.com - // ES - // - // - // 16092 - // B97367486 - // VERDNA22 - // - // - // - // - // `; const response = await axios.post(`${viaexpressConfig.url}ServicioVxClientes.asmx`, renderedXml, { headers: { 'Content-Type': 'application/soap+xml; charset=utf-8' } }); - console.log(response); - const startTag = ''; - const endTag = ''; - const startIndex = response.data.indexOf(startTag) + startTag.length; - const endIndex = response.data.indexOf(endTag); - const referenciaVx = response.data.substring(startIndex, endIndex); + + const xmlString = response.data; + const parser = new DOMParser(); + const xmlDoc = parser.parseFromString(xmlString, 'text/xml'); + const referenciaVxElement = xmlDoc.getElementsByTagName('ReferenciaVx')[0]; + const referenciaVx = referenciaVxElement.textContent; return referenciaVx; }; diff --git a/back/methods/viaexpress-config/renderer.js b/back/methods/viaexpress-config/renderer.js index 588733174..4014dd42d 100644 --- a/back/methods/viaexpress-config/renderer.js +++ b/back/methods/viaexpress-config/renderer.js @@ -1,7 +1,5 @@ const fs = require('fs'); -const handlebars = require('handlebars'); -// const Vue = require('vue'); -// const renderer = require('vue-server-renderer').createRenderer(); +const ejs = require('ejs'); module.exports = Self => { Self.remoteMethod('renderer', { @@ -110,14 +108,10 @@ module.exports = Self => { }); const shipped = expedition.ticket().shipped; - const year = shipped.getFullYear(); - const month = shipped.getMonth() + 1; - const day = shipped.getDate(); - const date = `${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}`; const data = { defaultWeight: viaexpressConfig.defaultWeight, - date: date, // const date = new Date().toISOString(); + date: shipped.toISOString(), // const date = new Date().toISOString(); deliveryType: viaexpressConfig.deliveryType, senderName: expedition.ticket().company().client().socialName, senderStreet: expedition.ticket().company().client().defaultAddress().street, @@ -145,20 +139,8 @@ module.exports = Self => { passwordViaexpress: viaexpressConfig.passwordViaexpress }; - const templateXml = fs.readFileSync(__dirname + '/template.xml', 'utf-8'); - - // // Crea una instancia de Vue con los datos - // const vueInstance = new Vue({ - // data: data, - // template: templateXml, - // }); - - // // Renderiza la plantilla con los datos utilizando vue-server-renderer - // const renderer = createRenderer(); - // return renderer.renderToString(vueInstance); - - const compiledTemplate = handlebars.compile(templateXml); - const renderedHtml = compiledTemplate(data); - return renderedHtml; + const template = fs.readFileSync(__dirname + '/template.ejs', 'utf-8'); + const renderedXml = ejs.render(template, data); + return renderedXml; }; }; diff --git a/back/methods/viaexpress-config/template.ejs b/back/methods/viaexpress-config/template.ejs new file mode 100644 index 000000000..e8b1f1977 --- /dev/null +++ b/back/methods/viaexpress-config/template.ejs @@ -0,0 +1,52 @@ + + + + + + <%= defaultWeight %> + 1 + 0 + <%= date %> + 0 + <%= deliveryType %> + 0 + 0 + 0 + 0 + 0 + + + 0 + + + + <%= senderName %> + <%= senderStreet %> + <%= senderPostalCode %> + <%= senderCity %> + <%= senderProvince %> + + <%= senderPhone %> + <%= senderEmail %> + + + <%= receiverName %> + <%= receiverStreet %> + <%= receiverPostalCode %> + <%= receiverCity %> + + <%= receiverProvince %> + + <%= receiverPhone %> + <%= receiverEmail %> + <%= receiverCountry %> + + + <%= clientViaexpress %> + <%= userViaexpress %> + <%= passwordViaexpress %> + + + + + diff --git a/back/methods/viaexpress-config/template.xml b/back/methods/viaexpress-config/template.xml deleted file mode 100644 index 141fb939a..000000000 --- a/back/methods/viaexpress-config/template.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - {{ defaultWeight }} - 1 - 0 - {{ date }} - 0 - {{ deliveryType }} - 0 - 0 - 0 - 0 - 0 - - - 0 - - - - {{ senderName }} - {{ senderStreet }} - {{ senderPostalCode }} - {{ senderCity }} - {{ senderProvince }} - - {{ senderPhone }} - {{ senderEmail }} - - - {{ receiverName }} - {{ receiverStreet }} - {{ receiverPostalCode }} - {{ receiverCity }} - - {{ receiverProvince }} - - {{ receiverPhone }} - {{ receiverEmail }} - {{ receiverCountry }} - - - {{ clientViaexpress }} - {{ userViaexpress }} - {{ passwordViaexpress }} - - - - - From 783d4c60c4d7e81e5cf99369944947fac7624502 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 28 Jun 2023 13:02:47 +0200 Subject: [PATCH 20/46] refs #4734 delete module handlebars from package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 857a7c172..4358c86a7 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "ftps": "^1.2.0", "gm": "^1.25.0", "got": "^10.7.0", - "handlebars": "^4.7.7", "helmet": "^3.21.2", "i18n": "^0.8.4", "image-type": "^4.1.0", From 4f616397a2d1c513f5e051872fb7468de28e5978 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 3 Jul 2023 15:05:39 +0200 Subject: [PATCH 21/46] 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 22/46] 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 23/46] 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 24/46] 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 112d7a84e336b6242ff04a845faf256bb81b71b2 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 13 Jul 2023 09:32:08 +0200 Subject: [PATCH 25/46] solved test --- back/methods/vn-user/specs/addAlias.spec.js | 68 ------------------- modules/ticket/front/descriptor-menu/index.js | 2 +- 2 files changed, 1 insertion(+), 69 deletions(-) delete mode 100644 back/methods/vn-user/specs/addAlias.spec.js diff --git a/back/methods/vn-user/specs/addAlias.spec.js b/back/methods/vn-user/specs/addAlias.spec.js deleted file mode 100644 index ef657a3a8..000000000 --- a/back/methods/vn-user/specs/addAlias.spec.js +++ /dev/null @@ -1,68 +0,0 @@ -const {models} = require('vn-loopback/server/server'); - -describe('VnUser addAlias()', () => { - const employeeId = 1; - const sysadminId = 66; - const developerId = 9; - const customerId = 2; - const mailAlias = 1; - it('should throw an error when user not has privileges', async() => { - const ctx = {req: {accessToken: {userId: employeeId}}}; - const tx = await models.VnUser.beginTransaction({}); - - let error; - try { - const options = {transaction: tx}; - - await models.VnUser.addAlias(ctx, employeeId, mailAlias, options); - - await tx.rollback(); - } catch (e) { - error = e; - await tx.rollback(); - } - - expect(error.message).toContain(`You don't have grant privilege`); - }); - - it('should throw an error when user has privileges but not has the role from user', async() => { - const ctx = {req: {accessToken: {userId: sysadminId}}}; - const tx = await models.VnUser.beginTransaction({}); - - let error; - try { - const options = {transaction: tx}; - - await models.VnUser.addAlias(ctx, employeeId, mailAlias, options); - - await tx.rollback(); - } catch (e) { - error = e; - await tx.rollback(); - } - - expect(error.message).toContain(`You cannot assign an alias that you are not assigned to`); - }); - - it('should add an alias', async() => { - const ctx = {req: {accessToken: {userId: developerId}}}; - const tx = await models.VnUser.beginTransaction({}); - - let result; - try { - const options = {transaction: tx}; - - const user = await models.VnUser.findById(developerId, null, options); - await user.updateAttribute('hasGrant', true, options); - - result = await models.VnUser.addAlias(ctx, customerId, mailAlias, options); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - } - - expect(result.mailAlias).toBe(mailAlias); - expect(result.account).toBe(customerId); - }); -}); diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 0b47102ac..0fc8488ca 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -270,7 +270,7 @@ class Controller extends Section { }); } - return this.$http.post(`Tickets/invoiceTickets`, params) + return this.$http.post(`Tickets/invoiceTickets`, {ticketsIds: [this.id]}) .then(() => this.reload()) .then(() => this.vnApp.showSuccess(this.$t('Ticket invoiced'))); } From 834e4b3723d3d3c9ed569f1397a4d75d475a59e0 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 18 Jul 2023 07:56:44 +0200 Subject: [PATCH 26/46] refs #4734 refactor: variables definindas --- back/methods/viaexpress-config/renderer.js | 40 +++++--------------- back/methods/viaexpress-config/template.ejs | 42 ++++++++++----------- back/models/viaexpress-config.json | 6 +-- db/changes/232601/00-viaexpress.sql | 6 +-- 4 files changed, 37 insertions(+), 57 deletions(-) diff --git a/back/methods/viaexpress-config/renderer.js b/back/methods/viaexpress-config/renderer.js index 4014dd42d..e9abce5ca 100644 --- a/back/methods/viaexpress-config/renderer.js +++ b/back/methods/viaexpress-config/renderer.js @@ -24,7 +24,7 @@ module.exports = Self => { const models = Self.app.models; const viaexpressConfig = await models.ViaexpressConfig.findOne({ - fields: ['clientViaexpress', 'userViaexpress', 'passwordViaexpress', 'defaultWeight', 'deliveryType'] + fields: ['client', 'user', 'password', 'defaultWeight', 'deliveryType'] }); const expedition = await models.Expedition.findOne({ @@ -107,36 +107,16 @@ module.exports = Self => { ] }); - const shipped = expedition.ticket().shipped; - + const ticket = expedition.ticket(); + const sender = ticket.company().client(); + const shipped = ticket.shipped.toISOString(); const data = { - defaultWeight: viaexpressConfig.defaultWeight, - date: shipped.toISOString(), // const date = new Date().toISOString(); - deliveryType: viaexpressConfig.deliveryType, - senderName: expedition.ticket().company().client().socialName, - senderStreet: expedition.ticket().company().client().defaultAddress().street, - senderPostalCode: expedition.ticket().company().client().defaultAddress().postalCode, - senderCity: expedition.ticket().company().client().defaultAddress().city, - senderProvince: expedition.ticket().company().client().defaultAddress().province().name, - senderPhone: expedition.ticket().company().client().defaultAddress().mobile - || expedition.ticket().company().client().defaultAddress().phone - || expedition.ticket().company().client().mobile - || expedition.ticket().company().client().phone, - senderEmail: expedition.ticket().company().client().email, - receiverName: expedition.ticket().address().nickname, - receiverStreet: expedition.ticket().address().street, - receiverPostalCode: expedition.ticket().address().postalCode, - receiverCity: expedition.ticket().address().city, - receiverProvince: expedition.ticket().address().province().name, - receiverPhone: expedition.ticket().address().mobile - || expedition.ticket().address().phone - || expedition.ticket().client().mobile - || expedition.ticket().client().phone, - receiverEmail: expedition.ticket().client().email, - receiverCountry: expedition.ticket().address().province().country().code, - clientViaexpress: viaexpressConfig.clientViaexpress, - userViaexpress: viaexpressConfig.userViaexpress, - passwordViaexpress: viaexpressConfig.passwordViaexpress + viaexpressConfig, + sender, + senderAddress: sender.defaultAddress(), + client: ticket.client(), + address: ticket.address(), + shipped }; const template = fs.readFileSync(__dirname + '/template.ejs', 'utf-8'); diff --git a/back/methods/viaexpress-config/template.ejs b/back/methods/viaexpress-config/template.ejs index e8b1f1977..0b6eb468c 100644 --- a/back/methods/viaexpress-config/template.ejs +++ b/back/methods/viaexpress-config/template.ejs @@ -3,12 +3,12 @@ - <%= defaultWeight %> + <%= viaexpressConfig.defaultWeight %> 1 0 - <%= date %> + <%= shipped %> 0 - <%= deliveryType %> + <%= viaexpressConfig.deliveryType %> 0 0 0 @@ -20,31 +20,31 @@ - <%= senderName %> - <%= senderStreet %> - <%= senderPostalCode %> - <%= senderCity %> - <%= senderProvince %> + <%= sender.socialName %> + <%= senderAddress.street %> + <%= senderAddress.postalCode %> + <%= senderAddress.city %> + <%= senderAddress.province().name %> - <%= senderPhone %> - <%= senderEmail %> + <%= senderAddress.mobile || senderAddress.phone || sender.mobile || sender.phone %> + <%= sender.email %> - <%= receiverName %> - <%= receiverStreet %> - <%= receiverPostalCode %> - <%= receiverCity %> + <%= address.nickname %> + <%= address.street %> + <%= address.postalCode %> + <%= address.city %> - <%= receiverProvince %> + <%= address.province().name %> - <%= receiverPhone %> - <%= receiverEmail %> - <%= receiverCountry %> + <%= address.mobile || address.phone || client.mobile || client.phone %> + <%= client.email %> + <%= address.province().country().code %> - <%= clientViaexpress %> - <%= userViaexpress %> - <%= passwordViaexpress %> + <%= viaexpressConfig.client %> + <%= viaexpressConfig.user %> + <%= viaexpressConfig.password %> diff --git a/back/models/viaexpress-config.json b/back/models/viaexpress-config.json index 26d6c8e37..8df24201b 100644 --- a/back/models/viaexpress-config.json +++ b/back/models/viaexpress-config.json @@ -15,13 +15,13 @@ "type": "string", "required": true }, - "clientViaexpress": { + "client": { "type": "string" }, - "userViaexpress": { + "user": { "type": "string" }, - "passwordViaexpress": { + "password": { "type": "string" }, "defaultWeight": { diff --git a/db/changes/232601/00-viaexpress.sql b/db/changes/232601/00-viaexpress.sql index 9e3baa9fd..42cf3b647 100644 --- a/db/changes/232601/00-viaexpress.sql +++ b/db/changes/232601/00-viaexpress.sql @@ -1,9 +1,9 @@ CREATE TABLE `vn`.`viaexpressConfig` ( id int auto_increment NOT NULL, url varchar(100) NOT NULL, - clientViaexpress varchar(100) NOT NULL, - userViaexpress varchar(100) NOT NULL, - passwordViaexpress varchar(100) NOT NULL, + client varchar(100) NOT NULL, + user varchar(100) NOT NULL, + password varchar(100) NOT NULL, defaultWeight decimal(10,2) NOT NULL, deliveryType varchar(5) NOT NULL, CONSTRAINT viaexpressConfig_PK PRIMARY KEY (id) From 7bd378e9dde911c7176e92fc1d4a5883f44e071d Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 18 Jul 2023 14:15:56 +0200 Subject: [PATCH 27/46] refs # --- back/models/company.json | 3 + db/changes/233001/00-company.sql | 1 + loopback/locale/en.json | 1 + loopback/locale/es.json | 4 +- .../back/methods/client/canBeInvoiced.js | 25 ++++++- .../ticket/back/methods/ticket/makeInvoice.js | 4 +- print/templates/reports/invoice/sql/sales.sql | 66 ++++++------------- 7 files changed, 53 insertions(+), 51 deletions(-) create mode 100644 db/changes/233001/00-company.sql diff --git a/back/models/company.json b/back/models/company.json index f16c5762f..f8b5641ac 100644 --- a/back/models/company.json +++ b/back/models/company.json @@ -18,6 +18,9 @@ }, "expired": { "type": "date" + }, + "supplierAccountFk": { + "type": "number" } }, "scope": { diff --git a/db/changes/233001/00-company.sql b/db/changes/233001/00-company.sql new file mode 100644 index 000000000..a3b61b9cc --- /dev/null +++ b/db/changes/233001/00-company.sql @@ -0,0 +1 @@ +ALTER TABLE `vn`.`company` MODIFY COLUMN sage200Company int(2) DEFAULT 10 NOT NULL; diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 030afbe9e..5c7c10967 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -177,6 +177,7 @@ "Mail not sent": "There has been an error sending the invoice to the client [{{clientId}}]({{{clientUrl}}}), please check the email address", "The renew period has not been exceeded": "The renew period has not been exceeded", "You can not use the same password": "You can not use the same password", + "The company has not informed the supplier account for bank transfers": "La empresa no tiene informado la cuenta de proveedor para transferencias bancarias", "Valid priorities": "Valid priorities: %d", "Negative basis of tickets": "Negative basis of tickets: {{ticketsIds}}" } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 784ff5e6e..69f157a47 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -305,5 +305,7 @@ "The renew period has not been exceeded": "El periodo de renovación no ha sido superado", "Valid priorities": "Prioridades válidas: %d", "Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}", - "You cannot assign an alias that you are not assigned to": "No puede asignar un alias que no tenga asignado" + "You cannot assign an alias that you are not assigned to": "No puede asignar un alias que no tenga asignado", + "The company has not informed the supplier account for bank transfers": "La empresa no tiene informado la cuenta de proveedor para transferencias bancarias" + " } diff --git a/modules/client/back/methods/client/canBeInvoiced.js b/modules/client/back/methods/client/canBeInvoiced.js index 567d491f1..843e9549f 100644 --- a/modules/client/back/methods/client/canBeInvoiced.js +++ b/modules/client/back/methods/client/canBeInvoiced.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = function(Self) { Self.remoteMethodCtx('canBeInvoiced', { description: 'Change property isEqualizated in all client addresses', @@ -9,6 +11,12 @@ module.exports = function(Self) { required: true, description: 'Client id', http: {source: 'path'} + }, + { + arg: 'companyFk', + description: 'The company id', + type: 'number', + required: true } ], returns: { @@ -22,18 +30,29 @@ module.exports = function(Self) { } }); - Self.canBeInvoiced = async(id, options) => { + Self.canBeInvoiced = async(id, companyFk, options) => { const models = Self.app.models; - const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); const client = await models.Client.findById(id, { - fields: ['id', 'isTaxDataChecked', 'hasToInvoice'] + fields: ['id', 'isTaxDataChecked', 'hasToInvoice', 'payMethodFk'], + include: + { + relation: 'payMethod', + scope: { + fields: ['code'] + } + } }, myOptions); + const company = await models.Company.findById(companyFk, {fields: ['supplierAccountFk']}, myOptions); + + if (client.payMethod().code === 'wireTransfer' && !company.supplierAccountFk) + throw new UserError('The company has not informed the supplier account for bank transfers'); + if (client.isTaxDataChecked && client.hasToInvoice) return true; diff --git a/modules/ticket/back/methods/ticket/makeInvoice.js b/modules/ticket/back/methods/ticket/makeInvoice.js index 22fe7b3f5..e18e58e0b 100644 --- a/modules/ticket/back/methods/ticket/makeInvoice.js +++ b/modules/ticket/back/methods/ticket/makeInvoice.js @@ -14,7 +14,7 @@ module.exports = function(Self) { { arg: 'companyFk', description: 'The company id', - type: 'string', + type: 'number', required: true }, { @@ -67,7 +67,7 @@ module.exports = function(Self) { const [firstTicket] = tickets; const clientId = firstTicket.clientFk; - const clientCanBeInvoiced = await models.Client.canBeInvoiced(clientId, myOptions); + const clientCanBeInvoiced = await models.Client.canBeInvoiced(clientId, companyFk, myOptions); if (!clientCanBeInvoiced) throw new UserError(`This client can't be invoiced`); diff --git a/print/templates/reports/invoice/sql/sales.sql b/print/templates/reports/invoice/sql/sales.sql index f5721a594..3833a3700 100644 --- a/print/templates/reports/invoice/sql/sales.sql +++ b/print/templates/reports/invoice/sql/sales.sql @@ -1,31 +1,19 @@ -SELECT +SELECT io.ref, - c.socialName, - sa.iban, - pm.name AS payMethod, - t.clientFk, - t.shipped, - t.nickname, s.ticketFk, - s.itemFk, - s.concept, - s.quantity, - s.price, + ib.ediBotanic botanical, + s.quantity, + s.price, s.discount, - i.tag5, - i.value5, - i.tag6, - i.value6, - i.tag7, - i.value7, - tc.code AS vatType, - ib.ediBotanic botanical + s.itemFk, + s.concept, + tc.code vatType FROM vn.invoiceOut io JOIN vn.ticket t ON t.refFk = io.ref JOIN vn.supplier su ON su.id = io.companyFk - JOIN vn.client c ON c.id = t.clientFk + JOIN vn.client c ON c.id = t.clientFk JOIN vn.payMethod pm ON pm.id = c.payMethodFk - JOIN vn.company co ON co.id = io.companyFk + JOIN vn.company co ON co.id = io.companyFk JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk JOIN vn.sale s ON s.ticketFk = t.id JOIN item i ON i.id = s.itemFk @@ -38,35 +26,23 @@ SELECT AND itc.itemFk = s.itemFk JOIN vn.taxClass tc ON tc.id = itc.taxClassFk WHERE t.refFk = ? - UNION ALL -SELECT + UNION ALL +SELECT io.ref, - c.socialName, - sa.iban, - pm.name AS payMethod, - t.clientFk, - t.shipped, - t.nickname, - t.id AS ticketFk, + t.id ticketFk, + NULL botanical, + ts.quantity, + ts.price, + 0 discount, '', - ts.description concept, - ts.quantity, - ts.price, - 0 discount, - NULL AS tag5, - NULL AS value5, - NULL AS tag6, - NULL AS value6, - NULL AS tag7, - NULL AS value7, - tc.code AS vatType, - NULL AS botanical + ts.description concept, + tc.code vatType FROM vn.invoiceOut io JOIN vn.ticket t ON t.refFk = io.ref JOIN vn.ticketService ts ON ts.ticketFk = t.id - JOIN vn.client c ON c.id = t.clientFk + JOIN vn.client c ON c.id = t.clientFk JOIN vn.payMethod pm ON pm.id = c.payMethodFk - JOIN vn.company co ON co.id = io.companyFk + JOIN vn.company co ON co.id = io.companyFk JOIN vn.supplierAccount sa ON sa.id = co.supplierAccountFk JOIN vn.taxClass tc ON tc.id = ts.taxClassFk - WHERE t.refFk = ? \ No newline at end of file + WHERE t.refFk = ? From 4c7f42acb5a05bd868dbc095feff9504d80f2d91 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 18 Jul 2023 14:17:07 +0200 Subject: [PATCH 28/46] a --- loopback/locale/es.json | 1 - 1 file changed, 1 deletion(-) diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 69f157a47..9412a9571 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -307,5 +307,4 @@ "Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}", "You cannot assign an alias that you are not assigned to": "No puede asignar un alias que no tenga asignado", "The company has not informed the supplier account for bank transfers": "La empresa no tiene informado la cuenta de proveedor para transferencias bancarias" - " } From d3165fcdc75c74bb05a15060dcfec1c55bc80394 Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 18 Jul 2023 14:25:53 +0200 Subject: [PATCH 29/46] refs #5849 fix: tback --- .../client/back/methods/client/specs/canBeInvoiced.spec.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/client/back/methods/client/specs/canBeInvoiced.spec.js b/modules/client/back/methods/client/specs/canBeInvoiced.spec.js index 2f11d8013..397be3c92 100644 --- a/modules/client/back/methods/client/specs/canBeInvoiced.spec.js +++ b/modules/client/back/methods/client/specs/canBeInvoiced.spec.js @@ -4,6 +4,7 @@ const LoopBackContext = require('loopback-context'); describe('client canBeInvoiced()', () => { const userId = 19; const clientId = 1101; + const companyId = 442; const activeCtx = { accessToken: {userId: userId} }; @@ -23,7 +24,7 @@ describe('client canBeInvoiced()', () => { const client = await models.Client.findById(clientId, null, options); await client.updateAttribute('isTaxDataChecked', false, options); - const canBeInvoiced = await models.Client.canBeInvoiced(clientId, options); + const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options); expect(canBeInvoiced).toEqual(false); @@ -43,7 +44,7 @@ describe('client canBeInvoiced()', () => { const client = await models.Client.findById(clientId, null, options); await client.updateAttribute('hasToInvoice', false, options); - const canBeInvoiced = await models.Client.canBeInvoiced(clientId, options); + const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options); expect(canBeInvoiced).toEqual(false); @@ -60,7 +61,7 @@ describe('client canBeInvoiced()', () => { try { const options = {transaction: tx}; - const canBeInvoiced = await models.Client.canBeInvoiced(clientId, options); + const canBeInvoiced = await models.Client.canBeInvoiced(clientId, companyId, options); expect(canBeInvoiced).toEqual(true); From b13618529aebd455f42d1285dbe59e2c6313549a Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 20 Jul 2023 07:21:38 +0200 Subject: [PATCH 30/46] =?UTF-8?q?refs=20#5849=20delete:=20traducci=C3=B3n?= =?UTF-8?q?=20erronea?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- loopback/locale/en.json | 1 - 1 file changed, 1 deletion(-) diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 5c7c10967..030afbe9e 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -177,7 +177,6 @@ "Mail not sent": "There has been an error sending the invoice to the client [{{clientId}}]({{{clientUrl}}}), please check the email address", "The renew period has not been exceeded": "The renew period has not been exceeded", "You can not use the same password": "You can not use the same password", - "The company has not informed the supplier account for bank transfers": "La empresa no tiene informado la cuenta de proveedor para transferencias bancarias", "Valid priorities": "Valid priorities: %d", "Negative basis of tickets": "Negative basis of tickets: {{ticketsIds}}" } From 75ea5942729af3e528157f6b946ef0d3679596e7 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 20 Jul 2023 09:32:52 +0200 Subject: [PATCH 31/46] refs #6011 deploy(2332): init version --- CHANGELOG.md | 9 +++++++++ db/changes/233201/.gitkeep | 0 package-lock.json | 2 +- package.json | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 db/changes/233201/.gitkeep diff --git a/CHANGELOG.md b/CHANGELOG.md index d5928e9c4..d4a1e147f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2330.01] - 2023-07-27 + +### Added + +### Changed + +### Fixed + + ## [2330.01] - 2023-07-27 ### Added diff --git a/db/changes/233201/.gitkeep b/db/changes/233201/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/package-lock.json b/package-lock.json index ee6d4e0fa..5506075b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "23.30.01", + "version": "23.32.01", "lockfileVersion": 2, "requires": true, "packages": { diff --git a/package.json b/package.json index 66e341ad5..37e39d5a5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "salix-back", - "version": "23.30.01", + "version": "23.32.01", "author": "Verdnatura Levante SL", "description": "Salix backend", "license": "GPL-3.0", From 9db8ae237fcbb9fce120af1f237d7b6496338fd7 Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 20 Jul 2023 10:19:03 +0200 Subject: [PATCH 32/46] refs #5866 addBackTransferClient --- db/changes/233001/00-transferClient.sql | 2 + .../back/methods/ticket/transferClient.js | 69 +++++++++++++++++++ modules/ticket/back/models/ticket-methods.js | 1 + modules/ticket/front/descriptor-menu/index.js | 8 +++ 4 files changed, 80 insertions(+) create mode 100644 db/changes/233001/00-transferClient.sql create mode 100644 modules/ticket/back/methods/ticket/transferClient.js diff --git a/db/changes/233001/00-transferClient.sql b/db/changes/233001/00-transferClient.sql new file mode 100644 index 000000000..8a7ce0543 --- /dev/null +++ b/db/changes/233001/00-transferClient.sql @@ -0,0 +1,2 @@ +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) + VALUES ('Ticket','transferClient','WRITE','ALLOW','ROLE','administrative'); \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js new file mode 100644 index 000000000..226f5dedf --- /dev/null +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -0,0 +1,69 @@ +const UserError = require('vn-loopback/util/user-error'); +module.exports = Self => { + Self.remoteMethodCtx('transferClient', { + description: 'Transfering ticket to another client', + accessType: 'WRITE', + accepts: [ + { + arg: 'id', + type: 'number', + required: true, + description: 'the ticket id', + http: {source: 'path'} + }, + { + arg: 'data', + type: 'object', + required: true, + description: 'the client id', + http: {source: 'body'} + }, + ], + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/:id/transferClient`, + verb: 'PATCH' + } + }); + + Self.transferClient = async(ctx, ticketId, params) => { + const models = Self.app.models; + const args = ctx.args; + const myOptions = {}; + try { + const clientId = params.clientId; + const isEditable = await Self.isEditable(ctx, args.id, myOptions); + console.log('es editable?',isEditable) // Revisar + /* if (!isEditable){ + console.log('no es editable!') + throw new UserError(`The sales of this ticket can't be modified`); + } */ + + const ticket = await models.Ticket.findById(ticketId, myOptions); + console.log('ticket',ticket); + if(!ticket) return false; + const nparams = { + clientFk: clientId, + addressFk: ticket.addressFk, + } + + const promise = await ticket.updateAttributes(nparams); + console.log('promise', promise); + if(promise) return true; + } catch (error) { + console.log(error); + } + + /* if (typeof options == 'object') + Object.assign(myOptions, options); + + const ticket = await Self.findById(id, { + fields: ['isDeleted', 'refFk'] + }, myOptions); */ + + return false; + }; +}; \ No newline at end of file diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index f0c85ecc4..b432c9f6b 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -19,6 +19,7 @@ module.exports = function(Self) { require('../methods/ticket/uploadFile')(Self); require('../methods/ticket/addSale')(Self); require('../methods/ticket/transferSales')(Self); + require('../methods/ticket/transferClient')(Self); require('../methods/ticket/recalculateComponents')(Self); require('../methods/ticket/sendSms')(Self); require('../methods/ticket/isLocked')(Self); diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 0fc8488ca..019ae4fa6 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -96,6 +96,14 @@ class Controller extends Section { } transferClient() { + const ticket = this.ticket; + const clientId = ticket.client.id; + console.log('ticketId',ticket.id) + console.log('clientId',clientId); + this.$http.patch(`Tickets/${ticket.id}/transferClient`, {clientId}).then(() =>{ + this.vnApp.showSuccess(this.$t('Data saved!')); + this.reload(); + }) this.$http.get(`Clients/${this.ticket.client.id}`).then(client => { const ticket = this.ticket; From 618989052a481df85338fa54ec297c0ae57d876c Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 20 Jul 2023 15:15:33 +0200 Subject: [PATCH 33/46] refs #5866 fix transferClient and test added --- .../{233001 => 233201}/00-transferClient.sql | 0 .../ticket/specs/transferClient.spec.js | 49 +++++++++++++++ .../back/methods/ticket/transferClient.js | 60 +++++++------------ modules/ticket/front/descriptor-menu/index.js | 18 +----- .../front/descriptor-menu/index.spec.js | 13 ---- 5 files changed, 71 insertions(+), 69 deletions(-) rename db/changes/{233001 => 233201}/00-transferClient.sql (100%) create mode 100644 modules/ticket/back/methods/ticket/specs/transferClient.spec.js diff --git a/db/changes/233001/00-transferClient.sql b/db/changes/233201/00-transferClient.sql similarity index 100% rename from db/changes/233001/00-transferClient.sql rename to db/changes/233201/00-transferClient.sql diff --git a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js new file mode 100644 index 000000000..ed10e5159 --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js @@ -0,0 +1,49 @@ +const models = require('vn-loopback/server/server').models; + +describe('Ticket transferClient()', () => { + const userId = 9; + const activeCtx = { + accessToken: {userId: userId}, + }; + const ctx = {req: activeCtx}; + + it('should throw an error as the ticket is not editable', async() => { + const tx = await models.Ticket.beginTransaction({}); + let error; + + try { + const options = {transaction: tx}; + const ticketId = 4; + const clientId = 1; + await models.Ticket.transferClient(ctx, ticketId, clientId, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toEqual(`The current ticket can't be modified`); + }); + + it('should be assigned a different clientFk', async() => { + const tx = await models.Ticket.beginTransaction({}); + let updatedTicket; + const ticketId = 10; + const clientId = 1; + + try { + const options = {transaction: tx}; + + await models.Ticket.transferClient(ctx, ticketId, clientId, options); + updatedTicket = await models.Ticket.findById(ticketId, {fields: ['clientFk']}, options); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + + expect(updatedTicket.clientFk).toEqual(clientId); + }); +}); diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index 226f5dedf..05ea27fa0 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -12,58 +12,38 @@ module.exports = Self => { http: {source: 'path'} }, { - arg: 'data', - type: 'object', + arg: 'clientId', + type: 'number', required: true, - description: 'the client id', - http: {source: 'body'} }, ], - returns: { - type: 'boolean', - root: true - }, http: { path: `/:id/transferClient`, verb: 'PATCH' } }); - Self.transferClient = async(ctx, ticketId, params) => { + Self.transferClient = async(ctx, ticketId, clientId, options) => { const models = Self.app.models; - const args = ctx.args; const myOptions = {}; - try { - const clientId = params.clientId; - const isEditable = await Self.isEditable(ctx, args.id, myOptions); - console.log('es editable?',isEditable) // Revisar - /* if (!isEditable){ - console.log('no es editable!') - throw new UserError(`The sales of this ticket can't be modified`); - } */ - - const ticket = await models.Ticket.findById(ticketId, myOptions); - console.log('ticket',ticket); - if(!ticket) return false; - const nparams = { - clientFk: clientId, - addressFk: ticket.addressFk, - } - - const promise = await ticket.updateAttributes(nparams); - console.log('promise', promise); - if(promise) return true; - } catch (error) { - console.log(error); - } - - /* if (typeof options == 'object') + if (typeof options == 'object') Object.assign(myOptions, options); - const ticket = await Self.findById(id, { - fields: ['isDeleted', 'refFk'] - }, myOptions); */ + const isEditable = await Self.isEditable(ctx, ticketId, myOptions); - return false; + if (!isEditable) + throw new UserError(`The current ticket can't be modified`); + + const ticket = await models.Ticket.findById( + ticketId, + {fields: ['id', 'shipped', 'clientFk', 'addressFk']}, + myOptions + ); + const client = await models.Client.findById(clientId, {fields: ['id', 'defaultAddressFk']}, myOptions); + + await ticket.updateAttributes({ + clientFk: clientId, + addressFk: client.defaultAddressFk, + }); }; -}; \ No newline at end of file +}; diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 019ae4fa6..62a233891 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -98,26 +98,12 @@ class Controller extends Section { transferClient() { const ticket = this.ticket; const clientId = ticket.client.id; - console.log('ticketId',ticket.id) - console.log('clientId',clientId); - this.$http.patch(`Tickets/${ticket.id}/transferClient`, {clientId}).then(() =>{ - this.vnApp.showSuccess(this.$t('Data saved!')); - this.reload(); - }) - this.$http.get(`Clients/${this.ticket.client.id}`).then(client => { - const ticket = this.ticket; - const params = - { - clientFk: client.data.id, - addressFk: client.data.defaultAddressFk, - }; - - this.$http.patch(`Tickets/${ticket.id}`, params).then(() => { + this.$http.patch(`Tickets/${ticket.id}/transferClient`, {clientId}) + .then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); this.reload(); }); - }); } isTicketEditable() { diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index 914fe486c..1bb270165 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -326,17 +326,4 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { expect(controller.vnApp.showSuccess).toHaveBeenCalled(); }); }); - - describe('transferClient()', () => { - it(`should perform two queries, a get to obtain the clientData and a patch to update the ticket`, () => { - const client = - { - clientFk: 1101, - addressFk: 1, - }; - $httpBackend.expect('GET', `Clients/${ticket.client.id}`).respond(client); - $httpBackend.expect('PATCH', `Tickets/${ticket.id}`).respond(); - controller.transferClient(); - }); - }); }); From eb963ff993f8f142298a6edefc631f2451fbf90b Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 21 Jul 2023 08:28:19 +0200 Subject: [PATCH 34/46] refs #5866 fix(transferClient): correct variable name --- modules/ticket/back/methods/ticket/transferClient.js | 12 ++++++------ modules/ticket/front/descriptor-menu/index.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index 05ea27fa0..04c153bd2 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -12,7 +12,7 @@ module.exports = Self => { http: {source: 'path'} }, { - arg: 'clientId', + arg: 'clientFk', type: 'number', required: true, }, @@ -23,26 +23,26 @@ module.exports = Self => { } }); - Self.transferClient = async(ctx, ticketId, clientId, options) => { + Self.transferClient = async(ctx, id, clientFk, options) => { const models = Self.app.models; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); - const isEditable = await Self.isEditable(ctx, ticketId, myOptions); + const isEditable = await Self.isEditable(ctx, id, myOptions); if (!isEditable) throw new UserError(`The current ticket can't be modified`); const ticket = await models.Ticket.findById( - ticketId, + id, {fields: ['id', 'shipped', 'clientFk', 'addressFk']}, myOptions ); - const client = await models.Client.findById(clientId, {fields: ['id', 'defaultAddressFk']}, myOptions); + const client = await models.Client.findById(clientFk, {fields: ['id', 'defaultAddressFk']}, myOptions); await ticket.updateAttributes({ - clientFk: clientId, + clientFk, addressFk: client.defaultAddressFk, }); }; diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index 62a233891..7bdefcd97 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -97,9 +97,9 @@ class Controller extends Section { transferClient() { const ticket = this.ticket; - const clientId = ticket.client.id; + const clientFk = ticket.client.id; - this.$http.patch(`Tickets/${ticket.id}/transferClient`, {clientId}) + this.$http.patch(`Tickets/${ticket.id}/transferClient`, {clientFk}) .then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); this.reload(); From 203f6a5659f6fdead03c013a43f2b59ec881e5f8 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 21 Jul 2023 12:41:16 +0200 Subject: [PATCH 35/46] 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 36/46] 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 37/46] 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}} Date: Mon, 24 Jul 2023 10:34:44 +0200 Subject: [PATCH 38/46] refs #5929 added ACL and accurate errors --- db/changes/233201/00-updatePrice.sql | 2 ++ loopback/locale/es.json | 6 +++-- .../ticket/back/methods/ticket/isEditable.js | 23 +++++++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 db/changes/233201/00-updatePrice.sql diff --git a/db/changes/233201/00-updatePrice.sql b/db/changes/233201/00-updatePrice.sql new file mode 100644 index 000000000..93888df6e --- /dev/null +++ b/db/changes/233201/00-updatePrice.sql @@ -0,0 +1,2 @@ +INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) + VALUES ('Ticket','*','*','ALLOW','ROLE','buyer'); diff --git a/loopback/locale/es.json b/loopback/locale/es.json index d95e8d8a4..1a200709f 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -307,5 +307,7 @@ "Negative basis of tickets": "Base negativa para los tickets: {{ticketsIds}}", "The company has not informed the supplier account for bank transfers": "La empresa no tiene informado la cuenta de proveedor para transferencias bancarias", "You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado", - "This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado" -} + "This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado", + "You don't have enough privileges.": "You don't have enough privileges.", + "This ticket is locked.": "This ticket is locked." +} \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/isEditable.js b/modules/ticket/back/methods/ticket/isEditable.js index 13bd4d57f..9f7e14dcc 100644 --- a/modules/ticket/back/methods/ticket/isEditable.js +++ b/modules/ticket/back/methods/ticket/isEditable.js @@ -1,3 +1,5 @@ +const UserError = require('vn-loopback/util/user-error'); + module.exports = Self => { Self.remoteMethodCtx('isEditable', { description: 'Check if a ticket is editable', @@ -31,7 +33,7 @@ module.exports = Self => { }, myOptions); const isRoleAdvanced = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*'); - + const canEditWeeklyTicket = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'buyer', 'WRITE'); const alertLevel = state ? state.alertLevel : null; const ticket = await models.Ticket.findById(id, { fields: ['clientFk'], @@ -48,13 +50,26 @@ module.exports = Self => { const isLocked = await models.Ticket.isLocked(id, myOptions); const isWeekly = await models.TicketWeekly.findOne({where: {ticketFk: id}}, myOptions); + console.log('isRoleAdvanced', isRoleAdvanced); + console.log('canEditWeeklyTicket', canEditWeeklyTicket); + console.log('ticket', ticket); + console.log('isLocked', isLocked); + console.log('isWeekly', isWeekly); const alertLevelGreaterThanZero = (alertLevel && alertLevel > 0); const isNormalClient = ticket && ticket.client().type().code == 'normal'; const isEditable = !(alertLevelGreaterThanZero && isNormalClient); + if (!ticket) + throw new UserError(`The ticket doesn't exist.`); - if (ticket && (isEditable || isRoleAdvanced) && !isLocked && !isWeekly) - return true; + if (!isEditable && !isRoleAdvanced) + throw new UserError(`This ticket is not editable.`); - return false; + if (isLocked) + throw new UserError(`This ticket is locked.`); + + if (isWeekly && !canEditWeeklyTicket) + throw new UserError(`You don't have enough privileges.`); + + return true; }; }; From 9978db9d523f4b82670a5ea6b431c8b37630c121 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 25 Jul 2023 11:33:01 +0200 Subject: [PATCH 39/46] refs #5929 WIP test created --- db/changes/233201/00-updatePrice.sql | 2 +- loopback/locale/es.json | 3 +- .../ticket/back/methods/ticket/isEditable.js | 8 +- .../methods/ticket/specs/isEditable.spec.js | 130 +++++------------- 4 files changed, 42 insertions(+), 101 deletions(-) diff --git a/db/changes/233201/00-updatePrice.sql b/db/changes/233201/00-updatePrice.sql index 93888df6e..959943d6f 100644 --- a/db/changes/233201/00-updatePrice.sql +++ b/db/changes/233201/00-updatePrice.sql @@ -1,2 +1,2 @@ INSERT INTO `salix`.`ACL` (`model`,`property`,`accessType`,`permission`,`principalType`,`principalId`) - VALUES ('Ticket','*','*','ALLOW','ROLE','buyer'); + VALUES ('Ticket','canEditWeekly','WRITE','ALLOW','ROLE','buyer'); diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 1a200709f..942cc74c7 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -309,5 +309,6 @@ "You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado", "This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado", "You don't have enough privileges.": "You don't have enough privileges.", - "This ticket is locked.": "This ticket is locked." + "This ticket is locked.": "This ticket is locked.", + "This ticket is not editable.": "This ticket is not editable." } \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/isEditable.js b/modules/ticket/back/methods/ticket/isEditable.js index 9f7e14dcc..967988214 100644 --- a/modules/ticket/back/methods/ticket/isEditable.js +++ b/modules/ticket/back/methods/ticket/isEditable.js @@ -33,7 +33,7 @@ module.exports = Self => { }, myOptions); const isRoleAdvanced = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*'); - const canEditWeeklyTicket = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'buyer', 'WRITE'); + const canEditWeeklyTicket = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'canEditWeekly', 'WRITE'); const alertLevel = state ? state.alertLevel : null; const ticket = await models.Ticket.findById(id, { fields: ['clientFk'], @@ -50,14 +50,10 @@ module.exports = Self => { const isLocked = await models.Ticket.isLocked(id, myOptions); const isWeekly = await models.TicketWeekly.findOne({where: {ticketFk: id}}, myOptions); - console.log('isRoleAdvanced', isRoleAdvanced); - console.log('canEditWeeklyTicket', canEditWeeklyTicket); - console.log('ticket', ticket); - console.log('isLocked', isLocked); - console.log('isWeekly', isWeekly); const alertLevelGreaterThanZero = (alertLevel && alertLevel > 0); const isNormalClient = ticket && ticket.client().type().code == 'normal'; const isEditable = !(alertLevelGreaterThanZero && isNormalClient); + if (!ticket) throw new UserError(`The ticket doesn't exist.`); diff --git a/modules/ticket/back/methods/ticket/specs/isEditable.spec.js b/modules/ticket/back/methods/ticket/specs/isEditable.spec.js index 7337017d6..043445c28 100644 --- a/modules/ticket/back/methods/ticket/specs/isEditable.spec.js +++ b/modules/ticket/back/methods/ticket/specs/isEditable.spec.js @@ -1,143 +1,68 @@ const models = require('vn-loopback/server/server').models; describe('ticket isEditable()', () => { - it('should return false if the given ticket does not exist', async() => { + it('should throw an error as the ticket does not exist', async() => { const tx = await models.Ticket.beginTransaction({}); - let result; - + let error; try { const options = {transaction: tx}; const ctx = { req: {accessToken: {userId: 9}} }; - result = await models.Ticket.isEditable(ctx, 9999, options); - + await models.Ticket.isEditable(ctx, 9999, options); await tx.rollback(); } catch (e) { await tx.rollback(); - throw e; + error = e; } - expect(result).toEqual(false); + expect(error.message).toEqual(`The ticket doesn't exist.`); }); - it(`should return false if the given ticket isn't invoiced but isDeleted`, async() => { + it('should throw an error as this ticket is not editable', async() => { const tx = await models.Ticket.beginTransaction({}); - let result; - - try { - const options = {transaction: tx}; - const deletedTicket = await models.Ticket.findOne({ - where: { - invoiceOut: null, - isDeleted: true - }, - fields: ['id'] - }); - - const ctx = { - req: {accessToken: {userId: 9}} - }; - - result = await models.Ticket.isEditable(ctx, deletedTicket.id, options); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - - expect(result).toEqual(false); - }); - - it('should return true if the given ticket is editable', async() => { - const tx = await models.Ticket.beginTransaction({}); - let result; + let error; try { const options = {transaction: tx}; const ctx = { - req: {accessToken: {userId: 9}} + req: {accessToken: {userId: 1}} }; - result = await models.Ticket.isEditable(ctx, 16, options); - + await models.Ticket.isEditable(ctx, 8, options); await tx.rollback(); } catch (e) { + error = e; await tx.rollback(); - throw e; } - expect(result).toEqual(true); + expect(error.message).toEqual(`This ticket is not editable.`); }); - it('should not be able to edit a deleted or invoiced ticket even for salesAssistant', async() => { + it('should throw an error as this ticket is locked.', async() => { const tx = await models.Ticket.beginTransaction({}); - let result; - - try { - const options = {transaction: tx}; - const ctx = { - req: {accessToken: {userId: 21}} - }; - - result = await models.Ticket.isEditable(ctx, 19, options); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - - expect(result).toEqual(false); - }); - - it('should not be able to edit a deleted or invoiced ticket even for productionBoss', async() => { - const tx = await models.Ticket.beginTransaction({}); - let result; - - try { - const options = {transaction: tx}; - const ctx = { - req: {accessToken: {userId: 50}} - }; - - result = await models.Ticket.isEditable(ctx, 19, options); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - - expect(result).toEqual(false); - }); - - it('should not be able to edit a deleted or invoiced ticket even for salesPerson', async() => { - const tx = await models.Ticket.beginTransaction({}); - let result; - + let error; try { const options = {transaction: tx}; const ctx = { req: {accessToken: {userId: 18}} }; - result = await models.Ticket.isEditable(ctx, 19, options); + await models.Ticket.isEditable(ctx, 19, options); await tx.rollback(); } catch (e) { + error = e; await tx.rollback(); - throw e; } - expect(result).toEqual(false); + expect(error.message).toEqual(`This ticket is locked.`); }); - it('should not be able to edit if is a ticket weekly', async() => { + it('should throw an error as you do not have enough privileges.', async() => { const tx = await models.Ticket.beginTransaction({}); - + let error; try { const options = {transaction: tx}; @@ -147,10 +72,29 @@ describe('ticket isEditable()', () => { expect(result).toEqual(false); + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error.message).toEqual(`You don't have enough privileges.`); + }); + + it('should be able to edit a ticket weekly', async() => { + const tx = await models.Ticket.beginTransaction({}); + let result; + try { + const options = {transaction: tx}; + const ctx = {req: {accessToken: {userId: 35}}}; + + result = await models.Ticket.isEditable(ctx, 15, options); await tx.rollback(); } catch (e) { await tx.rollback(); throw e; } + + expect(result).toEqual(true); }); }); From 543fbf3c0a322e9b586ed3caf8194c1491753235 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 25 Jul 2023 15:35:08 +0200 Subject: [PATCH 40/46] refs #5929 isEditableOrThrow created, tests passed --- loopback/locale/en.json | 6 +- loopback/locale/es.json | 7 +- modules/ticket/back/methods/ticket/addSale.js | 5 +- .../back/methods/ticket/componentUpdate.js | 6 +- .../ticket/back/methods/ticket/isEditable.js | 52 +-------- .../back/methods/ticket/isEditableOrThrow.js | 49 ++++++++ .../back/methods/ticket/priceDifference.js | 7 +- .../methods/ticket/recalculateComponents.js | 6 +- .../ticket/back/methods/ticket/setDeleted.js | 5 +- .../back/methods/ticket/specs/addSale.spec.js | 2 +- .../methods/ticket/specs/isEditable.spec.js | 109 ++++-------------- .../ticket/specs/isEditableOrThrow.spec.js | 100 ++++++++++++++++ .../ticket/specs/priceDifference.spec.js | 3 +- .../specs/recalculateComponents.spec.js | 3 +- .../ticket/specs/transferClient.spec.js | 2 +- .../ticket/specs/transferSales.spec.js | 2 +- .../back/methods/ticket/transferClient.js | 6 +- .../back/methods/ticket/transferSales.js | 6 +- modules/ticket/back/models/ticket-methods.js | 1 + 19 files changed, 203 insertions(+), 174 deletions(-) create mode 100644 modules/ticket/back/methods/ticket/isEditableOrThrow.js create mode 100644 modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 030afbe9e..135bb2be9 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -178,5 +178,9 @@ "The renew period has not been exceeded": "The renew period has not been exceeded", "You can not use the same password": "You can not use the same password", "Valid priorities": "Valid priorities: %d", - "Negative basis of tickets": "Negative basis of tickets: {{ticketsIds}}" + "Negative basis of tickets": "Negative basis of tickets: {{ticketsIds}}", + "You don't have enough privileges.": "You don't have enough privileges.", + "This ticket is locked.": "This ticket is locked.", + "This ticket is not editable.": "This ticket is not editable.", + "The ticket doesn't exist.": "The ticket doesn't exist." } diff --git a/loopback/locale/es.json b/loopback/locale/es.json index 942cc74c7..ac62d62e1 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -308,7 +308,8 @@ "The company has not informed the supplier account for bank transfers": "La empresa no tiene informado la cuenta de proveedor para transferencias bancarias", "You cannot assign/remove an alias that you are not assigned to": "No puede asignar/eliminar un alias que no tenga asignado", "This invoice has a linked vehicle.": "Esta factura tiene un vehiculo vinculado", - "You don't have enough privileges.": "You don't have enough privileges.", - "This ticket is locked.": "This ticket is locked.", - "This ticket is not editable.": "This ticket is not editable." + "You don't have enough privileges.": "No tienes suficientes permisos.", + "This ticket is locked.": "Este ticket está bloqueado.", + "This ticket is not editable.": "Este ticket no es editable.", + "The ticket doesn't exist.": "No existe el ticket." } \ No newline at end of file diff --git a/modules/ticket/back/methods/ticket/addSale.js b/modules/ticket/back/methods/ticket/addSale.js index 2cd02a8a4..9a3e32a7e 100644 --- a/modules/ticket/back/methods/ticket/addSale.js +++ b/modules/ticket/back/methods/ticket/addSale.js @@ -1,4 +1,3 @@ - const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { @@ -47,9 +46,7 @@ module.exports = Self => { } try { - const isEditable = await models.Ticket.isEditable(ctx, id, myOptions); - if (!isEditable) - throw new UserError(`The sales of this ticket can't be modified`); + const isEditable = await models.Ticket.isEditableOrThrow(ctx, id, myOptions); const item = await models.Item.findById(itemId, null, myOptions); const ticket = await models.Ticket.findById(id, { diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 48aee36d4..eadbf65c2 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -1,4 +1,3 @@ -const UserError = require('vn-loopback/util/user-error'); const loggable = require('vn-loopback/util/log'); module.exports = Self => { @@ -116,10 +115,7 @@ module.exports = Self => { const userId = ctx.req.accessToken.userId; const models = Self.app.models; const $t = ctx.req.__; // $translate - const isEditable = await models.Ticket.isEditable(ctx, args.id, myOptions); - - if (!isEditable) - throw new UserError(`The sales of this ticket can't be modified`); + const isEditable = await models.Ticket.isEditableOrThrow(ctx, args.id, myOptions); const editZone = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'editZone', 'WRITE'); if (!editZone) { diff --git a/modules/ticket/back/methods/ticket/isEditable.js b/modules/ticket/back/methods/ticket/isEditable.js index 967988214..f657cd5e3 100644 --- a/modules/ticket/back/methods/ticket/isEditable.js +++ b/modules/ticket/back/methods/ticket/isEditable.js @@ -1,5 +1,3 @@ -const UserError = require('vn-loopback/util/user-error'); - module.exports = Self => { Self.remoteMethodCtx('isEditable', { description: 'Check if a ticket is editable', @@ -22,50 +20,12 @@ module.exports = Self => { }); Self.isEditable = async(ctx, id, options) => { - const models = Self.app.models; - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - const state = await models.TicketState.findOne({ - where: {ticketFk: id} - }, myOptions); - - const isRoleAdvanced = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*'); - const canEditWeeklyTicket = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'canEditWeekly', 'WRITE'); - const alertLevel = state ? state.alertLevel : null; - const ticket = await models.Ticket.findById(id, { - fields: ['clientFk'], - include: [{ - relation: 'client', - scope: { - include: { - relation: 'type' - } - } - }] - }, myOptions); - - const isLocked = await models.Ticket.isLocked(id, myOptions); - const isWeekly = await models.TicketWeekly.findOne({where: {ticketFk: id}}, myOptions); - - const alertLevelGreaterThanZero = (alertLevel && alertLevel > 0); - const isNormalClient = ticket && ticket.client().type().code == 'normal'; - const isEditable = !(alertLevelGreaterThanZero && isNormalClient); - - if (!ticket) - throw new UserError(`The ticket doesn't exist.`); - - if (!isEditable && !isRoleAdvanced) - throw new UserError(`This ticket is not editable.`); - - if (isLocked) - throw new UserError(`This ticket is locked.`); - - if (isWeekly && !canEditWeeklyTicket) - throw new UserError(`You don't have enough privileges.`); - + try { + await Self.isEditableOrThrow(ctx, id, options); + } catch (e) { + if (e.name === 'ForbiddenError') return false; + throw e; + } return true; }; }; diff --git a/modules/ticket/back/methods/ticket/isEditableOrThrow.js b/modules/ticket/back/methods/ticket/isEditableOrThrow.js new file mode 100644 index 000000000..6a8bafa2c --- /dev/null +++ b/modules/ticket/back/methods/ticket/isEditableOrThrow.js @@ -0,0 +1,49 @@ +const ForbiddenError = require('vn-loopback/util/forbiddenError'); + +module.exports = Self => { + Self.isEditableOrThrow = async(ctx, id, options) => { + const models = Self.app.models; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const state = await models.TicketState.findOne({ + where: {ticketFk: id} + }, myOptions); + + const isRoleAdvanced = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'isRoleAdvanced', '*'); + const canEditWeeklyTicket = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'canEditWeekly', 'WRITE'); + const alertLevel = state ? state.alertLevel : null; + const ticket = await models.Ticket.findById(id, { + fields: ['clientFk'], + include: [{ + relation: 'client', + scope: { + include: { + relation: 'type' + } + } + }] + }, myOptions); + + const isLocked = await models.Ticket.isLocked(id, myOptions); + const isWeekly = await models.TicketWeekly.findOne({where: {ticketFk: id}}, myOptions); + + const alertLevelGreaterThanZero = (alertLevel && alertLevel > 0); + const isNormalClient = ticket && ticket.client().type().code == 'normal'; + const isEditable = !(alertLevelGreaterThanZero && isNormalClient); + + if (!ticket) + throw new ForbiddenError(`The ticket doesn't exist.`); + + if (!isEditable && !isRoleAdvanced) + throw new ForbiddenError(`This ticket is not editable.`); + + if (isLocked) + throw new ForbiddenError(`This ticket is locked.`); + + if (isWeekly && !canEditWeeklyTicket) + throw new ForbiddenError(`You don't have enough privileges.`); + }; +}; diff --git a/modules/ticket/back/methods/ticket/priceDifference.js b/modules/ticket/back/methods/ticket/priceDifference.js index 42a71f1c8..754646b03 100644 --- a/modules/ticket/back/methods/ticket/priceDifference.js +++ b/modules/ticket/back/methods/ticket/priceDifference.js @@ -1,5 +1,3 @@ -const UserError = require('vn-loopback/util/user-error'); - module.exports = Self => { Self.remoteMethodCtx('priceDifference', { description: 'Returns sales with price difference if the ticket is editable', @@ -72,10 +70,7 @@ module.exports = Self => { } try { - const isEditable = await Self.isEditable(ctx, args.id, myOptions); - - if (!isEditable) - throw new UserError(`The sales of this ticket can't be modified`); + const isEditable = await Self.isEditableOrThrow(ctx, args.id, myOptions); const editZone = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'editZone', 'WRITE'); if (!editZone) { diff --git a/modules/ticket/back/methods/ticket/recalculateComponents.js b/modules/ticket/back/methods/ticket/recalculateComponents.js index eb9c8a72e..78c44bab3 100644 --- a/modules/ticket/back/methods/ticket/recalculateComponents.js +++ b/modules/ticket/back/methods/ticket/recalculateComponents.js @@ -1,4 +1,3 @@ -const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('recalculateComponents', { description: 'Calculates the price of a sale and its components', @@ -33,10 +32,7 @@ module.exports = Self => { } try { - const isEditable = await Self.isEditable(ctx, id, myOptions); - - if (!isEditable) - throw new UserError(`The current ticket can't be modified`); + const isEditable = await Self.isEditableOrThrow(ctx, id, myOptions); const recalculation = await Self.rawSql('CALL vn.ticket_recalcComponents(?, NULL)', [id], myOptions); diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index 878cce056..6485f198e 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -39,10 +39,7 @@ module.exports = Self => { const ticketToDelete = await models.Ticket.findById(id, {fields: ['isDeleted']}, myOptions); if (ticketToDelete.isDeleted) return false; - const isEditable = await Self.isEditable(ctx, id, myOptions); - - if (!isEditable) - throw new UserError(`The sales of this ticket can't be modified`); + const isEditable = await Self.isEditableOrThrow(ctx, id, myOptions); // Check if ticket has refunds const ticketRefunds = await models.TicketRefund.find({ diff --git a/modules/ticket/back/methods/ticket/specs/addSale.spec.js b/modules/ticket/back/methods/ticket/specs/addSale.spec.js index 2e568716a..b1ecb133b 100644 --- a/modules/ticket/back/methods/ticket/specs/addSale.spec.js +++ b/modules/ticket/back/methods/ticket/specs/addSale.spec.js @@ -97,6 +97,6 @@ describe('ticket addSale()', () => { error = e; } - expect(error.message).toEqual(`The sales of this ticket can't be modified`); + expect(error.message).toEqual(`This ticket is locked.`); }); }); diff --git a/modules/ticket/back/methods/ticket/specs/isEditable.spec.js b/modules/ticket/back/methods/ticket/specs/isEditable.spec.js index 043445c28..301745ed3 100644 --- a/modules/ticket/back/methods/ticket/specs/isEditable.spec.js +++ b/modules/ticket/back/methods/ticket/specs/isEditable.spec.js @@ -1,100 +1,37 @@ const models = require('vn-loopback/server/server').models; -describe('ticket isEditable()', () => { - it('should throw an error as the ticket does not exist', async() => { - const tx = await models.Ticket.beginTransaction({}); - let error; - try { - const options = {transaction: tx}; - const ctx = { - req: {accessToken: {userId: 9}} - }; - - await models.Ticket.isEditable(ctx, 9999, options); - await tx.rollback(); - } catch (e) { - await tx.rollback(); - error = e; - } - - expect(error.message).toEqual(`The ticket doesn't exist.`); - }); - - it('should throw an error as this ticket is not editable', async() => { - const tx = await models.Ticket.beginTransaction({}); - let error; - - try { - const options = {transaction: tx}; - const ctx = { - req: {accessToken: {userId: 1}} - }; - - await models.Ticket.isEditable(ctx, 8, options); - await tx.rollback(); - } catch (e) { - error = e; - await tx.rollback(); - } - - expect(error.message).toEqual(`This ticket is not editable.`); - }); - - it('should throw an error as this ticket is locked.', async() => { - const tx = await models.Ticket.beginTransaction({}); - let error; - try { - const options = {transaction: tx}; - const ctx = { - req: {accessToken: {userId: 18}} - }; - - await models.Ticket.isEditable(ctx, 19, options); - - await tx.rollback(); - } catch (e) { - error = e; - await tx.rollback(); - } - - expect(error.message).toEqual(`This ticket is locked.`); - }); - - it('should throw an error as you do not have enough privileges.', async() => { - const tx = await models.Ticket.beginTransaction({}); - let error; - try { - const options = {transaction: tx}; - - const ctx = {req: {accessToken: {userId: 1}}}; - - const result = await models.Ticket.isEditable(ctx, 15, options); - - expect(result).toEqual(false); - - await tx.rollback(); - } catch (e) { - error = e; - await tx.rollback(); - } - - expect(error.message).toEqual(`You don't have enough privileges.`); - }); - - it('should be able to edit a ticket weekly', async() => { +describe('isEditable()', () => { + it('should return false if It is able to edit', async() => { const tx = await models.Ticket.beginTransaction({}); let result; + try { const options = {transaction: tx}; const ctx = {req: {accessToken: {userId: 35}}}; - - result = await models.Ticket.isEditable(ctx, 15, options); + result = await models.Ticket.isEditable(ctx, 5, options); await tx.rollback(); - } catch (e) { + } catch (error) { await tx.rollback(); throw e; } - expect(result).toEqual(true); + expect(result).toBeFalse(); + }); + + it('should return true if It is able to edit', async() => { + const tx = await models.Ticket.beginTransaction({}); + let result; + + try { + const options = {transaction: tx}; + const ctx = {req: {accessToken: {userId: 35}}}; + result = await models.Ticket.isEditable(ctx, 15, options); + await tx.rollback(); + } catch (error) { + await tx.rollback(); + throw e; + } + + expect(result).toBeTrue(); }); }); diff --git a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js new file mode 100644 index 000000000..b65ed64a1 --- /dev/null +++ b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js @@ -0,0 +1,100 @@ +const models = require('vn-loopback/server/server').models; + +describe('ticket isEditableOrThrow()', () => { + it('should throw an error as the ticket does not exist', async() => { + const tx = await models.Ticket.beginTransaction({}); + let error; + try { + const options = {transaction: tx}; + const ctx = { + req: {accessToken: {userId: 9}} + }; + + await models.Ticket.isEditableOrThrow(ctx, 9999, options); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + error = e; + } + + expect(error.message).toEqual(`The ticket doesn't exist.`); + }); + + it('should throw an error as this ticket is not editable', async() => { + const tx = await models.Ticket.beginTransaction({}); + let error; + + try { + const options = {transaction: tx}; + const ctx = { + req: {accessToken: {userId: 1}} + }; + + await models.Ticket.isEditableOrThrow(ctx, 8, options); + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error.message).toEqual(`This ticket is not editable.`); + }); + + it('should throw an error as this ticket is locked.', async() => { + const tx = await models.Ticket.beginTransaction({}); + let error; + try { + const options = {transaction: tx}; + const ctx = { + req: {accessToken: {userId: 18}} + }; + + await models.Ticket.isEditableOrThrow(ctx, 19, options); + + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error.message).toEqual(`This ticket is locked.`); + }); + + it('should throw an error as you do not have enough privileges.', async() => { + const tx = await models.Ticket.beginTransaction({}); + let error; + try { + const options = {transaction: tx}; + + const ctx = {req: {accessToken: {userId: 1}}}; + + const result = await models.Ticket.isEditableOrThrow(ctx, 15, options); + + expect(result).toEqual(false); + + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error.message).toEqual(`You don't have enough privileges.`); + }); + + it('should return undefined if It can be edited', async() => { + const tx = await models.Ticket.beginTransaction({}); + let result; + try { + const options = {transaction: tx}; + const ctx = {req: {accessToken: {userId: 35}}}; + + result = await models.Ticket.isEditableOrThrow(ctx, 15, options); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + + expect(result).toBeUndefined(); + }); +}); diff --git a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js index cc54353ef..d01f0c1bb 100644 --- a/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js +++ b/modules/ticket/back/methods/ticket/specs/priceDifference.spec.js @@ -1,5 +1,6 @@ const models = require('vn-loopback/server/server').models; const UserError = require('vn-loopback/util/user-error'); +const ForbiddenError = require('vn-loopback/util/forbiddenError'); describe('sale priceDifference()', () => { it('should return ticket price differences', async() => { @@ -59,7 +60,7 @@ describe('sale priceDifference()', () => { await tx.rollback(); } - expect(error).toEqual(new UserError(`The sales of this ticket can't be modified`)); + expect(error).toEqual(new ForbiddenError(`This ticket is not editable.`)); }); it('should return ticket movable', async() => { diff --git a/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js b/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js index ed10d114f..383c2c6d5 100644 --- a/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js +++ b/modules/ticket/back/methods/ticket/specs/recalculateComponents.spec.js @@ -1,4 +1,5 @@ const models = require('vn-loopback/server/server').models; +const ForbiddenError = require('vn-loopback/util/forbiddenError'); describe('ticket recalculateComponents()', () => { const ticketId = 11; @@ -38,6 +39,6 @@ describe('ticket recalculateComponents()', () => { error = e; } - expect(error).toEqual(new Error(`The current ticket can't be modified`)); + expect(error).toEqual(new ForbiddenError(`This ticket is locked.`)); }); }); diff --git a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js index ed10e5159..c09c20083 100644 --- a/modules/ticket/back/methods/ticket/specs/transferClient.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferClient.spec.js @@ -23,7 +23,7 @@ describe('Ticket transferClient()', () => { error = e; } - expect(error.message).toEqual(`The current ticket can't be modified`); + expect(error.message).toEqual(`This ticket is locked.`); }); it('should be assigned a different clientFk', async() => { diff --git a/modules/ticket/back/methods/ticket/specs/transferSales.spec.js b/modules/ticket/back/methods/ticket/specs/transferSales.spec.js index 562688917..ef92e88c0 100644 --- a/modules/ticket/back/methods/ticket/specs/transferSales.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferSales.spec.js @@ -33,7 +33,7 @@ describe('sale transferSales()', () => { error = e; } - expect(error.message).toEqual(`The sales of this ticket can't be modified`); + expect(error.message).toEqual(`This ticket is not editable.`); }); it('should throw an error if the receiving ticket is not editable', async() => { diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index 04c153bd2..c87ad4881 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -1,4 +1,3 @@ -const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('transferClient', { description: 'Transfering ticket to another client', @@ -29,10 +28,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isEditable = await Self.isEditable(ctx, id, myOptions); - - if (!isEditable) - throw new UserError(`The current ticket can't be modified`); + const isEditable = await Self.isEditableOrThrow(ctx, id, myOptions); const ticket = await models.Ticket.findById( id, diff --git a/modules/ticket/back/methods/ticket/transferSales.js b/modules/ticket/back/methods/ticket/transferSales.js index 0eee50d5f..bd99920db 100644 --- a/modules/ticket/back/methods/ticket/transferSales.js +++ b/modules/ticket/back/methods/ticket/transferSales.js @@ -1,4 +1,4 @@ -let UserError = require('vn-loopback/util/user-error'); +const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('transferSales', { @@ -48,9 +48,7 @@ module.exports = Self => { } try { - const isEditable = await models.Ticket.isEditable(ctx, id, myOptions); - if (!isEditable) - throw new UserError(`The sales of this ticket can't be modified`); + const isEditable = await models.Ticket.isEditableOrThrow(ctx, id, myOptions); if (ticketId) { const isReceiverEditable = await models.Ticket.isEditable(ctx, ticketId, myOptions); diff --git a/modules/ticket/back/models/ticket-methods.js b/modules/ticket/back/models/ticket-methods.js index b432c9f6b..c37337253 100644 --- a/modules/ticket/back/models/ticket-methods.js +++ b/modules/ticket/back/models/ticket-methods.js @@ -6,6 +6,7 @@ module.exports = function(Self) { require('../methods/ticket/componentUpdate')(Self); require('../methods/ticket/new')(Self); require('../methods/ticket/isEditable')(Self); + require('../methods/ticket/isEditableOrThrow')(Self); require('../methods/ticket/setDeleted')(Self); require('../methods/ticket/restore')(Self); require('../methods/ticket/getSales')(Self); From a0fee6ad50add6065c60c701ab9abcbf1adfc611 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 26 Jul 2023 09:20:54 +0200 Subject: [PATCH 41/46] refs #5929 removed useless vars --- modules/ticket/back/methods/ticket/addSale.js | 2 +- modules/ticket/back/methods/ticket/componentUpdate.js | 2 +- modules/ticket/back/methods/ticket/priceDifference.js | 2 +- modules/ticket/back/methods/ticket/recalculateComponents.js | 2 +- modules/ticket/back/methods/ticket/setDeleted.js | 2 +- .../back/methods/ticket/specs/isEditableOrThrow.spec.js | 6 +----- modules/ticket/back/methods/ticket/transferClient.js | 2 +- modules/ticket/back/methods/ticket/transferSales.js | 2 +- 8 files changed, 8 insertions(+), 12 deletions(-) diff --git a/modules/ticket/back/methods/ticket/addSale.js b/modules/ticket/back/methods/ticket/addSale.js index 9a3e32a7e..cbf884273 100644 --- a/modules/ticket/back/methods/ticket/addSale.js +++ b/modules/ticket/back/methods/ticket/addSale.js @@ -46,7 +46,7 @@ module.exports = Self => { } try { - const isEditable = await models.Ticket.isEditableOrThrow(ctx, id, myOptions); + await models.Ticket.isEditableOrThrow(ctx, id, myOptions); const item = await models.Item.findById(itemId, null, myOptions); const ticket = await models.Ticket.findById(id, { diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index eadbf65c2..b5ff50d59 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -115,7 +115,7 @@ module.exports = Self => { const userId = ctx.req.accessToken.userId; const models = Self.app.models; const $t = ctx.req.__; // $translate - const isEditable = await models.Ticket.isEditableOrThrow(ctx, args.id, myOptions); + await models.Ticket.isEditableOrThrow(ctx, args.id, myOptions); const editZone = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'editZone', 'WRITE'); if (!editZone) { diff --git a/modules/ticket/back/methods/ticket/priceDifference.js b/modules/ticket/back/methods/ticket/priceDifference.js index 754646b03..495e9e1aa 100644 --- a/modules/ticket/back/methods/ticket/priceDifference.js +++ b/modules/ticket/back/methods/ticket/priceDifference.js @@ -70,7 +70,7 @@ module.exports = Self => { } try { - const isEditable = await Self.isEditableOrThrow(ctx, args.id, myOptions); + await Self.isEditableOrThrow(ctx, args.id, myOptions); const editZone = await models.ACL.checkAccessAcl(ctx, 'Ticket', 'editZone', 'WRITE'); if (!editZone) { diff --git a/modules/ticket/back/methods/ticket/recalculateComponents.js b/modules/ticket/back/methods/ticket/recalculateComponents.js index 78c44bab3..bdf74f8b6 100644 --- a/modules/ticket/back/methods/ticket/recalculateComponents.js +++ b/modules/ticket/back/methods/ticket/recalculateComponents.js @@ -32,7 +32,7 @@ module.exports = Self => { } try { - const isEditable = await Self.isEditableOrThrow(ctx, id, myOptions); + await Self.isEditableOrThrow(ctx, id, myOptions); const recalculation = await Self.rawSql('CALL vn.ticket_recalcComponents(?, NULL)', [id], myOptions); diff --git a/modules/ticket/back/methods/ticket/setDeleted.js b/modules/ticket/back/methods/ticket/setDeleted.js index 6485f198e..2f8c402da 100644 --- a/modules/ticket/back/methods/ticket/setDeleted.js +++ b/modules/ticket/back/methods/ticket/setDeleted.js @@ -39,7 +39,7 @@ module.exports = Self => { const ticketToDelete = await models.Ticket.findById(id, {fields: ['isDeleted']}, myOptions); if (ticketToDelete.isDeleted) return false; - const isEditable = await Self.isEditableOrThrow(ctx, id, myOptions); + await Self.isEditableOrThrow(ctx, id, myOptions); // Check if ticket has refunds const ticketRefunds = await models.TicketRefund.find({ diff --git a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js index b65ed64a1..6c89bac26 100644 --- a/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js +++ b/modules/ticket/back/methods/ticket/specs/isEditableOrThrow.spec.js @@ -65,13 +65,9 @@ describe('ticket isEditableOrThrow()', () => { let error; try { const options = {transaction: tx}; - const ctx = {req: {accessToken: {userId: 1}}}; - const result = await models.Ticket.isEditableOrThrow(ctx, 15, options); - - expect(result).toEqual(false); - + await models.Ticket.isEditableOrThrow(ctx, 15, options); await tx.rollback(); } catch (e) { error = e; diff --git a/modules/ticket/back/methods/ticket/transferClient.js b/modules/ticket/back/methods/ticket/transferClient.js index c87ad4881..60e70d710 100644 --- a/modules/ticket/back/methods/ticket/transferClient.js +++ b/modules/ticket/back/methods/ticket/transferClient.js @@ -28,7 +28,7 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const isEditable = await Self.isEditableOrThrow(ctx, id, myOptions); + await Self.isEditableOrThrow(ctx, id, myOptions); const ticket = await models.Ticket.findById( id, diff --git a/modules/ticket/back/methods/ticket/transferSales.js b/modules/ticket/back/methods/ticket/transferSales.js index bd99920db..a48c5683c 100644 --- a/modules/ticket/back/methods/ticket/transferSales.js +++ b/modules/ticket/back/methods/ticket/transferSales.js @@ -48,7 +48,7 @@ module.exports = Self => { } try { - const isEditable = await models.Ticket.isEditableOrThrow(ctx, id, myOptions); + await models.Ticket.isEditableOrThrow(ctx, id, myOptions); if (ticketId) { const isReceiverEditable = await models.Ticket.isEditable(ctx, ticketId, myOptions); From 65b9cadd9e6ed72d263c8a23e1efb0878069b4ca Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 27 Jul 2023 12:51:14 +0200 Subject: [PATCH 42/46] refs #5804 refactor: sustituido activeBuyers por getItemTypeWorker --- .../item/back/methods/item/activeBuyers.js | 44 ------------------- .../methods/item/specs/activeBuyers.spec.js | 24 ---------- modules/item/back/models/item.js | 1 - .../front/request-search-panel/index.html | 14 +++--- modules/item/front/search-panel/index.html | 12 ++--- .../ticket-request/getItemTypeWorker.js | 33 ++++++++------ .../specs/getItemTypeWorkers.spec.js | 6 +-- 7 files changed, 34 insertions(+), 100 deletions(-) delete mode 100644 modules/item/back/methods/item/activeBuyers.js delete mode 100644 modules/item/back/methods/item/specs/activeBuyers.spec.js diff --git a/modules/item/back/methods/item/activeBuyers.js b/modules/item/back/methods/item/activeBuyers.js deleted file mode 100644 index e16ff877b..000000000 --- a/modules/item/back/methods/item/activeBuyers.js +++ /dev/null @@ -1,44 +0,0 @@ -const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; -const mergeFilters = require('vn-loopback/util/filter').mergeFilters; - -module.exports = Self => { - Self.remoteMethod('activeBuyers', { - description: 'Returns a list of buyers for the given item type', - accepts: [{ - arg: 'filter', - type: 'object', - description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string` - }], - returns: { - type: ['object'], - root: true - }, - http: { - path: `/activeBuyers`, - verb: 'GET' - } - }); - - Self.activeBuyers = async(filter, options) => { - const conn = Self.dataSource.connector; - const where = {isActive: true}; - const myOptions = {}; - - if (typeof options == 'object') - Object.assign(myOptions, options); - - filter = mergeFilters(filter, {where}); - - let stmt = new ParameterizedSQL( - `SELECT DISTINCT w.id workerFk, w.firstName, w.lastName, u.name, u.nickname - FROM worker w - JOIN itemType it ON it.workerFk = w.id - JOIN account.user u ON u.id = w.id - JOIN item i ON i.typeFk = it.id`, - null, myOptions); - - stmt.merge(conn.makeSuffix(filter)); - - return conn.executeStmt(stmt); - }; -}; diff --git a/modules/item/back/methods/item/specs/activeBuyers.spec.js b/modules/item/back/methods/item/specs/activeBuyers.spec.js deleted file mode 100644 index 5bf36756f..000000000 --- a/modules/item/back/methods/item/specs/activeBuyers.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -const models = require('vn-loopback/server/server').models; - -describe('Worker activeBuyers', () => { - it('should return the buyers in itemType as result', async() => { - const tx = await models.Item.beginTransaction({}); - - try { - const options = {transaction: tx}; - const filter = {}; - const result = await models.Item.activeBuyers(filter, options); - const firstWorker = result[0]; - const secondWorker = result[1]; - - expect(result.length).toEqual(2); - expect(firstWorker.nickname).toEqual('logisticBossNick'); - expect(secondWorker.nickname).toEqual('buyerNick'); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); diff --git a/modules/item/back/models/item.js b/modules/item/back/models/item.js index b8baa97ea..61c5c2588 100644 --- a/modules/item/back/models/item.js +++ b/modules/item/back/models/item.js @@ -14,7 +14,6 @@ module.exports = Self => { require('../methods/item/getWasteByWorker')(Self); require('../methods/item/getWasteByItem')(Self); require('../methods/item/createIntrastat')(Self); - require('../methods/item/activeBuyers')(Self); require('../methods/item/buyerWasteEmail')(Self); require('../methods/item/labelPdf')(Self); diff --git a/modules/item/front/request-search-panel/index.html b/modules/item/front/request-search-panel/index.html index a76684776..9d35fbca4 100644 --- a/modules/item/front/request-search-panel/index.html +++ b/modules/item/front/request-search-panel/index.html @@ -1,7 +1,7 @@
@@ -26,7 +26,7 @@ search-function="{firstName: $search}" value-field="id" where="{role: {inq: ['logistic', 'buyer']}}" - label="Atender"> + label="Buyer"> {{nickname}} @@ -57,7 +57,7 @@ {{firstName}} {{lastName}} - +
- - - - { - Self.remoteMethodCtx('getItemTypeWorker', { + Self.remoteMethod('getItemTypeWorker', { description: 'Returns the workers that appear in itemType', accessType: 'READ', accepts: [{ @@ -20,10 +22,9 @@ module.exports = Self => { } }); - Self.getItemTypeWorker = async(ctx, filter, options) => { + Self.getItemTypeWorker = async(filter, options) => { const myOptions = {}; const conn = Self.dataSource.connector; - let tx; if (typeof options == 'object') Object.assign(myOptions, options); @@ -33,25 +34,29 @@ module.exports = Self => { FROM itemType it JOIN worker w ON w.id = it.workerFk JOIN account.user u ON u.id = w.id`; + const stmt = new ParameterizedSQL(query); - let stmt = new ParameterizedSQL(query); - - if (filter.where) { - const value = filter.where.firstName; - const myFilter = { - where: {or: [ + filter.where = buildFilter(filter.where, (param, value) => { + switch (param) { + case 'firstName': + return {or: [ {'w.firstName': {like: `%${value}%`}}, {'w.lastName': {like: `%${value}%`}}, {'u.name': {like: `%${value}%`}}, {'u.nickname': {like: `%${value}%`}} - ]} - }; + ]}; + case 'id': + return {'w.id': value}; + } + }); - stmt.merge(conn.makeSuffix(myFilter)); - } + let myFilter = { + where: {'u.active': true} + }; - if (tx) await tx.commit(); + myFilter = mergeFilters(myFilter, filter); + stmt.merge(conn.makeSuffix(myFilter)); return conn.executeStmt(stmt); }; }; diff --git a/modules/ticket/back/methods/ticket-request/specs/getItemTypeWorkers.spec.js b/modules/ticket/back/methods/ticket-request/specs/getItemTypeWorkers.spec.js index ae5c508b6..c57451c26 100644 --- a/modules/ticket/back/methods/ticket-request/specs/getItemTypeWorkers.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/getItemTypeWorkers.spec.js @@ -1,12 +1,10 @@ const models = require('vn-loopback/server/server').models; describe('ticket-request getItemTypeWorker()', () => { - const ctx = {req: {accessToken: {userId: 18}}}; - it('should return the buyer as result', async() => { const filter = {where: {firstName: 'buyer'}}; - const result = await models.TicketRequest.getItemTypeWorker(ctx, filter); + const result = await models.TicketRequest.getItemTypeWorker(filter); expect(result.length).toEqual(1); }); @@ -14,7 +12,7 @@ describe('ticket-request getItemTypeWorker()', () => { it('should return the workers at itemType as result', async() => { const filter = {}; - const result = await models.TicketRequest.getItemTypeWorker(ctx, filter); + const result = await models.TicketRequest.getItemTypeWorker(filter); expect(result.length).toBeGreaterThan(1); }); From 1d4ce2c70342e01371143b317f80d5c17214c474 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 28 Jul 2023 12:24:24 +0200 Subject: [PATCH 43/46] refs #5804 fix: delete transaction --- .../ticket/back/methods/ticket-request/getItemTypeWorker.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js b/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js index f160cfaac..9ea859f7c 100644 --- a/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js +++ b/modules/ticket/back/methods/ticket-request/getItemTypeWorker.js @@ -22,13 +22,9 @@ module.exports = Self => { } }); - Self.getItemTypeWorker = async(filter, options) => { - const myOptions = {}; + Self.getItemTypeWorker = async filter => { const conn = Self.dataSource.connector; - if (typeof options == 'object') - Object.assign(myOptions, options); - const query = `SELECT DISTINCT u.id, u.nickname FROM itemType it From 81dc163819fb45e288d004378f7f916cb7e7b5d1 Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 28 Jul 2023 14:40:03 +0200 Subject: [PATCH 44/46] ya no muestra error en el front --- modules/worker/front/card/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/front/card/index.js b/modules/worker/front/card/index.js index 0bf9ae5c4..b8b533c5d 100644 --- a/modules/worker/front/card/index.js +++ b/modules/worker/front/card/index.js @@ -36,7 +36,7 @@ class Controller extends ModuleCard { this.$http.get(`Workers/${this.$params.id}`, {filter}) .then(res => this.worker = res.data), this.$http.get(`Workers/${this.$params.id}/activeContract`) - .then(res => this.hasWorkCenter = res.data.workCenterFk) + .then(res => this.hasWorkCenter = res.data?.workCenterFk) ]); } } From 3d200ed64b8bdbf12a6da6f1d977bacfc3e9e5ab Mon Sep 17 00:00:00 2001 From: alexm Date: Wed, 2 Aug 2023 13:59:56 +0200 Subject: [PATCH 45/46] changeLog correct version --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de66fe928..2f935f786 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [2330.01] - 2023-07-27 +## [2332.01] - 2023-08-09 ### Added From ca34065e899257be75c14ede0b25b7c260529c92 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 3 Aug 2023 09:17:32 +0200 Subject: [PATCH 46/46] refs #6093 deploy(2332): dev to test --- CHANGELOG.md | 4 ++++ db/changes/{232601 => 233201}/00-acl_viaexpressConfig.sql | 0 db/changes/{232601 => 233201}/00-viaexpress.sql | 0 3 files changed, 4 insertions(+) rename db/changes/{232601 => 233201}/00-acl_viaexpressConfig.sql (100%) rename db/changes/{232601 => 233201}/00-viaexpress.sql (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f935f786..73520a6db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [2332.01] - 2023-08-09 ### Added +- (Trabajadores -> Gestión documental) Soporte para Docuware +- (General -> Agencia) Soporte para Viaexpress ### Changed +- (General -> Tickets) Devuelve el motivo por el cual no es editable +- (Desplegables -> Trabajadores) Mejorados ### Fixed diff --git a/db/changes/232601/00-acl_viaexpressConfig.sql b/db/changes/233201/00-acl_viaexpressConfig.sql similarity index 100% rename from db/changes/232601/00-acl_viaexpressConfig.sql rename to db/changes/233201/00-acl_viaexpressConfig.sql diff --git a/db/changes/232601/00-viaexpress.sql b/db/changes/233201/00-viaexpress.sql similarity index 100% rename from db/changes/232601/00-viaexpress.sql rename to db/changes/233201/00-viaexpress.sql