fix: refs #6731 fix ticketRequest #2364

Merged
jon merged 1 commits from 6731-fixTicketRequestLog into dev 2024-04-30 10:19:31 +00:00
8 changed files with 42 additions and 39 deletions

View File

@ -1,19 +0,0 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`ticketRequest_Add`(vDescription VARCHAR(255), vQuantity INT, vPrice DOUBLE, vTicketFk INT, vBuyerCode VARCHAR(3))
jgallego marked this conversation as resolved
Review

me extraña ver que se elimina un proc pero no veo la alternativa que se usará a partir de ahora

me extraña ver que se elimina un proc pero no veo la alternativa que se usará a partir de ahora
Review

Estuve buscando quien usaba ese procedimiento, y en salix y lilium no se usa. Busqué también en access y tampoco se usa ahí el procedimiento, por eso lo eliminé

Estuve buscando quien usaba ese procedimiento, y en salix y lilium no se usa. Busqué también en access y tampoco se usa ahí el procedimiento, por eso lo eliminé
Review

He seguido las instrucciones de https://wiki.verdnatura.es/index.php/Deprecar_objetos_de_las_BBDD para el procedimiento que eliminé, y he visto que tampoco se usa en hedera ni en vn.warehouse

He seguido las instrucciones de https://wiki.verdnatura.es/index.php/Deprecar_objetos_de_las_BBDD para el procedimiento que eliminé, y he visto que tampoco se usa en hedera ni en vn.warehouse
BEGIN
INSERT INTO vn.ticketRequest(description,
quantity,
price,
ticketFk,
buyerCode,
requesterFk)
VALUES(vDescription,
vQuantity,
vPrice,
vTicketFk,
vBuyerCode,
vn.getUser());
END$$
DELIMITER ;

View File

@ -14,7 +14,7 @@ BEGIN
END IF;
IF NEW.attenderFk IS NULL THEN
SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode);
SET NEW.attenderFk = (SELECT defaultAttenderFk FROM ticketConfig LIMIT 1);
END IF;
END$$
DELIMITER ;

View File

@ -12,9 +12,5 @@ BEGIN
IF NEW.salesPersonCode <> OLD.salesPersonCode THEN
SET NEW.requesterFk = (SELECT w.id FROM worker w WHERE w.code = NEW.salesPersonCode);
END IF;
IF NEW.buyerCode <> OLD.buyerCode THEN
SET NEW.attenderFk = (SELECT w.id FROM worker w WHERE w.code = NEW.buyerCode);
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,7 @@
-- Place your SQL code here
ALTER TABLE `vn`.`ticketRequest`
CHANGE IF EXISTS `buyerCode` `buyerCode__` varchar(3) NOT NULL COMMENT '@deprecated 2024-04-23 refs #6731 field not used';
ALTER TABLE `vn`.`ticketConfig` ADD COLUMN IF NOT EXISTS `defaultAttenderFk` int unsigned;
ALTER TABLE vn.ticketConfig ADD CONSTRAINT ticketConfig_worker_FK FOREIGN KEY (defaultAttenderFk) REFERENCES vn.worker(id);

View File

@ -92,9 +92,7 @@ describe('ticket-request confirm()', () => {
const request = await models.TicketRequest.findById(requestId, null, options);
expect(request.saleFk).toBeNull();
await request.updateAttributes({saleFk: 2}, options);
await request.updateAttributes({saleFk: 2});
ctx.args = {
itemFk: itemId,
id: requestId,
@ -102,7 +100,6 @@ describe('ticket-request confirm()', () => {
};
await models.TicketRequest.confirm(ctx, options);
await tx.rollback();
} catch (e) {
await tx.rollback();

View File

@ -23,6 +23,16 @@
},
"daysForWarningClaim": {
"type": "number"
},
"defaultAttenderFk": {
"type": "number"
}
},
"relations": {
"attender": {
"type": "belongsTo",
"model": "Worker",
"foreignKey": "defaultAttenderFk"
}
}
}

View File

@ -8,21 +8,21 @@ module.exports = function(Self) {
require('../methods/ticket-request/getItemTypeWorker')(Self);
Self.observe('before save', async function(ctx) {
if (ctx.isNewInstance) {
const loopBackContext = LoopBackContext.getCurrentContext();
const filter = {where: {id: loopBackContext.active.accessToken.userId}};
const models = Self.app.models;
const worker = await models.Worker.findOne(filter);
const instance = ctx.instance;
const attenderFk = instance?.attenderFk;
if (ctx.isNewInstance) {
instance.requesterFk = worker.id;
const httpCtx = {req: loopBackContext.active};
const httpRequest = httpCtx.req.http .req;
const $t = httpRequest.__;
const attenderId = instance.attenderFk;
if (attenderId) {
if (attenderFk) {
const ticket = await models.Ticket.findById(instance.ticketFk);
let messageText = 'New ticket request has been created';
if (instance.price)
@ -35,8 +35,20 @@ module.exports = function(Self) {
quantity: instance.quantity,
price: instance.price
});
await models.Chat.sendCheckingPresence(httpCtx, attenderId, message);
await models.Chat.sendCheckingPresence(httpCtx, attenderFk, message);
} else {
const {defaultAttenderFk} = await models.TicketConfig.findOne();
Object.assign(instance, {attenderFk: defaultAttenderFk});
}
}
});
Self.observe('after save', async function(ctx) {
const models = Self.app.models;
const instance = ctx.instance;
if (instance?.attenderFk === null && !ctx.isNewInstance) {
const {defaultAttenderFk} = await models.TicketConfig.findOne();
await models.TicketRequest.updateAll({id: instance.id}, {attenderFk: defaultAttenderFk});
}
});
};