From b71b959b495d0a5e5158c33a4a2d78972d5167ea Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Wed, 17 Feb 2021 11:01:50 +0100 Subject: [PATCH 01/19] Formated sql and tests passed --- .../back/methods/travel/getAverageDays.js | 43 +++++++++++++++---- modules/travel/front/create/index.js | 6 +-- modules/travel/front/create/index.spec.js | 17 ++++---- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/modules/travel/back/methods/travel/getAverageDays.js b/modules/travel/back/methods/travel/getAverageDays.js index bcc98dbe2..9a326652d 100644 --- a/modules/travel/back/methods/travel/getAverageDays.js +++ b/modules/travel/back/methods/travel/getAverageDays.js @@ -1,3 +1,4 @@ +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; module.exports = Self => { Self.remoteMethod('getAverageDays', { description: 'Returns the average days duration and the two warehouses of the travel.', @@ -18,15 +19,41 @@ module.exports = Self => { }); Self.getAverageDays = async agencyModeFk => { - const query = ` - SELECT t.id, t.warehouseInFk, t.warehouseOutFk, - (SELECT ROUND(AVG(DATEDIFF(t.landed, t.shipped ))) - FROM travel t - WHERE t.agencyFk = ? LIMIT 50) AS dayDuration - FROM travel t - WHERE t.agencyFk = ? ORDER BY t.id DESC LIMIT 1;`; + const conn = Self.dataSource.connector; + let stmts = []; + let avgDays = {}; - const [avgDays] = await Self.rawSql(query, [agencyModeFk, agencyModeFk]); + stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.travel'); + + stmt = new ParameterizedSQL(` + CREATE TEMPORARY TABLE tmp.travel ( + SELECT t.id, + t.warehouseInFk, + t.warehouseOutFk, + t.landed, + t.shipped,+ + t.agencyFk + FROM travel t + WHERE t.agencyFk = ? LIMIT 50)`, [agencyModeFk]); + stmts.push(stmt); + console.log(stmts); + + stmt = new ParameterizedSQL(`SELECT t.id, t.warehouseInFk, t.warehouseOutFk, + (SELECT ROUND(AVG(DATEDIFF(t.landed, t.shipped ))) + FROM tmp.travel t + WHERE t.agencyFk ORDER BY id DESC LIMIT 50) AS dayDuration + FROM tmp.travel t + WHERE t.agencyFk ORDER BY t.id DESC LIMIT 1`); + let resultAvgDays = stmts.push(stmt) - 1; + stmts.push( + `DROP TEMPORARY TABLE + tmp.travel`); + + let sql = ParameterizedSQL.join(stmts, ';'); + let result = await conn.executeStmt(sql); + + avgDays = result[resultAvgDays]; + console.log(avgDays); return avgDays; }; }; diff --git a/modules/travel/front/create/index.js b/modules/travel/front/create/index.js index cf0b2f382..c76728e59 100644 --- a/modules/travel/front/create/index.js +++ b/modules/travel/front/create/index.js @@ -23,12 +23,12 @@ class Controller extends Section { }; this.$http.get(query, {params}).then(res => { const landed = new Date(value); - const futureDate = landed.getDate() + res.data.dayDuration; + const futureDate = landed.getDate() + res.data[0].dayDuration; landed.setDate(futureDate); this.travel.landed = landed; - this.travel.warehouseInFk = res.data.warehouseInFk; - this.travel.warehouseOutFk = res.data.warehouseOutFk; + this.travel.warehouseInFk = res.data[0].warehouseInFk; + this.travel.warehouseOutFk = res.data[0].warehouseOutFk; }); } diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index b59530604..dcb17d494 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -54,20 +54,21 @@ describe('Travel Component vnTravelCreate', () => { it(`should fill the fields when it's selected a date and agency.`, () => { controller.travel = {agencyModeFk: 1}; const tomorrow = new Date(); - tomorrow.setDate(tomorrow.getDate() + 1); - const expectedResponse = { - dayDuration: 2, - warehouseInFk: 1, - warehouseOutFk: 2 - }; + tomorrow.setDate(tomorrow.getDate() + 9); + const expectedResponse = [{ + id: 8, + dayDuration: 9, + warehouseInFk: 5, + warehouseOutFk: 1 + }]; const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`; $httpBackend.expectGET(query).respond(expectedResponse); controller.onShippedChange(tomorrow); $httpBackend.flush(); - expect(controller.travel.warehouseInFk).toEqual(expectedResponse.warehouseInFk); - expect(controller.travel.warehouseOutFk).toEqual(expectedResponse.warehouseOutFk); + expect(controller.travel.warehouseInFk).toEqual(expectedResponse[0].warehouseInFk); + expect(controller.travel.warehouseOutFk).toEqual(expectedResponse[0].warehouseOutFk); }); }); }); From 0732ff38b19ddf6e6b6d78ff803835ce0adcff46 Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Wed, 17 Feb 2021 11:04:46 +0100 Subject: [PATCH 02/19] Quit clogs --- modules/travel/back/methods/travel/getAverageDays.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/travel/back/methods/travel/getAverageDays.js b/modules/travel/back/methods/travel/getAverageDays.js index 9a326652d..e56ac21e6 100644 --- a/modules/travel/back/methods/travel/getAverageDays.js +++ b/modules/travel/back/methods/travel/getAverageDays.js @@ -36,7 +36,6 @@ module.exports = Self => { FROM travel t WHERE t.agencyFk = ? LIMIT 50)`, [agencyModeFk]); stmts.push(stmt); - console.log(stmts); stmt = new ParameterizedSQL(`SELECT t.id, t.warehouseInFk, t.warehouseOutFk, (SELECT ROUND(AVG(DATEDIFF(t.landed, t.shipped ))) @@ -53,7 +52,6 @@ module.exports = Self => { let result = await conn.executeStmt(sql); avgDays = result[resultAvgDays]; - console.log(avgDays); return avgDays; }; }; From 3763b95f6230c7502f4c580e979db37837567b1d Mon Sep 17 00:00:00 2001 From: Jorge Padawan Date: Wed, 17 Feb 2021 15:38:57 +0100 Subject: [PATCH 03/19] Added multiplier in sections and filter selection --- modules/item/front/basic-data/index.html | 7 +++++++ modules/item/front/index/index.html | 26 +++++++++++++++++++++++- modules/item/front/summary/index.html | 3 +++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/item/front/basic-data/index.html b/modules/item/front/basic-data/index.html index 3f049675c..1fa913940 100644 --- a/modules/item/front/basic-data/index.html +++ b/modules/item/front/basic-data/index.html @@ -113,6 +113,13 @@ ng-model="$ctrl.item.stems" rule> + + - \ No newline at end of file + + + + + Filter by selection + + + Exclude selection + + + Remove filter + + + Remove all filters + + + \ No newline at end of file diff --git a/modules/item/front/summary/index.html b/modules/item/front/summary/index.html index 59ceaebbe..67d3bf3c6 100644 --- a/modules/item/front/summary/index.html +++ b/modules/item/front/summary/index.html @@ -55,6 +55,9 @@ + + Date: Fri, 19 Feb 2021 17:45:45 +0100 Subject: [PATCH 04/19] Added boss on basic data and summary --- modules/worker/back/models/worker.json | 5 +++++ modules/worker/front/basic-data/index.html | 9 +++++++++ modules/worker/front/summary/index.html | 4 ++++ modules/worker/front/summary/index.js | 3 +++ 4 files changed, 21 insertions(+) diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 45eee23bf..906f9baef 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -61,6 +61,11 @@ "type": "hasMany", "model": "WorkerTeamCollegues", "foreignKey": "workerFk" + }, + "boss": { + "type": "belongsTo", + "model": "Worker", + "foreignKey": "bossFk" } } } \ No newline at end of file diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html index a2cbbc637..a767eccc4 100644 --- a/modules/worker/front/basic-data/index.html +++ b/modules/worker/front/basic-data/index.html @@ -29,6 +29,15 @@ ng-model="$ctrl.worker.phone" rule> + + diff --git a/modules/worker/front/summary/index.html b/modules/worker/front/summary/index.html index 0a99959e4..cc7a0b03c 100644 --- a/modules/worker/front/summary/index.html +++ b/modules/worker/front/summary/index.html @@ -30,6 +30,10 @@ + + diff --git a/modules/worker/front/summary/index.js b/modules/worker/front/summary/index.js index 6a4d87007..631b307a2 100644 --- a/modules/worker/front/summary/index.js +++ b/modules/worker/front/summary/index.js @@ -34,6 +34,9 @@ class Controller extends Summary { }, { relation: 'client', scope: {fields: ['fi']} + }, { + relation: 'boss', + scope: {fields: ['id', 'firstName']} }, { relation: 'sip', scope: {fields: ['extension']} From 5692b5f07e09436835171d7700dc0abb9783b6e9 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Mon, 22 Feb 2021 09:53:03 +0100 Subject: [PATCH 05/19] Added conditional and test --- .../travel/back/methods/travel/getAverageDays.js | 4 +++- modules/travel/front/create/index.js | 2 ++ modules/travel/front/create/index.spec.js | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/modules/travel/back/methods/travel/getAverageDays.js b/modules/travel/back/methods/travel/getAverageDays.js index e56ac21e6..7f6be936e 100644 --- a/modules/travel/back/methods/travel/getAverageDays.js +++ b/modules/travel/back/methods/travel/getAverageDays.js @@ -31,7 +31,7 @@ module.exports = Self => { t.warehouseInFk, t.warehouseOutFk, t.landed, - t.shipped,+ + t.shipped, t.agencyFk FROM travel t WHERE t.agencyFk = ? LIMIT 50)`, [agencyModeFk]); @@ -43,6 +43,7 @@ module.exports = Self => { WHERE t.agencyFk ORDER BY id DESC LIMIT 50) AS dayDuration FROM tmp.travel t WHERE t.agencyFk ORDER BY t.id DESC LIMIT 1`); + let resultAvgDays = stmts.push(stmt) - 1; stmts.push( `DROP TEMPORARY TABLE @@ -52,6 +53,7 @@ module.exports = Self => { let result = await conn.executeStmt(sql); avgDays = result[resultAvgDays]; + return avgDays; }; }; diff --git a/modules/travel/front/create/index.js b/modules/travel/front/create/index.js index c76728e59..ba5bbd1ff 100644 --- a/modules/travel/front/create/index.js +++ b/modules/travel/front/create/index.js @@ -22,6 +22,8 @@ class Controller extends Section { agencyModeFk: this.travel.agencyModeFk }; this.$http.get(query, {params}).then(res => { + if (res.data.length < 1) + return; const landed = new Date(value); const futureDate = landed.getDate() + res.data[0].dayDuration; landed.setDate(futureDate); diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index dcb17d494..af1864ffd 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -41,7 +41,7 @@ describe('Travel Component vnTravelCreate', () => { }); }); - describe('onShippedChange()', () => { + fdescribe('onShippedChange()', () => { it(`should do nothing if there's no agencyModeFk in the travel.`, () => { controller.travel = {}; controller.onShippedChange(); @@ -51,6 +51,20 @@ describe('Travel Component vnTravelCreate', () => { expect(controller.travel.warehouseOutFk).toBeUndefined(); }); + it(`should do nothing if it hasn't value on response data.`, () => { + controller.travel = {agencyModeFk: 4}; + const tomorrow = new Date(); + const result = [{}]; + const expectedResponse = [{}]; + + const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`; + $httpBackend.expectGET(query).respond(expectedResponse); + controller.onShippedChange(tomorrow); + $httpBackend.flush(); + + expect(expectedResponse).toEqual(result); + }); + it(`should fill the fields when it's selected a date and agency.`, () => { controller.travel = {agencyModeFk: 1}; const tomorrow = new Date(); From 5ef48919ecec6fa453b06a48513505db4fe1a885 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Mon, 22 Feb 2021 13:41:31 +0100 Subject: [PATCH 06/19] Added translate multiplier --- modules/item/front/basic-data/locale/es.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/item/front/basic-data/locale/es.yml b/modules/item/front/basic-data/locale/es.yml index 1681862e0..9fd3ca3c4 100644 --- a/modules/item/front/basic-data/locale/es.yml +++ b/modules/item/front/basic-data/locale/es.yml @@ -9,4 +9,5 @@ Price in kg: Precio en kg New intrastat: Nuevo intrastat Identifier: Identificador Fragile: Frágil -Is shown at website, app that this item cannot travel (wreath, palms, ...): Se muestra en la web, app que este artículo no puede viajar (coronas, palmas, ...) \ No newline at end of file +Is shown at website, app that this item cannot travel (wreath, palms, ...): Se muestra en la web, app que este artículo no puede viajar (coronas, palmas, ...) +Multiplier: Multiplicador \ No newline at end of file From 69f53972d58012a2ff786034ec4d9b57dd9383cf Mon Sep 17 00:00:00 2001 From: jorgebl Date: Mon, 22 Feb 2021 16:43:40 +0100 Subject: [PATCH 07/19] Added filter for selection --- modules/item/back/methods/item/filter.js | 19 ++++++++++++--- modules/item/front/index/index.js | 31 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index f392dba87..c2ba547c1 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -44,6 +44,10 @@ module.exports = Self => { arg: 'description', type: 'String', description: 'The item description', + }, { + arg: 'stemMultiplier', + type: 'Integer', + description: 'The item multiplier', } ], returns: { @@ -82,14 +86,22 @@ module.exports = Self => { return {'i.id': value}; case 'description': return {'i.description': {like: `%${value}%`}}; - case 'categoryFk': - return {'ic.id': value}; + case 'category': + return {'ic.name': value}; case 'salesPersonFk': return {'t.workerFk': value}; - case 'typeFk': + case 'type': return {'i.typeFk': value}; case 'isActive': return {'i.isActive': value}; + case 'multiplier': + return {'i.stemMultiplier': value}; + case 'origin': + return {'ori.code': value}; + case 'niche': + return {'itn.code': value}; + case 'intrastat': + return {'intr.description': value}; } }); filter = mergeFilters(filter, {where}); @@ -112,6 +124,7 @@ module.exports = Self => { i.subName, i.isActive, t.name type, + i.typeFk as type, t.workerFk buyerFk, u.name userName, intr.description AS intrastat, diff --git a/modules/item/front/index/index.js b/modules/item/front/index/index.js index cafa3e475..b9d626e50 100644 --- a/modules/item/front/index/index.js +++ b/modules/item/front/index/index.js @@ -11,6 +11,37 @@ class Controller extends Section { }; } + exprBuilder(param, value) { + switch (param) { + case 'category': + return {'ic.name': value}; + case 'salesPersonFk': + return {'t.workerFk': value}; + case 'grouping': + return {'b.grouping': value}; + case 'packing': + return {'b.packing': value}; + case 'origin': + return {'ori.code': value}; + case 'niche': + return {'itn.code': value}; + case 'type': + return {'i.typeFk': value}; + case 'intrastat': + return {'intr.description': value}; + case 'id': + case 'description': + case 'size': + case 'name': + case 'subname': + case 'isActive': + case 'density': + case 'stemMultiplier': + case 'stems': + return {[`i.${param}`]: value}; + } + } + onCloneAccept(itemFk) { return this.$http.post(`Items/${itemFk}/clone`) .then(res => { From 9855bd14fef0c5336a44d13cb3c84d84797dd4bb Mon Sep 17 00:00:00 2001 From: jorgebl Date: Tue, 23 Feb 2021 11:08:57 +0100 Subject: [PATCH 08/19] Translate Boss --- modules/worker/front/locale/es.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/worker/front/locale/es.yml b/modules/worker/front/locale/es.yml index 63570ddf0..1414d089b 100644 --- a/modules/worker/front/locale/es.yml +++ b/modules/worker/front/locale/es.yml @@ -7,6 +7,7 @@ Extension: Extensión Fiscal identifier: NIF Go to client: Ir al cliente Last name: Apellidos +Boss: Jefe Log: Historial Private Branch Exchange: Centralita Role: Rol From 71eeaadb43d095144901f0bbcef31c8c1bf3cc35 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Tue, 23 Feb 2021 14:54:07 +0100 Subject: [PATCH 09/19] Removed focus on test --- modules/travel/front/create/index.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index af1864ffd..6771afce0 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -41,7 +41,7 @@ describe('Travel Component vnTravelCreate', () => { }); }); - fdescribe('onShippedChange()', () => { + describe('onShippedChange()', () => { it(`should do nothing if there's no agencyModeFk in the travel.`, () => { controller.travel = {}; controller.onShippedChange(); From 7895af8a542e51b7ea40dc86bc9cd46029f81278 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Tue, 23 Feb 2021 17:00:31 +0100 Subject: [PATCH 10/19] Fixed test --- modules/travel/front/create/index.spec.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index 6771afce0..a9d5a1b02 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -54,15 +54,21 @@ describe('Travel Component vnTravelCreate', () => { it(`should do nothing if it hasn't value on response data.`, () => { controller.travel = {agencyModeFk: 4}; const tomorrow = new Date(); - const result = [{}]; - const expectedResponse = [{}]; + const expectedResponse = [{ + agencyModeFk: 4, + warehouseInFk: undefined, + warehouseOutFk: undefined, + dayDuration: 0 + }]; const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`; $httpBackend.expectGET(query).respond(expectedResponse); controller.onShippedChange(tomorrow); $httpBackend.flush(); - expect(expectedResponse).toEqual(result); + expect(controller.travel.warehouseInFk).toEqual(expectedResponse.warehouseInFk); + expect(controller.travel.warehouseOutFk).toEqual(expectedResponse.warehouseOutFk); + expect(controller.travel.dayDuration).toEqual(expectedResponse.dayDuration); }); it(`should fill the fields when it's selected a date and agency.`, () => { From 347ac77878312a3c93b9ed45f13228baa280d3db Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 24 Feb 2021 09:59:41 +0100 Subject: [PATCH 11/19] Changes to file names --- back/models/image.js | 4 ++-- .../item/back/methods/item-image-queue/downloadImages.js | 7 +------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/back/models/image.js b/back/models/image.js index 78d159940..2187b5278 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -54,7 +54,7 @@ module.exports = Self => { }; await fs.mkdir(dstDir, {recursive: true}); - await sharp(srcFilePath, {failOnError: false}) + await sharp(srcFilePath) .resize(collection.maxWidth, collection.maxHeight, resizeOpts) .png() .toFile(dstFile); @@ -69,7 +69,7 @@ module.exports = Self => { }; await fs.mkdir(dstDir, {recursive: true}); - await sharp(srcFilePath, {failOnError: false}) + await sharp(srcFilePath) .resize(size.width, size.height, resizeOpts) .png() .toFile(dstFile); diff --git a/modules/item/back/methods/item-image-queue/downloadImages.js b/modules/item/back/methods/item-image-queue/downloadImages.js index e3412d6a8..cc1315e91 100644 --- a/modules/item/back/methods/item-image-queue/downloadImages.js +++ b/modules/item/back/methods/item-image-queue/downloadImages.js @@ -47,12 +47,7 @@ module.exports = Self => { if (!image) return; const srcFile = image.url.split('/').pop(); - const dotIndex = srcFile.lastIndexOf('.'); - - let fileName = srcFile.substring(0, dotIndex); - if (dotIndex == -1) - fileName = srcFile; - + const fileName = srcFile.replace(/\./g, ''); const file = `${fileName}.png`; const filePath = path.join(tempPath, file); From 3af50dfc806d4a1f57a65d86c7822254c4d63e5d Mon Sep 17 00:00:00 2001 From: jorgebl Date: Wed, 24 Feb 2021 11:32:31 +0100 Subject: [PATCH 12/19] QA refactor --- .../back/methods/travel/getAverageDays.js | 49 ++++++++++-------- modules/travel/front/create/index.js | 9 ++-- modules/travel/front/create/index.spec.js | 50 ++++++++----------- 3 files changed, 55 insertions(+), 53 deletions(-) diff --git a/modules/travel/back/methods/travel/getAverageDays.js b/modules/travel/back/methods/travel/getAverageDays.js index 7f6be936e..9a9649d84 100644 --- a/modules/travel/back/methods/travel/getAverageDays.js +++ b/modules/travel/back/methods/travel/getAverageDays.js @@ -9,7 +9,7 @@ module.exports = Self => { required: true }], returns: { - type: 'number', + type: 'object', root: true }, http: { @@ -21,38 +21,45 @@ module.exports = Self => { Self.getAverageDays = async agencyModeFk => { const conn = Self.dataSource.connector; let stmts = []; - let avgDays = {}; stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.travel'); stmt = new ParameterizedSQL(` - CREATE TEMPORARY TABLE tmp.travel ( - SELECT t.id, - t.warehouseInFk, - t.warehouseOutFk, - t.landed, - t.shipped, - t.agencyFk - FROM travel t - WHERE t.agencyFk = ? LIMIT 50)`, [agencyModeFk]); + CREATE TEMPORARY TABLE tmp.travel ( + SELECT + t.id, + t.warehouseInFk, + t.warehouseOutFk, + t.landed, + t.shipped, + t.agencyFk + FROM travel t + WHERE t.agencyFk = ? LIMIT 50)`, [agencyModeFk]); stmts.push(stmt); - stmt = new ParameterizedSQL(`SELECT t.id, t.warehouseInFk, t.warehouseOutFk, - (SELECT ROUND(AVG(DATEDIFF(t.landed, t.shipped ))) - FROM tmp.travel t - WHERE t.agencyFk ORDER BY id DESC LIMIT 50) AS dayDuration - FROM tmp.travel t - WHERE t.agencyFk ORDER BY t.id DESC LIMIT 1`); + stmt = new ParameterizedSQL(` + SELECT + t.id, + t.warehouseInFk, + t.warehouseOutFk, + (SELECT ROUND(AVG(DATEDIFF(t.landed, t.shipped ))) + FROM tmp.travel t + WHERE t.agencyFk + ORDER BY id DESC LIMIT 50) AS dayDuration + FROM tmp.travel t + WHERE t.agencyFk + ORDER BY t.id DESC LIMIT 1`); + + const avgDaysIndex = stmts.push(stmt) - 1; - let resultAvgDays = stmts.push(stmt) - 1; stmts.push( `DROP TEMPORARY TABLE tmp.travel`); - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await conn.executeStmt(sql); + const sql = ParameterizedSQL.join(stmts, ';'); + const result = await conn.executeStmt(sql); - avgDays = result[resultAvgDays]; + const [avgDays] = result[avgDaysIndex]; return avgDays; }; diff --git a/modules/travel/front/create/index.js b/modules/travel/front/create/index.js index ba5bbd1ff..a85917ca8 100644 --- a/modules/travel/front/create/index.js +++ b/modules/travel/front/create/index.js @@ -22,15 +22,16 @@ class Controller extends Section { agencyModeFk: this.travel.agencyModeFk }; this.$http.get(query, {params}).then(res => { - if (res.data.length < 1) + if (!res.data) return; + const landed = new Date(value); - const futureDate = landed.getDate() + res.data[0].dayDuration; + const futureDate = landed.getDate() + res.data.dayDuration; landed.setDate(futureDate); this.travel.landed = landed; - this.travel.warehouseInFk = res.data[0].warehouseInFk; - this.travel.warehouseOutFk = res.data[0].warehouseOutFk; + this.travel.warehouseInFk = res.data.warehouseInFk; + this.travel.warehouseOutFk = res.data.warehouseOutFk; }); } diff --git a/modules/travel/front/create/index.spec.js b/modules/travel/front/create/index.spec.js index a9d5a1b02..e3f85d9ae 100644 --- a/modules/travel/front/create/index.spec.js +++ b/modules/travel/front/create/index.spec.js @@ -51,15 +51,30 @@ describe('Travel Component vnTravelCreate', () => { expect(controller.travel.warehouseOutFk).toBeUndefined(); }); - it(`should do nothing if it hasn't value on response data.`, () => { + it(`should do nothing if there's no response data.`, () => { controller.travel = {agencyModeFk: 4}; const tomorrow = new Date(); - const expectedResponse = [{ - agencyModeFk: 4, - warehouseInFk: undefined, - warehouseOutFk: undefined, - dayDuration: 0 - }]; + + const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`; + $httpBackend.expectGET(query).respond(undefined); + controller.onShippedChange(tomorrow); + $httpBackend.flush(); + + expect(controller.travel.warehouseInFk).toBeUndefined(); + expect(controller.travel.warehouseOutFk).toBeUndefined(); + expect(controller.travel.dayDuration).toBeUndefined(); + }); + + it(`should fill the fields when it's selected a date and agency.`, () => { + controller.travel = {agencyModeFk: 1}; + const tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 9); + const expectedResponse = { + id: 8, + dayDuration: 9, + warehouseInFk: 5, + warehouseOutFk: 1 + }; const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`; $httpBackend.expectGET(query).respond(expectedResponse); @@ -68,27 +83,6 @@ describe('Travel Component vnTravelCreate', () => { expect(controller.travel.warehouseInFk).toEqual(expectedResponse.warehouseInFk); expect(controller.travel.warehouseOutFk).toEqual(expectedResponse.warehouseOutFk); - expect(controller.travel.dayDuration).toEqual(expectedResponse.dayDuration); - }); - - it(`should fill the fields when it's selected a date and agency.`, () => { - controller.travel = {agencyModeFk: 1}; - const tomorrow = new Date(); - tomorrow.setDate(tomorrow.getDate() + 9); - const expectedResponse = [{ - id: 8, - dayDuration: 9, - warehouseInFk: 5, - warehouseOutFk: 1 - }]; - - const query = `travels/getAverageDays?agencyModeFk=${controller.travel.agencyModeFk}`; - $httpBackend.expectGET(query).respond(expectedResponse); - controller.onShippedChange(tomorrow); - $httpBackend.flush(); - - expect(controller.travel.warehouseInFk).toEqual(expectedResponse[0].warehouseInFk); - expect(controller.travel.warehouseOutFk).toEqual(expectedResponse[0].warehouseOutFk); }); }); }); From df9ca2ad3eb70157734783b125cb382f46a78af1 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Wed, 24 Feb 2021 12:24:50 +0100 Subject: [PATCH 13/19] Fixed filter description --- modules/item/back/methods/item/filter.js | 2 -- modules/item/front/index/index.html | 2 +- modules/item/front/index/index.js | 1 - 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index c2ba547c1..000d9bb8e 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -84,8 +84,6 @@ module.exports = Self => { : {or: [{'i.name': {like: `%${value}%`}}, codeWhere]}; case 'id': return {'i.id': value}; - case 'description': - return {'i.description': {like: `%${value}%`}}; case 'category': return {'ic.name': value}; case 'salesPersonFk': diff --git a/modules/item/front/index/index.html b/modules/item/front/index/index.html index 0cf18bdb0..21227ad95 100644 --- a/modules/item/front/index/index.html +++ b/modules/item/front/index/index.html @@ -15,7 +15,7 @@ Id Grouping Packing - Description + Description Stems Size Niche diff --git a/modules/item/front/index/index.js b/modules/item/front/index/index.js index b9d626e50..8a510c3a1 100644 --- a/modules/item/front/index/index.js +++ b/modules/item/front/index/index.js @@ -30,7 +30,6 @@ class Controller extends Section { case 'intrastat': return {'intr.description': value}; case 'id': - case 'description': case 'size': case 'name': case 'subname': From 1c819e692ee75314fafb051d8ba7dd0900a27a20 Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 24 Feb 2021 14:37:49 +0100 Subject: [PATCH 14/19] Floramondo image download fixes --- back/models/image.js | 62 ++++++++++++++++++- .../item-image-queue/downloadImages.js | 4 +- package-lock.json | 40 +++++++++++- package.json | 3 + 4 files changed, 103 insertions(+), 6 deletions(-) diff --git a/back/models/image.js b/back/models/image.js index 2187b5278..a35018814 100644 --- a/back/models/image.js +++ b/back/models/image.js @@ -1,11 +1,51 @@ const fs = require('fs-extra'); const sharp = require('sharp'); const path = require('path'); +const readChunk = require('read-chunk'); +const imageType = require('image-type'); +const bmp = require('bmp-js'); module.exports = Self => { require('../methods/image/download')(Self); require('../methods/image/upload')(Self); + // Function extracted from jimp package (utils) + function scan(image, x, y, w, h, f) { + // round input + x = Math.round(x); + y = Math.round(y); + w = Math.round(w); + h = Math.round(h); + + for (let _y = y; _y < y + h; _y++) { + for (let _x = x; _x < x + w; _x++) { + const idx = (image.bitmap.width * _y + _x) << 2; + f.call(image, _x, _y, idx); + } + } + + return image; + } + + // Function extracted from jimp package (type-bmp) + function fromAGBR(bitmap) { + return scan({bitmap}, 0, 0, bitmap.width, bitmap.height, function( + x, + y, + index + ) { + const alpha = this.bitmap.data[index + 0]; + const blue = this.bitmap.data[index + 1]; + const green = this.bitmap.data[index + 2]; + const red = this.bitmap.data[index + 3]; + + this.bitmap.data[index + 0] = red; + this.bitmap.data[index + 1] = green; + this.bitmap.data[index + 2] = blue; + this.bitmap.data[index + 3] = bitmap.is_with_alpha ? alpha : 0xff; + }).bitmap; + } + Self.registerImage = async(collectionName, srcFilePath, fileName, entityId) => { const models = Self.app.models; const tx = await Self.beginTransaction({}); @@ -48,13 +88,31 @@ module.exports = Self => { const dstDir = path.join(collectionDir, 'full'); const dstFile = path.join(dstDir, file); + const buffer = readChunk.sync(srcFilePath, 0, 12); + const type = imageType(buffer); + + let sharpOptions; + let imgSrc = srcFilePath; + if (type.mime == 'image/bmp') { + const bmpBuffer = fs.readFileSync(srcFilePath); + const bmpData = fromAGBR(bmp.decode(bmpBuffer)); + imgSrc = bmpData.data; + sharpOptions = { + raw: { + width: bmpData.width, + height: bmpData.height, + channels: 4 + } + }; + } + const resizeOpts = { withoutEnlargement: true, fit: 'inside' }; await fs.mkdir(dstDir, {recursive: true}); - await sharp(srcFilePath) + await sharp(imgSrc, sharpOptions) .resize(collection.maxWidth, collection.maxHeight, resizeOpts) .png() .toFile(dstFile); @@ -69,7 +127,7 @@ module.exports = Self => { }; await fs.mkdir(dstDir, {recursive: true}); - await sharp(srcFilePath) + await sharp(imgSrc, sharpOptions) .resize(size.width, size.height, resizeOpts) .png() .toFile(dstFile); diff --git a/modules/item/back/methods/item-image-queue/downloadImages.js b/modules/item/back/methods/item-image-queue/downloadImages.js index cc1315e91..713761df5 100644 --- a/modules/item/back/methods/item-image-queue/downloadImages.js +++ b/modules/item/back/methods/item-image-queue/downloadImages.js @@ -46,8 +46,8 @@ module.exports = Self => { if (!image) return; - const srcFile = image.url.split('/').pop(); - const fileName = srcFile.replace(/\./g, ''); + const srcFile = image.url; + const fileName = srcFile.replace(/\.|\/|:/g, ''); const file = `${fileName}.png`; const filePath = path.join(tempPath, file); diff --git a/package-lock.json b/package-lock.json index 861c917d0..79b5df904 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6996,6 +6996,11 @@ "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", "integrity": "sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==" }, + "bmp-js": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/bmp-js/-/bmp-js-0.1.0.tgz", + "integrity": "sha1-4Fpj95amwf8l9Hcex62twUjAcjM=" + }, "bn.js": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", @@ -10041,6 +10046,11 @@ } } }, + "file-type": { + "version": "10.11.0", + "resolved": "https://registry.npmjs.org/file-type/-/file-type-10.11.0.tgz", + "integrity": "sha512-uzk64HRpUZyTGZtVuvrjP0FYxzQrBf4rojot6J65YMEbwBLB0CWm0CLojVpwpmFmxcE/lkvYICgfcGozbBq6rw==" + }, "filed-mimefix": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/filed-mimefix/-/filed-mimefix-0.1.3.tgz", @@ -12985,6 +12995,14 @@ "integrity": "sha1-SMptcvbGo68Aqa1K5odr44ieKwk=", "dev": true }, + "image-type": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/image-type/-/image-type-4.1.0.tgz", + "integrity": "sha512-CFJMJ8QK8lJvRlTCEgarL4ro6hfDQKif2HjSvYCdQZESaIPV4v9imrf7BQHK+sQeTeNeMpWciR9hyC/g8ybXEg==", + "requires": { + "file-type": "^10.10.0" + } + }, "imap": { "version": "0.8.19", "resolved": "https://registry.npmjs.org/imap/-/imap-0.8.19.tgz", @@ -21219,8 +21237,7 @@ "p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", - "dev": true + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" }, "package-json": { "version": "4.0.1", @@ -22141,6 +22158,15 @@ "integrity": "sha512-tJBzzzIgnnRfEm046qRcURvwQnZVXmuCbscxUO5RWrGTXpon2d4c8mI0D8WE6ydVIm29JiLB6+RslkIvym9Rjw==", "dev": true }, + "read-chunk": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/read-chunk/-/read-chunk-3.2.0.tgz", + "integrity": "sha512-CEjy9LCzhmD7nUpJ1oVOE6s/hBkejlcJEgLQHVnQznOSilOPb+kpKktlLfFDK3/WP43+F80xkUTM2VOkYoSYvQ==", + "requires": { + "pify": "^4.0.1", + "with-open-file": "^0.1.6" + } + }, "read-pkg": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", @@ -26651,6 +26677,16 @@ "string-width": "^2.1.1" } }, + "with-open-file": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/with-open-file/-/with-open-file-0.1.7.tgz", + "integrity": "sha512-ecJS2/oHtESJ1t3ZfMI3B7KIDKyfN0O16miWxdn30zdh66Yd3LsRFebXZXq6GU4xfxLf6nVxp9kIqElb5fqczA==", + "requires": { + "p-finally": "^1.0.0", + "p-try": "^2.1.0", + "pify": "^4.0.1" + } + }, "word-count": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/word-count/-/word-count-0.2.2.tgz", diff --git a/package.json b/package.json index 0e1bc8e32..2514c2516 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,12 @@ "node": ">=12" }, "dependencies": { + "bmp-js": "^0.1.0", "compression": "^1.7.3", "fs-extra": "^5.0.0", "helmet": "^3.21.2", "i18n": "^0.8.4", + "image-type": "^4.1.0", "imap": "^0.8.19", "ldapjs": "^2.2.0", "loopback": "^3.26.0", @@ -30,6 +32,7 @@ "node-ssh": "^11.0.0", "object-diff": "0.0.4", "object.pick": "^1.3.0", + "read-chunk": "^3.2.0", "request": "^2.88.0", "request-promise-native": "^1.0.8", "require-yaml": "0.0.1", From f1c481de64f8cc915466539471d424a41ffd8126 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Wed, 24 Feb 2021 14:49:58 +0100 Subject: [PATCH 15/19] QA refactor --- modules/item/back/methods/item/filter.js | 43 ++-- modules/item/front/basic-data/index.html | 3 +- modules/item/front/index/index.html | 249 ++++++++++++----------- modules/item/front/index/index.js | 6 +- 4 files changed, 152 insertions(+), 149 deletions(-) diff --git a/modules/item/back/methods/item/filter.js b/modules/item/back/methods/item/filter.js index 000d9bb8e..eba0b0f91 100644 --- a/modules/item/back/methods/item/filter.js +++ b/modules/item/back/methods/item/filter.js @@ -84,20 +84,20 @@ module.exports = Self => { : {or: [{'i.name': {like: `%${value}%`}}, codeWhere]}; case 'id': return {'i.id': value}; - case 'category': - return {'ic.name': value}; - case 'salesPersonFk': - return {'t.workerFk': value}; - case 'type': - return {'i.typeFk': value}; case 'isActive': return {'i.isActive': value}; case 'multiplier': return {'i.stemMultiplier': value}; + case 'typeFk': + return {'i.typeFk': value}; + case 'category': + return {'ic.name': value}; + case 'salesPersonFk': + return {'it.workerFk': value}; case 'origin': return {'ori.code': value}; case 'niche': - return {'itn.code': value}; + return {'ip.code': value}; case 'intrastat': return {'intr.description': value}; } @@ -108,7 +108,8 @@ module.exports = Self => { let stmt; stmt = new ParameterizedSQL( - `SELECT i.id, + `SELECT + i.id, i.image, i.name, i.description, @@ -121,30 +122,30 @@ module.exports = Self => { i.tag10, i.value10, i.subName, i.isActive, - t.name type, - i.typeFk as type, - t.workerFk buyerFk, - u.name userName, - intr.description AS intrastat, i.stems, - ori.code AS origin, - ic.name AS category, i.density, i.stemMultiplier, + i.typeFk, + it.name AS typeName, + it.workerFk AS buyerFk, + u.name AS userName, + ori.code AS origin, + ic.name AS category, + intr.description AS intrastat, b.grouping, b.packing, - itn.code AS niche, @visibleCalc + ip.code AS niche, @visibleCalc FROM item i - LEFT JOIN itemType t ON t.id = i.typeFk - LEFT JOIN itemCategory ic ON ic.id = t.categoryFk - LEFT JOIN worker w ON w.id = t.workerFk + LEFT JOIN itemType it ON it.id = i.typeFk + LEFT JOIN itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN worker w ON w.id = it.workerFk LEFT JOIN account.user u ON u.id = w.userFk LEFT JOIN intrastat intr ON intr.id = i.intrastatFk LEFT JOIN producer pr ON pr.id = i.producerFk LEFT JOIN origin ori ON ori.id = i.originFk - LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = t.warehouseFk + LEFT JOIN cache.last_buy lb ON lb.item_id = i.id AND lb.warehouse_id = it.warehouseFk LEFT JOIN vn.buy b ON b.id = lb.buy_id - LEFT JOIN itemPlacement itn ON itn.itemFk = i.id AND itn.warehouseFk = t.warehouseFk` + LEFT JOIN itemPlacement ip ON ip.itemFk = i.id AND ip.warehouseFk = it.warehouseFk` ); if (ctx.args.tags) { diff --git a/modules/item/front/basic-data/index.html b/modules/item/front/basic-data/index.html index 1fa913940..cec7a063f 100644 --- a/modules/item/front/basic-data/index.html +++ b/modules/item/front/basic-data/index.html @@ -117,8 +117,7 @@ vn-one min="0" label="Multiplier" - ng-model="$ctrl.item.stemMultiplier" - rule> + ng-model="$ctrl.item.stemMultiplier"> diff --git a/modules/item/front/index/index.html b/modules/item/front/index/index.html index 21227ad95..590a6fdf3 100644 --- a/modules/item/front/index/index.html +++ b/modules/item/front/index/index.html @@ -5,107 +5,107 @@ model="model" class="vn-w-xl vn-mb-xl"> - - - - - Id - Grouping - Packing - Description - Stems - Size - Niche - Type - Category - Intrastat - Origin - Buyer - Density - Multiplier - Active - - - - - - - - - - - {{::item.id}} - - - {{::item.grouping | dashIfEmpty}} - {{::item.packing | dashIfEmpty}} - - {{::item.name}} - -

{{::item.subName}}

-
- - -
- {{::item.stems}} - {{::item.size}} - {{::item.niche}} - - {{::item.type}} - - - {{::item.category}} - - - {{::item.intrastat}} - - {{::item.origin}} - - - {{::item.userName}} - - - {{::item.density}} - {{::item.stemMultiplier}} - - - - - - - - - - - - -
-
-
+ + + + + Id + Grouping + Packing + Description + Stems + Size + Niche + Type + Category + Intrastat + Origin + Buyer + Density + Multiplier + Active + + + + + + + + + + + {{::item.id}} + + + {{::item.grouping | dashIfEmpty}} + {{::item.packing | dashIfEmpty}} + + {{::item.name}} + +

{{::item.subName}}

+
+ + +
+ {{::item.stems}} + {{::item.size}} + {{::item.niche}} + + {{::item.typeName}} + + + {{::item.category}} + + + {{::item.intrastat}} + + {{::item.origin}} + + + {{::item.userName}} + + + {{::item.density}} + {{::item.stemMultiplier}} + + + + + + + + + + + + +
+
+
@@ -128,27 +128,30 @@ item="$ctrl.itemSelected"> - - - - Filter by selection - - - Exclude selection - - - Remove filter - - - Remove all filters - - + + + Filter by selection + + + Exclude selection + + + Remove filter + + + Remove all filters + + \ No newline at end of file diff --git a/modules/item/front/index/index.js b/modules/item/front/index/index.js index 8a510c3a1..175beb88a 100644 --- a/modules/item/front/index/index.js +++ b/modules/item/front/index/index.js @@ -16,7 +16,7 @@ class Controller extends Section { case 'category': return {'ic.name': value}; case 'salesPersonFk': - return {'t.workerFk': value}; + return {'it.workerFk': value}; case 'grouping': return {'b.grouping': value}; case 'packing': @@ -24,8 +24,8 @@ class Controller extends Section { case 'origin': return {'ori.code': value}; case 'niche': - return {'itn.code': value}; - case 'type': + return {'ip.code': value}; + case 'typeFk': return {'i.typeFk': value}; case 'intrastat': return {'intr.description': value}; From d3879635a81effdbb4fa1000dcb10c68aa861d5b Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 24 Feb 2021 15:54:02 +0100 Subject: [PATCH 16/19] Regex changes --- modules/item/back/methods/item-image-queue/downloadImages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/methods/item-image-queue/downloadImages.js b/modules/item/back/methods/item-image-queue/downloadImages.js index 713761df5..16ad33ce3 100644 --- a/modules/item/back/methods/item-image-queue/downloadImages.js +++ b/modules/item/back/methods/item-image-queue/downloadImages.js @@ -47,7 +47,7 @@ module.exports = Self => { if (!image) return; const srcFile = image.url; - const fileName = srcFile.replace(/\.|\/|:/g, ''); + const fileName = srcFile.replace(/\.|\/|:|\?|\\/g, ''); const file = `${fileName}.png`; const filePath = path.join(tempPath, file); From ddb77a5c05d8fa65529203ba59210a867207645d Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 24 Feb 2021 15:55:09 +0100 Subject: [PATCH 17/19] Regex change --- modules/item/back/methods/item-image-queue/downloadImages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/methods/item-image-queue/downloadImages.js b/modules/item/back/methods/item-image-queue/downloadImages.js index 16ad33ce3..2f591ad4b 100644 --- a/modules/item/back/methods/item-image-queue/downloadImages.js +++ b/modules/item/back/methods/item-image-queue/downloadImages.js @@ -47,7 +47,7 @@ module.exports = Self => { if (!image) return; const srcFile = image.url; - const fileName = srcFile.replace(/\.|\/|:|\?|\\/g, ''); + const fileName = srcFile.replace(/\.|\/|:|\?|\\|=/g, ''); const file = `${fileName}.png`; const filePath = path.join(tempPath, file); From c2a22044377077d2d67f85655fb305fcd34b099a Mon Sep 17 00:00:00 2001 From: joan Date: Wed, 24 Feb 2021 16:04:09 +0100 Subject: [PATCH 18/19] Regex change --- modules/item/back/methods/item-image-queue/downloadImages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/item/back/methods/item-image-queue/downloadImages.js b/modules/item/back/methods/item-image-queue/downloadImages.js index 2f591ad4b..2d2e8af91 100644 --- a/modules/item/back/methods/item-image-queue/downloadImages.js +++ b/modules/item/back/methods/item-image-queue/downloadImages.js @@ -47,7 +47,7 @@ module.exports = Self => { if (!image) return; const srcFile = image.url; - const fileName = srcFile.replace(/\.|\/|:|\?|\\|=/g, ''); + const fileName = srcFile.replace(/\.|\/|:|\?|\\|=|%/g, ''); const file = `${fileName}.png`; const filePath = path.join(tempPath, file); From 1f1db53d415d6f3a8b14a6ae9ff33a24964ee0a8 Mon Sep 17 00:00:00 2001 From: jorgebl Date: Wed, 24 Feb 2021 16:12:44 +0100 Subject: [PATCH 19/19] Summary boss shown on descriptor --- modules/worker/back/models/worker.json | 10 +++++----- modules/worker/front/summary/index.html | 13 ++++++++++--- modules/worker/front/summary/index.js | 18 +++++++++++------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index 906f9baef..cad38ac3b 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -42,6 +42,11 @@ "model": "Account", "foreignKey": "userFk" }, + "boss": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "bossFk" + }, "client": { "type": "belongsTo", "model": "Client", @@ -61,11 +66,6 @@ "type": "hasMany", "model": "WorkerTeamCollegues", "foreignKey": "workerFk" - }, - "boss": { - "type": "belongsTo", - "model": "Worker", - "foreignKey": "bossFk" } } } \ No newline at end of file diff --git a/modules/worker/front/summary/index.html b/modules/worker/front/summary/index.html index cc7a0b03c..d2a7e750b 100644 --- a/modules/worker/front/summary/index.html +++ b/modules/worker/front/summary/index.html @@ -31,8 +31,12 @@ value="{{worker.department.department.name}}"> + label="Boss"> + + {{::worker.boss.nickname}} + @@ -54,4 +58,7 @@
- \ No newline at end of file + + + \ No newline at end of file diff --git a/modules/worker/front/summary/index.js b/modules/worker/front/summary/index.js index 631b307a2..3cdb2c36f 100644 --- a/modules/worker/front/summary/index.js +++ b/modules/worker/front/summary/index.js @@ -11,8 +11,8 @@ class Controller extends Summary { this.$.worker = null; if (!value) return; - let query = `Workers/${value.id}`; - let filter = { + const query = `Workers/${value.id}`; + const filter = { include: [ { relation: 'user', @@ -31,16 +31,20 @@ class Controller extends Summary { } }] } - }, { + }, + { relation: 'client', scope: {fields: ['fi']} - }, { + }, + { relation: 'boss', - scope: {fields: ['id', 'firstName']} - }, { + scope: {fields: ['id', 'nickname']} + }, + { relation: 'sip', scope: {fields: ['extension']} - }, { + }, + { relation: 'department', scope: { include: {