refactor(ticketSms): refs #6259 merge ticksms to clientsms
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
2185b4ddc0
commit
27a369bef4
|
@ -0,0 +1,25 @@
|
||||||
|
ALTER TABLE `vn`.`clientSms` ADD `ticketFk` int(11) NULL;
|
||||||
|
ALTER TABLE `vn`.`clientSms` ADD CONSTRAINT `clientSms_FK_2` FOREIGN KEY (`ticketFk`) REFERENCES `vn`.`ticket`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
INSERT INTO`vn`.`clientSms` (`clientFk`, `smsFk`, `ticketFk`)
|
||||||
|
SELECT `t`.`clientFk`, `s`.`smsFk`, `s`.`ticketFk`
|
||||||
|
FROM `vn`.`clientSms` `s`
|
||||||
|
JOIN `vn`.`ticket` `t` ON `t`.`id` = `s`.`ticketFk`;
|
||||||
|
|
||||||
|
RENAME TABLE `vn`.`ticketSms` TO `vn`.`ticketSms__`;
|
||||||
|
|
||||||
|
DELIMITER $$
|
||||||
|
CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`clientSms_beforeInsert`
|
||||||
|
BEFORE INSERT ON `clientSms`
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
DECLARE vTicketOwner INT;
|
||||||
|
|
||||||
|
SELECT clientFk INTO vTicketOwner
|
||||||
|
FROM ticket
|
||||||
|
WHERE id = NEW.ticketFk;
|
||||||
|
|
||||||
|
IF NOT NEW.clientFk = vTicketOwner THEN
|
||||||
|
CALL util.throw('Unable to send an SMS ticket to a client who is not the owner');
|
||||||
|
END IF;
|
||||||
|
END$$
|
|
@ -3009,3 +3009,17 @@ INSERT INTO `vn`.`invoiceCorrectionType` (`id`, `description`)
|
||||||
(1, 'Error in VAT calculation'),
|
(1, 'Error in VAT calculation'),
|
||||||
(2, 'Error in sales details'),
|
(2, 'Error in sales details'),
|
||||||
(3, 'Error in customer data');
|
(3, 'Error in customer data');
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`sms` (`id`, `senderFk`, `sender`, `destination`, `message`, `statusCode`, `status`, `created`)
|
||||||
|
VALUES (1, 66, '111111111', '0001111111111', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'OK', util.VN_CURDATE()),
|
||||||
|
(2, 66, '222222222', '0002222222222', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'PENDING', util.VN_CURDATE()),
|
||||||
|
(3, 66, '333333333', '0003333333333', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'ERROR', util.VN_CURDATE()),
|
||||||
|
(4, 66, '444444444', '0004444444444', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 0, 'OK', util.VN_CURDATE());
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`clientSms` (`id`, `clientFk`, `smsFk`, `ticketFk`)
|
||||||
|
VALUES(1, 1103, 1, NULL),
|
||||||
|
(2, 1103, 2, NULL),
|
||||||
|
(3, 1103, 3, 32),
|
||||||
|
(4, 1103, 4, 32),
|
||||||
|
(13, 1101, 1, NULL),
|
||||||
|
(14, 1101, 4, 27);
|
|
@ -113,9 +113,6 @@
|
||||||
"SageTransactionType": {
|
"SageTransactionType": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
"TicketSms": {
|
|
||||||
"dataSource": "vn"
|
|
||||||
},
|
|
||||||
"TpvError": {
|
"TpvError": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -21,6 +21,11 @@
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "Sms",
|
"model": "Sms",
|
||||||
"foreignKey": "smsFk"
|
"foreignKey": "smsFk"
|
||||||
|
},
|
||||||
|
"ticket": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Ticket",
|
||||||
|
"foreignKey": "ticketFk"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
{
|
|
||||||
"name": "TicketSms",
|
|
||||||
"base": "VnModel",
|
|
||||||
"options": {
|
|
||||||
"mysql": {
|
|
||||||
"table": "ticketSms"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"properties": {
|
|
||||||
"smsFk": {
|
|
||||||
"type": "number",
|
|
||||||
"id": true,
|
|
||||||
"description": "Identifier"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"relations": {
|
|
||||||
"ticket": {
|
|
||||||
"type": "belongsTo",
|
|
||||||
"model": "Ticket",
|
|
||||||
"foreignKey": "ticketFk"
|
|
||||||
},
|
|
||||||
"sms": {
|
|
||||||
"type": "belongsTo",
|
|
||||||
"model": "Sms",
|
|
||||||
"foreignKey": "smsFk"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -33,7 +33,9 @@ module.exports = Self => {
|
||||||
Self.sendSms = async(ctx, id, destination, message) => {
|
Self.sendSms = async(ctx, id, destination, message) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const sms = await models.Sms.send(ctx, destination, message);
|
const sms = await models.Sms.send(ctx, destination, message);
|
||||||
await models.TicketSms.create({
|
const {clientFk} = await models.Ticket.findById(id);
|
||||||
|
await models.ClientSms.create({
|
||||||
|
clientFk,
|
||||||
ticketFk: id,
|
ticketFk: id,
|
||||||
smsFk: sms.id
|
smsFk: sms.id
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,9 +17,9 @@ describe('ticket sendSms()', () => {
|
||||||
const filter = {
|
const filter = {
|
||||||
ticketFk: id
|
ticketFk: id
|
||||||
};
|
};
|
||||||
const ticketSms = await models.TicketSms.findOne(filter, options);
|
const clientSms = await models.ClientSms.findOne(filter, options);
|
||||||
|
|
||||||
expect(ticketSms.ticketFk).toEqual(id);
|
expect(clientSms.ticketFk).toEqual(id);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in New Issue