From 5acbaf036a521cb6dcd2e971d933dcea7e56665d Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 15 Nov 2022 09:30:36 +0100 Subject: [PATCH 1/7] refs #3557 back and test done --- .../10503-november/00-sale_missingTrash.sql | 23 ++++++ .../ticket/back/methods/sale/missingTrash.js | 70 +++++++++++++++++++ .../methods/sale/specs/missingTrash.spec.js | 35 ++++++++++ modules/ticket/back/models/sale.js | 1 + 4 files changed, 129 insertions(+) create mode 100644 db/changes/10503-november/00-sale_missingTrash.sql create mode 100644 modules/ticket/back/methods/sale/missingTrash.js create mode 100644 modules/ticket/back/methods/sale/specs/missingTrash.spec.js diff --git a/db/changes/10503-november/00-sale_missingTrash.sql b/db/changes/10503-november/00-sale_missingTrash.sql new file mode 100644 index 000000000..f0de6d5cd --- /dev/null +++ b/db/changes/10503-november/00-sale_missingTrash.sql @@ -0,0 +1,23 @@ +DROP PROCEDURE IF EXISTS vn.sale_missingTrash; + +DELIMITER $$ +$$ +CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_missingTrash`( + vSaleFk BIGINT, + vQuantity INT, + vIsTrash BOOLEAN, + vWarehouseFk INT, + vNewQuantity INT) +/** + * Modifica la cantidad de una sale tirĂ¡ndola a faltas o basura + * + * @param vSaleFk el id de la sale + * @param vQuantity cantidad que se va a tirar a faltas o basura + * @param vIsTrash true si es basura, false si es faltas + * @param vWarehouseFk id warehouse + * @param vNewQuantity cantidad que se queda en el ticket original + */ +BEGIN + CALL vn.collection_missingTrash(vSaleFk ,vQuantity ,vIsTrash ,vWarehouseFk ,vNewQuantity); +END$$ +DELIMITER ; diff --git a/modules/ticket/back/methods/sale/missingTrash.js b/modules/ticket/back/methods/sale/missingTrash.js new file mode 100644 index 000000000..6d4f69178 --- /dev/null +++ b/modules/ticket/back/methods/sale/missingTrash.js @@ -0,0 +1,70 @@ +module.exports = Self => { + Self.remoteMethodCtx('missingTrash', { + description: 'Modify the amount of a sale by throwing it to faults or garbage', + accessType: 'WRITE', + accepts: [ + { + arg: 'saleFk', + type: 'number', + required: true, + description: 'The sale id' + }, + { + arg: 'quantity', + type: 'number', + required: true, + description: 'Quantity that is going to be thrown away' + }, + { + arg: 'isTrash', + type: 'boolean', + required: true, + description: 'True if garbage, false if fault' + }, + { + arg: 'warehouseFk', + type: 'number', + required: true, + description: 'The warehouse id' + }, + { + arg: 'newQuantity', + type: 'number', + required: true, + description: 'Amount remaining on the original ticket' + }, + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/missingTrash`, + verb: 'POST' + } + }); + + Self.missingTrash = async function (ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options) { + const myOptions = {}; + let tx; + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const missingTrash = await Self.rawSql(`CALL vn.sale_missingTrash(?, ?, ?, ?, ?)`, + [saleFk, quantity, isTrash, warehouseFk, newQuantity], myOptions); + + if (tx) await tx.commit(); + + return missingTrash; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js new file mode 100644 index 000000000..62fd74343 --- /dev/null +++ b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js @@ -0,0 +1,35 @@ +const models = require('vn-loopback/server/server').models; + +fdescribe('sale missingTrash()', () => { + it('should modify the amount of a sale by throwing it to faults or garbage', async () => { + const tx = await models.Sale.beginTransaction({}); + + try { + const options = { transaction: tx }; + + const saleFk = 1; + const quantity = 3; + const isTrash = true; + const warehouseFk = 1; + const newQuantity = 2; + + const ctx = { req: { accessToken: { userId: 9 } } }; + + let sale = await models.Sale.findById(saleFk, null, options); + expect(sale.quantity).toEqual(5); + expect(sale.originalQuantity).toBe(null); + + await models.Sale.missingTrash(ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options); + + sale = await models.Sale.findById(saleFk, null, options); + expect(sale.quantity).toEqual(2); + expect(sale.originalQuantity).toBe(5); + + await tx.rollback(); + + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index ae247fc24..cb8814e67 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -9,6 +9,7 @@ module.exports = Self => { require('../methods/sale/refund')(Self); require('../methods/sale/canEdit')(Self); require('../methods/sale/usesMana')(Self); + require('../methods/sale/missingTrash')(Self); Self.validatesPresenceOf('concept', { message: `Concept cannot be blank` From 3dd43d21aef8412f511839d5ef4f3147c613a8ce Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 15 Nov 2022 09:37:26 +0100 Subject: [PATCH 2/7] fix test --- modules/ticket/back/methods/sale/specs/missingTrash.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js index 62fd74343..4dbe2588c 100644 --- a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js +++ b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js @@ -1,6 +1,6 @@ const models = require('vn-loopback/server/server').models; -fdescribe('sale missingTrash()', () => { +describe('sale missingTrash()', () => { it('should modify the amount of a sale by throwing it to faults or garbage', async () => { const tx = await models.Sale.beginTransaction({}); From e4a6585b6af91fff3192cf1819a6b4b27d9c3fb0 Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 16 Nov 2022 13:46:16 +0100 Subject: [PATCH 3/7] fix test back --- .../10503-november/00-sale_missingTrash.sql | 4 ++++ db/changes/10503-november/delete.keep | 0 .../methods/sale/specs/missingTrash.spec.js | 21 +++++++++---------- 3 files changed, 14 insertions(+), 11 deletions(-) delete mode 100644 db/changes/10503-november/delete.keep diff --git a/db/changes/10503-november/00-sale_missingTrash.sql b/db/changes/10503-november/00-sale_missingTrash.sql index f0de6d5cd..8c1bcaed3 100644 --- a/db/changes/10503-november/00-sale_missingTrash.sql +++ b/db/changes/10503-november/00-sale_missingTrash.sql @@ -21,3 +21,7 @@ BEGIN CALL vn.collection_missingTrash(vSaleFk ,vQuantity ,vIsTrash ,vWarehouseFk ,vNewQuantity); END$$ DELIMITER ; + +INSERT INTO `salix`.`ACL` +(model, property, accessType, permission, principalType, principalId) +VALUES('Sale', 'missingTrash', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/changes/10503-november/delete.keep b/db/changes/10503-november/delete.keep deleted file mode 100644 index e69de29bb..000000000 diff --git a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js index 4dbe2588c..490ad7e0e 100644 --- a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js +++ b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js @@ -7,23 +7,22 @@ describe('sale missingTrash()', () => { try { const options = { transaction: tx }; - const saleFk = 1; - const quantity = 3; + const quantity = 1; const isTrash = true; - const warehouseFk = 1; - const newQuantity = 2; const ctx = { req: { accessToken: { userId: 9 } } }; - let sale = await models.Sale.findById(saleFk, null, options); - expect(sale.quantity).toEqual(5); - expect(sale.originalQuantity).toBe(null); + const sale = await models.Sale.findOne({fields: ['id','quantity', 'originalQuantity', 'ticketFk']}, options); + console.log(sale); + const ticket = await models.Ticket.findById(sale.ticketFk, {fields: ['warehouseFk']}, options); + console.log(ticket); + const newQuantity = sale.quantity-quantity; - await models.Sale.missingTrash(ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options); + await models.Sale.missingTrash(ctx, sale.id, quantity, isTrash, ticket.warehouseFk, newQuantity, options); - sale = await models.Sale.findById(saleFk, null, options); - expect(sale.quantity).toEqual(2); - expect(sale.originalQuantity).toBe(5); + const saleAfter = await models.Sale.findById(sale.id, {fields: ['quantity', 'originalQuantity']}, options); + expect(saleAfter.quantity).toEqual(newQuantity); + expect(saleAfter.originalQuantity).toBe(sale.quantity); await tx.rollback(); From 153cb48ff0fa25e505a4825a94408a4372c0318d Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 17 Nov 2022 08:55:35 +0100 Subject: [PATCH 4/7] fix test --- db/dump/fixtures.sql | 4 +-- .../ticket/back/methods/sale/missingTrash.js | 2 +- .../methods/sale/specs/missingTrash.spec.js | 35 ++++++++++++++----- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 49cf639ef..98c15075e 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -333,7 +333,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (1109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist'), (1110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist'), (1111, 'Missing', NULL, 'Missing man', 'Anton', 'The space, Universe far away', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL), - (1112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city, Underground', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL); + (1112, 'Trash', '12345678Z', 'Garbage man', 'Unknown name', 'New York city, Underground', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 @@ -2701,7 +2701,7 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) VALUES (1, 9); - + INSERT INTO `vn`.`productionConfig` (`isPreviousPreparationRequired`, `ticketPrintedMax`, `ticketTrolleyMax`, `rookieDays`, `notBuyingMonths`, `id`, `isZoneClosedByExpeditionActivated`, `maxNotReadyCollections`, `minTicketsToCloseZone`, `movingTicketDelRoute`, `defaultZone`, `defautlAgencyMode`, `hasUniqueCollectionTime`, `maxCollectionWithoutUser`, `pendingCollectionsOrder`, `pendingCollectionsAge`) VALUES (0, 8, 80, 0, 0, 1, 0, 15, 25, -1, 697, 1328, 0, 1, 8, 6); diff --git a/modules/ticket/back/methods/sale/missingTrash.js b/modules/ticket/back/methods/sale/missingTrash.js index 6d4f69178..4ff37eb1f 100644 --- a/modules/ticket/back/methods/sale/missingTrash.js +++ b/modules/ticket/back/methods/sale/missingTrash.js @@ -44,7 +44,7 @@ module.exports = Self => { } }); - Self.missingTrash = async function (ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options) { + Self.missingTrash = async function(ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options) { const myOptions = {}; let tx; if (typeof options == 'object') diff --git a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js index 490ad7e0e..dcc59333d 100644 --- a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js +++ b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js @@ -1,31 +1,50 @@ const models = require('vn-loopback/server/server').models; +const LoopBackContext = require('loopback-context'); describe('sale missingTrash()', () => { - it('should modify the amount of a sale by throwing it to faults or garbage', async () => { + const activeCtx = { + accessToken: {userId: 9}, + headers: {origin: 'localhost:5000'}, + __: () => {} + }; + + const ctx = { + req: activeCtx + }; + + beforeEach(() => { + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + }); + + it('should modify the amount of a sale by throwing it to faults or garbage', async() => { const tx = await models.Sale.beginTransaction({}); try { - const options = { transaction: tx }; + const options = {transaction: tx}; const quantity = 1; const isTrash = true; - const ctx = { req: { accessToken: { userId: 9 } } }; + const trashClient = await models.Client.findOne({where: {name: 'Trash'}}, options); + await trashClient.updateAttribute('name', 'BASURA', options); + + const sale = await models.Sale.findOne({fields: ['id', 'quantity', 'originalQuantity', 'ticketFk']} + , options); - const sale = await models.Sale.findOne({fields: ['id','quantity', 'originalQuantity', 'ticketFk']}, options); - console.log(sale); const ticket = await models.Ticket.findById(sale.ticketFk, {fields: ['warehouseFk']}, options); - console.log(ticket); - const newQuantity = sale.quantity-quantity; + + const newQuantity = sale.quantity - quantity; await models.Sale.missingTrash(ctx, sale.id, quantity, isTrash, ticket.warehouseFk, newQuantity, options); const saleAfter = await models.Sale.findById(sale.id, {fields: ['quantity', 'originalQuantity']}, options); + expect(saleAfter.quantity).toEqual(newQuantity); expect(saleAfter.originalQuantity).toBe(sale.quantity); await tx.rollback(); - } catch (e) { await tx.rollback(); throw e; From fd58eaf8388daa990a071e19a876461a2c20f484 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 18 Nov 2022 09:36:38 +0100 Subject: [PATCH 5/7] drop procedure --- .../00-collection_missingTrash.sql | 1 + .../10503-november/00-sale_missingTrash.sql | 27 ------- db/dump/fixtures.sql | 2 +- .../ticket/back/methods/sale/missingTrash.js | 70 ------------------- .../methods/sale/specs/missingTrash.spec.js | 53 -------------- modules/ticket/back/models/sale.js | 1 - 6 files changed, 2 insertions(+), 152 deletions(-) create mode 100644 db/changes/10503-november/00-collection_missingTrash.sql delete mode 100644 db/changes/10503-november/00-sale_missingTrash.sql delete mode 100644 modules/ticket/back/methods/sale/missingTrash.js delete mode 100644 modules/ticket/back/methods/sale/specs/missingTrash.spec.js diff --git a/db/changes/10503-november/00-collection_missingTrash.sql b/db/changes/10503-november/00-collection_missingTrash.sql new file mode 100644 index 000000000..d4467c699 --- /dev/null +++ b/db/changes/10503-november/00-collection_missingTrash.sql @@ -0,0 +1 @@ +DROP PROCEDURE IF EXISTS `vn`.`collection_missingTrash`; diff --git a/db/changes/10503-november/00-sale_missingTrash.sql b/db/changes/10503-november/00-sale_missingTrash.sql deleted file mode 100644 index 8c1bcaed3..000000000 --- a/db/changes/10503-november/00-sale_missingTrash.sql +++ /dev/null @@ -1,27 +0,0 @@ -DROP PROCEDURE IF EXISTS vn.sale_missingTrash; - -DELIMITER $$ -$$ -CREATE DEFINER=`root`@`localhost` PROCEDURE `vn`.`sale_missingTrash`( - vSaleFk BIGINT, - vQuantity INT, - vIsTrash BOOLEAN, - vWarehouseFk INT, - vNewQuantity INT) -/** - * Modifica la cantidad de una sale tirĂ¡ndola a faltas o basura - * - * @param vSaleFk el id de la sale - * @param vQuantity cantidad que se va a tirar a faltas o basura - * @param vIsTrash true si es basura, false si es faltas - * @param vWarehouseFk id warehouse - * @param vNewQuantity cantidad que se queda en el ticket original - */ -BEGIN - CALL vn.collection_missingTrash(vSaleFk ,vQuantity ,vIsTrash ,vWarehouseFk ,vNewQuantity); -END$$ -DELIMITER ; - -INSERT INTO `salix`.`ACL` -(model, property, accessType, permission, principalType, principalId) -VALUES('Sale', 'missingTrash', 'WRITE', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 98c15075e..a436c7572 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -333,7 +333,7 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (1109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Gotham', 46460, 1111111111, 222222222, 1, 'BruceBanner@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, 0, NULL, 0, 0, 9, 0, 1, 'florist'), (1110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Gotham', 46460, 1111111111, 222222222, 1, 'JessicaJones@mydomain.com', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 1, 1, 1, 0, 0, NULL, 0, 0, NULL, 0, 1, 'florist'), (1111, 'Missing', NULL, 'Missing man', 'Anton', 'The space, Universe far away', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL), - (1112, 'Trash', '12345678Z', 'Garbage man', 'Unknown name', 'New York city, Underground', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL); + (1112, 'Trash', NULL, 'Garbage man', 'Unknown name', 'New York city, Underground', 'Gotham', 46460, 1111111111, 222222222, 1, NULL, NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1, NULL, 10, 5, util.VN_CURDATE(), 1, 5, 1, 1, 1, '0000-00-00', 4, 1, 0, 1, 0, NULL, 1, 0, NULL, 0, 1, NULL); INSERT INTO `vn`.`client`(`id`, `name`, `fi`, `socialName`, `contact`, `street`, `city`, `postcode`, `isRelevant`, `email`, `iban`,`dueDay`,`accountingAccount`, `isEqualizated`, `provinceFk`, `hasToInvoice`, `credit`, `countryFk`, `isActive`, `gestdocFk`, `quality`, `payMethodFk`,`created`, `isTaxDataChecked`) SELECT id, name, CONCAT(RPAD(CONCAT(id,9),8,id),'A'), CONCAT(name, 'Social'), CONCAT(name, 'Contact'), CONCAT(name, 'Street'), 'GOTHAM', 46460, 1, CONCAT(name,'@mydomain.com'), NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5, util.VN_CURDATE(), 1 diff --git a/modules/ticket/back/methods/sale/missingTrash.js b/modules/ticket/back/methods/sale/missingTrash.js deleted file mode 100644 index 4ff37eb1f..000000000 --- a/modules/ticket/back/methods/sale/missingTrash.js +++ /dev/null @@ -1,70 +0,0 @@ -module.exports = Self => { - Self.remoteMethodCtx('missingTrash', { - description: 'Modify the amount of a sale by throwing it to faults or garbage', - accessType: 'WRITE', - accepts: [ - { - arg: 'saleFk', - type: 'number', - required: true, - description: 'The sale id' - }, - { - arg: 'quantity', - type: 'number', - required: true, - description: 'Quantity that is going to be thrown away' - }, - { - arg: 'isTrash', - type: 'boolean', - required: true, - description: 'True if garbage, false if fault' - }, - { - arg: 'warehouseFk', - type: 'number', - required: true, - description: 'The warehouse id' - }, - { - arg: 'newQuantity', - type: 'number', - required: true, - description: 'Amount remaining on the original ticket' - }, - ], - returns: { - type: ['object'], - root: true - }, - http: { - path: `/missingTrash`, - verb: 'POST' - } - }); - - Self.missingTrash = async function(ctx, saleFk, quantity, isTrash, warehouseFk, newQuantity, options) { - const myOptions = {}; - let tx; - if (typeof options == 'object') - Object.assign(myOptions, options); - - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - - try { - const missingTrash = await Self.rawSql(`CALL vn.sale_missingTrash(?, ?, ?, ?, ?)`, - [saleFk, quantity, isTrash, warehouseFk, newQuantity], myOptions); - - if (tx) await tx.commit(); - - return missingTrash; - } catch (e) { - if (tx) await tx.rollback(); - throw e; - } - }; -}; diff --git a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js b/modules/ticket/back/methods/sale/specs/missingTrash.spec.js deleted file mode 100644 index dcc59333d..000000000 --- a/modules/ticket/back/methods/sale/specs/missingTrash.spec.js +++ /dev/null @@ -1,53 +0,0 @@ -const models = require('vn-loopback/server/server').models; -const LoopBackContext = require('loopback-context'); - -describe('sale missingTrash()', () => { - const activeCtx = { - accessToken: {userId: 9}, - headers: {origin: 'localhost:5000'}, - __: () => {} - }; - - const ctx = { - req: activeCtx - }; - - beforeEach(() => { - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ - active: activeCtx - }); - }); - - it('should modify the amount of a sale by throwing it to faults or garbage', async() => { - const tx = await models.Sale.beginTransaction({}); - - try { - const options = {transaction: tx}; - - const quantity = 1; - const isTrash = true; - - const trashClient = await models.Client.findOne({where: {name: 'Trash'}}, options); - await trashClient.updateAttribute('name', 'BASURA', options); - - const sale = await models.Sale.findOne({fields: ['id', 'quantity', 'originalQuantity', 'ticketFk']} - , options); - - const ticket = await models.Ticket.findById(sale.ticketFk, {fields: ['warehouseFk']}, options); - - const newQuantity = sale.quantity - quantity; - - await models.Sale.missingTrash(ctx, sale.id, quantity, isTrash, ticket.warehouseFk, newQuantity, options); - - const saleAfter = await models.Sale.findById(sale.id, {fields: ['quantity', 'originalQuantity']}, options); - - expect(saleAfter.quantity).toEqual(newQuantity); - expect(saleAfter.originalQuantity).toBe(sale.quantity); - - await tx.rollback(); - } catch (e) { - await tx.rollback(); - throw e; - } - }); -}); diff --git a/modules/ticket/back/models/sale.js b/modules/ticket/back/models/sale.js index cb8814e67..ae247fc24 100644 --- a/modules/ticket/back/models/sale.js +++ b/modules/ticket/back/models/sale.js @@ -9,7 +9,6 @@ module.exports = Self => { require('../methods/sale/refund')(Self); require('../methods/sale/canEdit')(Self); require('../methods/sale/usesMana')(Self); - require('../methods/sale/missingTrash')(Self); Self.validatesPresenceOf('concept', { message: `Concept cannot be blank` From 67f03469807df1e1025720c9414d4c63b6534fdd Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 18 Nov 2022 09:37:38 +0100 Subject: [PATCH 6/7] space fixtures --- db/dump/fixtures.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index a436c7572..c766bdee5 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2701,7 +2701,6 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) VALUES (1, 9); - INSERT INTO `vn`.`productionConfig` (`isPreviousPreparationRequired`, `ticketPrintedMax`, `ticketTrolleyMax`, `rookieDays`, `notBuyingMonths`, `id`, `isZoneClosedByExpeditionActivated`, `maxNotReadyCollections`, `minTicketsToCloseZone`, `movingTicketDelRoute`, `defaultZone`, `defautlAgencyMode`, `hasUniqueCollectionTime`, `maxCollectionWithoutUser`, `pendingCollectionsOrder`, `pendingCollectionsAge`) VALUES (0, 8, 80, 0, 0, 1, 0, 15, 25, -1, 697, 1328, 0, 1, 8, 6); From a952fc0330b61fed1fdd5df994bbe62296c61823 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 18 Nov 2022 09:38:22 +0100 Subject: [PATCH 7/7] space fixtures --- db/dump/fixtures.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index c766bdee5..a436c7572 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2701,6 +2701,7 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) VALUES (1, 9); + INSERT INTO `vn`.`productionConfig` (`isPreviousPreparationRequired`, `ticketPrintedMax`, `ticketTrolleyMax`, `rookieDays`, `notBuyingMonths`, `id`, `isZoneClosedByExpeditionActivated`, `maxNotReadyCollections`, `minTicketsToCloseZone`, `movingTicketDelRoute`, `defaultZone`, `defautlAgencyMode`, `hasUniqueCollectionTime`, `maxCollectionWithoutUser`, `pendingCollectionsOrder`, `pendingCollectionsAge`) VALUES (0, 8, 80, 0, 0, 1, 0, 15, 25, -1, 697, 1328, 0, 1, 8, 6);