From dc5f588c8e22799f989d088e8824f9e5336c5cd4 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 26 Mar 2024 10:13:57 +0100 Subject: [PATCH 1/8] refs #3520 feat: backWarehouse in Salix --- .../ticket-collection/getUncheckedTicket.js | 35 +++++++++++++++++++ .../ticket/back/models/ticket-collection.js | 3 ++ 2 files changed, 38 insertions(+) create mode 100644 modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js create mode 100644 modules/ticket/back/models/ticket-collection.js diff --git a/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js new file mode 100644 index 000000000..64a4c563c --- /dev/null +++ b/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js @@ -0,0 +1,35 @@ +module.exports = Self => { + Self.remoteMethod('getUncheckedTicket', { + description: + 'Get boolean if the collection of ticket has a ticket not checked', + accessType: 'READ', + accepts: [{ + arg: 'ticketFk', + type: 'int', + required: true, + description: 'Ticket id' + }], + returns: { + type: 'boolean', + root: true + }, + http: { + path: `/getUncheckedTicket`, + verb: 'GET' + } + }); + + Self.getUncheckedTicket = async ticketFk => { + const result = await Self.rawSql(` + SELECT tc2.ticketFk + FROM vn.ticketCollection tc + JOIN vn.ticketCollection tc2 ON tc2.collectionFk = tc.collectionFk + LEFT JOIN vn.ticketState ts ON ts.ticketFk = tc2.ticketFk + JOIN vn.state s ON s.id = ts.stateFk + JOIN vn.state s2 ON s2.code = 'CHECKED' + WHERE tc.ticketFk = ? AND s.order < s2.id + LIMIT 1;`, + [ticketFk]); + return result.length > 0 && result[0]['ticketFk'] > 0; + }; +}; diff --git a/modules/ticket/back/models/ticket-collection.js b/modules/ticket/back/models/ticket-collection.js new file mode 100644 index 000000000..55920f2a2 --- /dev/null +++ b/modules/ticket/back/models/ticket-collection.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/ticket-collection/getUncheckedTicket')(Self); +}; -- 2.40.1 From caf99a97382a8bdfa9b8ac9044f67ddc31e91c52 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 26 Mar 2024 11:06:14 +0100 Subject: [PATCH 2/8] refs #3520 feat:uncheckedTicket --- .../back/methods/ticket-collection/getUncheckedTicket.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js index 64a4c563c..9eead967d 100644 --- a/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js +++ b/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js @@ -19,7 +19,12 @@ module.exports = Self => { } }); - Self.getUncheckedTicket = async ticketFk => { + Self.getUncheckedTicket = async(ticketFk, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + const result = await Self.rawSql(` SELECT tc2.ticketFk FROM vn.ticketCollection tc @@ -29,7 +34,7 @@ module.exports = Self => { JOIN vn.state s2 ON s2.code = 'CHECKED' WHERE tc.ticketFk = ? AND s.order < s2.id LIMIT 1;`, - [ticketFk]); + [ticketFk], myOptions); return result.length > 0 && result[0]['ticketFk'] > 0; }; }; -- 2.40.1 From b805a5de0a0cb4d3d6a1b64fff2864d7707eb4c2 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Tue, 26 Mar 2024 12:40:44 +0100 Subject: [PATCH 3/8] refs #3520 feat:uncheckedTicket --- ...checkedTicket.js => hasUncheckedTicket.js} | 4 +-- .../spec/hasUncheckedTicket.spec.js | 35 +++++++++++++++++++ .../ticket/back/models/ticket-collection.js | 2 +- 3 files changed, 38 insertions(+), 3 deletions(-) rename modules/ticket/back/methods/ticket-collection/{getUncheckedTicket.js => hasUncheckedTicket.js} (93%) create mode 100644 modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js diff --git a/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js similarity index 93% rename from modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js rename to modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js index 9eead967d..1c5174969 100644 --- a/modules/ticket/back/methods/ticket-collection/getUncheckedTicket.js +++ b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethod('getUncheckedTicket', { + Self.remoteMethod('hasUncheckedTicket', { description: 'Get boolean if the collection of ticket has a ticket not checked', accessType: 'READ', @@ -14,7 +14,7 @@ module.exports = Self => { root: true }, http: { - path: `/getUncheckedTicket`, + path: `/hasUncheckedTicket`, verb: 'GET' } }); diff --git a/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js new file mode 100644 index 000000000..02db364b2 --- /dev/null +++ b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js @@ -0,0 +1,35 @@ + +const {models} = require('vn-loopback/server/server'); + +describe('ticketCollection hasUncheckedTicket()', () => { + fit('should return false because there are not tickets not checked', async() => { + const ticketFk = 1; + const result = await models.TicketCollection.hasUncheckedTicket(ticketFk); + + expect(result).toBe(false); + }); + + it('should return true because there is a ticket not checked', async() => { + const ticketFk = 1; + + const tx = await models.TicketTracking.beginTransaction({}); + const myOptions = {transaction: tx}; + const filter = {where: { + ticketFk: 1, + stateFk: 16} + }; + try { + const ticketTracking = await models.TicketTracking.findOne(filter, myOptions); + await ticketTracking.updateAttributes({ + stateFk: 7 + }); + const result = await models.TicketCollection.hasUncheckedTicket(ticketFk, myOptions); + + expect(result).toBe(true); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/models/ticket-collection.js b/modules/ticket/back/models/ticket-collection.js index 55920f2a2..c5cd75a94 100644 --- a/modules/ticket/back/models/ticket-collection.js +++ b/modules/ticket/back/models/ticket-collection.js @@ -1,3 +1,3 @@ module.exports = Self => { - require('../methods/ticket-collection/getUncheckedTicket')(Self); + require('../methods/ticket-collection/hasUncheckedTicket')(Self); }; -- 2.40.1 From 39b1e9ff7bc77c68f57ca957e7c9c72879fb5740 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 27 Mar 2024 07:26:11 +0100 Subject: [PATCH 4/8] refs #3520 hasUncheckedTicket --- .../back/methods/ticket-collection/hasUncheckedTicket.js | 2 +- .../ticket-collection/spec/hasUncheckedTicket.spec.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js index 1c5174969..dc4da2ae6 100644 --- a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js +++ b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js @@ -19,7 +19,7 @@ module.exports = Self => { } }); - Self.getUncheckedTicket = async(ticketFk, options) => { + Self.hasUncheckedTicket = async(ticketFk, options) => { const myOptions = {}; if (typeof options == 'object') diff --git a/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js index 02db364b2..9f88b9f0b 100644 --- a/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js +++ b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js @@ -2,7 +2,7 @@ const {models} = require('vn-loopback/server/server'); describe('ticketCollection hasUncheckedTicket()', () => { - fit('should return false because there are not tickets not checked', async() => { + it('should return false because there are not tickets not checked', async() => { const ticketFk = 1; const result = await models.TicketCollection.hasUncheckedTicket(ticketFk); @@ -11,17 +11,19 @@ describe('ticketCollection hasUncheckedTicket()', () => { it('should return true because there is a ticket not checked', async() => { const ticketFk = 1; + const stateFkCurrent = 16; + const stateFkUpdated = 7; const tx = await models.TicketTracking.beginTransaction({}); const myOptions = {transaction: tx}; const filter = {where: { ticketFk: 1, - stateFk: 16} + stateFk: stateFkCurrent} }; try { const ticketTracking = await models.TicketTracking.findOne(filter, myOptions); await ticketTracking.updateAttributes({ - stateFk: 7 + stateFk: stateFkUpdated }); const result = await models.TicketCollection.hasUncheckedTicket(ticketFk, myOptions); -- 2.40.1 From a983f25c57f05020e965fb597cb4f724015fa140 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 27 Mar 2024 07:47:36 +0100 Subject: [PATCH 5/8] refs #3520 hasUncheckedTicket --- .../ticket/back/methods/ticket-collection/hasUncheckedTicket.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js index dc4da2ae6..6c8df250a 100644 --- a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js +++ b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js @@ -5,7 +5,7 @@ module.exports = Self => { accessType: 'READ', accepts: [{ arg: 'ticketFk', - type: 'int', + type: 'integer', required: true, description: 'Ticket id' }], -- 2.40.1 From 2cf572baf874850175ace84f2c27331bfb751ac2 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 27 Mar 2024 07:48:16 +0100 Subject: [PATCH 6/8] refs #3520 hasUncheckedTicket --- .../ticket-collection/hasUncheckedTicket.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js index 6c8df250a..1ea522de6 100644 --- a/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js +++ b/modules/ticket/back/methods/ticket-collection/hasUncheckedTicket.js @@ -27,13 +27,13 @@ module.exports = Self => { const result = await Self.rawSql(` SELECT tc2.ticketFk - FROM vn.ticketCollection tc - JOIN vn.ticketCollection tc2 ON tc2.collectionFk = tc.collectionFk - LEFT JOIN vn.ticketState ts ON ts.ticketFk = tc2.ticketFk - JOIN vn.state s ON s.id = ts.stateFk - JOIN vn.state s2 ON s2.code = 'CHECKED' - WHERE tc.ticketFk = ? AND s.order < s2.id - LIMIT 1;`, + FROM vn.ticketCollection tc + JOIN vn.ticketCollection tc2 ON tc2.collectionFk = tc.collectionFk + LEFT JOIN vn.ticketState ts ON ts.ticketFk = tc2.ticketFk + JOIN vn.state s ON s.id = ts.stateFk + JOIN vn.state s2 ON s2.code = 'CHECKED' + WHERE tc.ticketFk = ? AND s.order < s2.id + LIMIT 1;`, [ticketFk], myOptions); return result.length > 0 && result[0]['ticketFk'] > 0; }; -- 2.40.1 From 483345666ed9f09d54dc836c1512a11a20d31a34 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Wed, 27 Mar 2024 11:01:32 +0100 Subject: [PATCH 7/8] refs #3520 feat:back WarehouseFk --- modules/ticket/back/models/ticket-collection.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/ticket/back/models/ticket-collection.json b/modules/ticket/back/models/ticket-collection.json index 4bd34f08e..bc1c2dd18 100644 --- a/modules/ticket/back/models/ticket-collection.json +++ b/modules/ticket/back/models/ticket-collection.json @@ -13,6 +13,9 @@ }, "usedShelves": { "type": "number" + }, + "collectionFk": { + "type": "number" } }, "relations": { @@ -20,6 +23,11 @@ "type": "belongsTo", "model": "Ticket", "foreignKey": "ticketFk" + }, + "collection": { + "type": "belongsTo", + "model": "Collection", + "foreignKey": "collectionFk" } } } \ No newline at end of file -- 2.40.1 From 8e6416d59c2f61e24fc553187e1ae550a410e478 Mon Sep 17 00:00:00 2001 From: sergiodt Date: Thu, 28 Mar 2024 08:08:32 +0100 Subject: [PATCH 8/8] refs #3520 feat:uncheckedTicket --- .../methods/ticket-collection/spec/hasUncheckedTicket.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js index 9f88b9f0b..ae7a8e6ee 100644 --- a/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js +++ b/modules/ticket/back/methods/ticket-collection/spec/hasUncheckedTicket.spec.js @@ -24,7 +24,7 @@ describe('ticketCollection hasUncheckedTicket()', () => { const ticketTracking = await models.TicketTracking.findOne(filter, myOptions); await ticketTracking.updateAttributes({ stateFk: stateFkUpdated - }); + }, myOptions); const result = await models.TicketCollection.hasUncheckedTicket(ticketFk, myOptions); expect(result).toBe(true); @@ -35,3 +35,4 @@ describe('ticketCollection hasUncheckedTicket()', () => { } }); }); + -- 2.40.1