From fd58eaf8388daa990a071e19a876461a2c20f484 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 18 Nov 2022 09:36:38 +0100 Subject: [PATCH] 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`