refactor: refs #6802 improve SQL procedure logic and clean up code formatting
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
5ff7234838
commit
d7fd35c6f6
|
@ -14,24 +14,22 @@ BEGIN
|
|||
FROM departmentManaExcluded
|
||||
WHERE departmentFk = vDepartmentFk;
|
||||
|
||||
IF vIsDepartmentExcluded THEN
|
||||
LEAVE whole_proc;
|
||||
IF NOT vIsDepartmentExcluded THEN
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.client
|
||||
SELECT id
|
||||
FROM client
|
||||
WHERE departmentFk = vDepartmentFk;
|
||||
|
||||
CALL client_getMana();
|
||||
|
||||
INSERT INTO departmentMana (departmentFk, amount)
|
||||
SELECT vDepartmentFk, SUM(mana)
|
||||
FROM tmp.clientMana
|
||||
ON DUPLICATE KEY UPDATE amount = VALUES(amount);
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.client,
|
||||
tmp.clientMana;
|
||||
END IF;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.client
|
||||
SELECT id
|
||||
FROM client
|
||||
WHERE departmentFk = vDepartmentFk;
|
||||
|
||||
CALL client_getMana();
|
||||
|
||||
INSERT INTO departmentMana (departmentFk, amount)
|
||||
SELECT vDepartmentFk, SUM(mana)
|
||||
FROM tmp.clientMana
|
||||
ON DUPLICATE KEY UPDATE amount = VALUES(amount);
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.client,
|
||||
tmp.clientMana;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -2,12 +2,12 @@ const models = require('vn-loopback/server/server').models;
|
|||
const LoopBackContext = require('loopback-context');
|
||||
|
||||
describe('invoiceOut delete()', () => {
|
||||
const invoiceOutId = 2;
|
||||
const invoiceOutId = 2;
|
||||
const userId = 106;
|
||||
const activeCtx = {
|
||||
accessToken: {userId: userId},
|
||||
};
|
||||
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||
active: activeCtx
|
||||
|
@ -19,7 +19,7 @@ describe('invoiceOut delete()', () => {
|
|||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
const invoiceOut = await models.InvoiceOut.findById(invoiceOutId , {}, options);
|
||||
const invoiceOut = await models.InvoiceOut.findById(invoiceOutId, {}, options);
|
||||
const tickets = await models.Ticket.find({where: {refFk: invoiceOut.ref}}, options);
|
||||
|
||||
expect(tickets.length).toEqual(1);
|
||||
|
@ -52,20 +52,20 @@ describe('invoiceOut delete()', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('should delete the corresponding bookEntry and not notify', async () => {
|
||||
it('should delete the corresponding bookEntry and not notify', async() => {
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
try {
|
||||
const filter = {
|
||||
where: {
|
||||
ASIEN: 2
|
||||
},
|
||||
fields: ['id', 'enlazadoSage']
|
||||
};
|
||||
|
||||
const [beforeXdiario] = await models.Xdiario.find(filter, options)
|
||||
|
||||
|
||||
const [beforeXdiario] = await models.Xdiario.find(filter, options);
|
||||
|
||||
const [beforeNotification] = await models.NotificationQueue.find({
|
||||
where: {
|
||||
notificationFk: 'book-entry-deleted',
|
||||
|
@ -74,16 +74,16 @@ describe('invoiceOut delete()', () => {
|
|||
}, options);
|
||||
|
||||
expect(beforeXdiario).toBeDefined();
|
||||
expect(beforeXdiario.enlazadoSage).toBeFalsy;
|
||||
expect(beforeXdiario.enlazadoSage).toBeFalsy();
|
||||
expect(beforeNotification).not.toBeDefined();
|
||||
|
||||
await models.InvoiceOut.delete(4, options);
|
||||
|
||||
|
||||
const [afterXdiario] = await models.Xdiario.find({
|
||||
where: {
|
||||
ASIEN: 2
|
||||
}
|
||||
}, options);
|
||||
}, options);
|
||||
|
||||
const [afterNotification] = await models.NotificationQueue.find({
|
||||
where: {
|
||||
|
@ -92,10 +92,10 @@ describe('invoiceOut delete()', () => {
|
|||
status: 'pending'
|
||||
}
|
||||
}, options);
|
||||
|
||||
|
||||
expect(afterXdiario).not.toBeDefined();
|
||||
expect(afterNotification).not.toBeDefined();
|
||||
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
|
@ -103,7 +103,7 @@ describe('invoiceOut delete()', () => {
|
|||
}
|
||||
});
|
||||
|
||||
it('should delete the corresponding bookEntry and notify', async () => {
|
||||
it('should delete the corresponding bookEntry and notify', async() => {
|
||||
const tx = await models.InvoiceOut.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
|
@ -114,9 +114,9 @@ describe('invoiceOut delete()', () => {
|
|||
},
|
||||
fields: ['id', 'enlazadoSage']
|
||||
};
|
||||
|
||||
const [beforeXdiario] = await models.Xdiario.find(filter, options)
|
||||
|
||||
|
||||
const [beforeXdiario] = await models.Xdiario.find(filter, options);
|
||||
|
||||
const [beforeNotification] = await models.NotificationQueue.find({
|
||||
where: {
|
||||
notificationFk: 'book-entry-deleted',
|
||||
|
@ -129,12 +129,12 @@ describe('invoiceOut delete()', () => {
|
|||
expect(beforeNotification).not.toBeDefined();
|
||||
|
||||
await models.InvoiceOut.delete(3, options);
|
||||
|
||||
|
||||
const [afterXdiario] = await models.Xdiario.find({
|
||||
where: {
|
||||
ASIEN: 1
|
||||
}
|
||||
}, options);
|
||||
}, options);
|
||||
|
||||
const [afterNotification] = await models.NotificationQueue.find({
|
||||
where: {
|
||||
|
@ -146,12 +146,11 @@ describe('invoiceOut delete()', () => {
|
|||
|
||||
expect(afterXdiario).not.toBeDefined();
|
||||
expect(afterNotification).toBeDefined();
|
||||
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue