From 70210e87c9ae50310aacb901565ac54728142a7e Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 27 Feb 2020 09:03:36 +0100 Subject: [PATCH 1/9] Advanced filter by ref --- modules/travel/back/methods/travel/filter.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index ecf152b0c..bfe49c834 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -63,6 +63,10 @@ module.exports = Self => { type: 'Number', description: 'The totalEntries filter', http: {source: 'query'} + }, { + arg: 'ref', + type: 'string', + description: 'The reference' } ], returns: { @@ -82,7 +86,7 @@ module.exports = Self => { case 'search': return {'t.id': value}; case 'ref': - return {[param]: {regexp: value}}; + return {'t.ref': {like: `%${value}%`}}; case 'shippedFrom': return {'t.shipped': {gte: value}}; case 'shippedTo': From ccd28114ca226619d68c86ad93a861663c261034 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 27 Feb 2020 12:39:58 +0100 Subject: [PATCH 2/9] Updated unit tests --- modules/travel/back/methods/travel/filter.js | 4 ++- .../back/methods/travel/specs/filter.spec.js | 33 ++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/modules/travel/back/methods/travel/filter.js b/modules/travel/back/methods/travel/filter.js index bfe49c834..4d1be2d0e 100644 --- a/modules/travel/back/methods/travel/filter.js +++ b/modules/travel/back/methods/travel/filter.js @@ -84,7 +84,9 @@ module.exports = Self => { let where = buildFilter(ctx.args, (param, value) => { switch (param) { case 'search': - return {'t.id': value}; + return /^\d+$/.test(value) + ? {'t.id': value} + : {'t.ref': {like: `%${value}%`}}; case 'ref': return {'t.ref': {like: `%${value}%`}}; case 'shippedFrom': diff --git a/modules/travel/back/methods/travel/specs/filter.spec.js b/modules/travel/back/methods/travel/specs/filter.spec.js index 03849f2b0..d04b0f093 100644 --- a/modules/travel/back/methods/travel/specs/filter.spec.js +++ b/modules/travel/back/methods/travel/specs/filter.spec.js @@ -2,38 +2,53 @@ const app = require('vn-loopback/server/server'); describe('Travel filter()', () => { it('should return the travel matching "search"', async() => { - let ctx = { + const ctx = { args: { search: 1 } }; - let result = await app.models.Travel.filter(ctx); + const result = await app.models.Travel.filter(ctx); + const firstRow = result[0]; expect(result.length).toEqual(1); - expect(result[0].id).toEqual(1); + expect(firstRow.id).toEqual(1); + }); + + it('should return the travel matching "search" by ref', async() => { + const ctx = { + args: { + search: 'third' + } + }; + + const result = await app.models.Travel.filter(ctx); + const firstRow = result[0]; + + expect(result.length).toEqual(1); + expect(firstRow.id).toEqual(3); }); it('should return the travel matching "warehouse out"', async() => { - let ctx = { + const ctx = { args: { warehouseOutFk: 2 } }; - let result = await app.models.Travel.filter(ctx); + const result = await app.models.Travel.filter(ctx); expect(result.length).toEqual(8); }); it('should return the travel matching "total entries"', async() => { - let ctx = { + const ctx = { args: { totalEntries: 1, } }; - let result = await app.models.Travel.filter(ctx); + const result = await app.models.Travel.filter(ctx); expect(result.length).toEqual(5); }); @@ -44,14 +59,14 @@ describe('Travel filter()', () => { from.setHours(0, 0, 0, 0); to.setHours(23, 59, 59, 999); to.setDate(to.getDate() + 1); - let ctx = { + const ctx = { args: { shippedFrom: from, shippedTo: to } }; - let result = await app.models.Travel.filter(ctx); + const result = await app.models.Travel.filter(ctx); expect(result.length).toEqual(1); }); From 6dcfc340566175e313a52f7d91f593fbf67c9763 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Thu, 27 Feb 2020 13:33:40 +0100 Subject: [PATCH 3/9] Fix - Find duplicated client --- modules/client/front/fiscal-data/index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/client/front/fiscal-data/index.js b/modules/client/front/fiscal-data/index.js index 98773de75..b2602f7a4 100644 --- a/modules/client/front/fiscal-data/index.js +++ b/modules/client/front/fiscal-data/index.js @@ -24,14 +24,15 @@ export default class Controller extends Component { const filter = encodeURIComponent(JSON.stringify(filterObj)); const query = `Clients/findOne?filter=${filter}`; this.$http.get(query).then(res => { - if (res.data.id) { - const params = {clientId: res.data.id}; - const question = $t('Found a client with this phone or email', params, null, null, 'sanitizeParameters'); + const params = {clientId: res.data.id}; + const question = $t('Found a client with this phone or email', params, null, null, 'sanitizeParameters'); - this.client.despiteOfClient = params.clientId; - this.$.confirmDuplicatedClient.question = question; - this.$.confirmDuplicatedClient.show(); - } + this.client.despiteOfClient = params.clientId; + this.$.confirmDuplicatedClient.question = question; + this.$.confirmDuplicatedClient.show(); + }).catch(error => { + if (error.status == 404) + this.save(); }); } From 442541d0f8c63a7aef48f40da7df442f1a43e2b0 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 07:24:36 +0100 Subject: [PATCH 4/9] Renamed rgb column --- modules/worker/back/models/calendar-holidays-type.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/back/models/calendar-holidays-type.json b/modules/worker/back/models/calendar-holidays-type.json index a83dbc13c..178331b87 100644 --- a/modules/worker/back/models/calendar-holidays-type.json +++ b/modules/worker/back/models/calendar-holidays-type.json @@ -14,7 +14,7 @@ "name": { "type": "String" }, - "rgb": { + "hexColour": { "type": "String" } }, From 56b986ff95a2299895f7fd1f9a1ce9cfe61402b5 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 07:26:19 +0100 Subject: [PATCH 5/9] No department error --- back/methods/chat/sendCheckingPresence.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index b2a3ca725..7e74a6980 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -37,7 +37,7 @@ module.exports = Self => { } }); const department = workerDepartment && workerDepartment.department(); - const channelName = department.chatName; + const channelName = department && department.chatName; if (channelName) return Self.send(ctx, `#${channelName}`, `@${account.name} => ${message}`); From a8eea3d8f6a24f6713e3c1790e44eccbaaf56fb1 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 08:19:37 +0100 Subject: [PATCH 6/9] Changed primary key --- modules/worker/back/models/worker-dms.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/worker/back/models/worker-dms.json b/modules/worker/back/models/worker-dms.json index 56cad65a6..f8ad824bc 100644 --- a/modules/worker/back/models/worker-dms.json +++ b/modules/worker/back/models/worker-dms.json @@ -13,10 +13,10 @@ }, "properties": { "id": { - "type": "Number", - "id": true + "type": "Number" }, "dmsFk": { + "id": true, "type": "Number", "required": true, "mysql": { From b0779fb2d363375792e76aa1a42bd0d634d3f79f Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 08:24:01 +0100 Subject: [PATCH 7/9] Added error handler --- back/methods/chat/sendCheckingPresence.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 7e74a6980..5a4ee2fcf 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -26,6 +26,10 @@ module.exports = Self => { Self.sendCheckingPresence = async(ctx, workerId, message) => { const models = Self.app.models; const account = await models.Account.findById(workerId); + const userId = ctx.req.accessToken.userId; + + if (!account) + throw new Error(`Could not send message to worker id ${workerId} from user ${userId}`); const query = `SELECT worker_isWorking(?) isWorking`; const [result] = await Self.rawSql(query, [workerId]); From 3739548d0d2e7beeefd4ef11c18e3fd137e9731d Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 08:39:59 +0100 Subject: [PATCH 8/9] Added error handling for worker not found --- back/methods/chat/sendCheckingPresence.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index 5a4ee2fcf..f67fb6942 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -29,7 +29,7 @@ module.exports = Self => { const userId = ctx.req.accessToken.userId; if (!account) - throw new Error(`Could not send message to worker id ${workerId} from user ${userId}`); + throw new Error(`Could not send message "${message}" to worker id ${workerId} from user ${userId}`); const query = `SELECT worker_isWorking(?) isWorking`; const [result] = await Self.rawSql(query, [workerId]); From 96d98a6dcca83ee14c560676fc21b2e9816b4b72 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 28 Feb 2020 09:23:02 +0100 Subject: [PATCH 9/9] Added workerId validation --- back/methods/chat/sendCheckingPresence.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/back/methods/chat/sendCheckingPresence.js b/back/methods/chat/sendCheckingPresence.js index f67fb6942..6fa029b70 100644 --- a/back/methods/chat/sendCheckingPresence.js +++ b/back/methods/chat/sendCheckingPresence.js @@ -24,6 +24,8 @@ module.exports = Self => { }); Self.sendCheckingPresence = async(ctx, workerId, message) => { + if (!workerId) return false; + const models = Self.app.models; const account = await models.Account.findById(workerId); const userId = ctx.req.accessToken.userId;