Merge pull request '4081-ticket.setDeleted' (#1003) from 4081-ticket.setDeleted into dev
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
Reviewed-on: #1003 Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
commit
b5cea244ca
|
@ -1129,19 +1129,17 @@ INSERT INTO `vn`.`collection`(`id`, `workerFk`, `stateFk`, `created`, `trainFk`)
|
||||||
(1, 1106, 5, DATE_ADD(util.VN_CURDATE(),INTERVAL +1 DAY), 1),
|
(1, 1106, 5, DATE_ADD(util.VN_CURDATE(),INTERVAL +1 DAY), 1),
|
||||||
(2, 1106, 14, util.VN_CURDATE(), 1);
|
(2, 1106, 14, util.VN_CURDATE(), 1);
|
||||||
|
|
||||||
INSERT INTO `vn`.`ticketCollection`(`id`, `ticketFk`, `collectionFk`)
|
INSERT INTO `vn`.`ticketCollection`(`ticketFk`, `collectionFk`, `level`)
|
||||||
VALUES
|
VALUES
|
||||||
(2, 2, 1),
|
(1, 1, 1),
|
||||||
(3, 3, 2);
|
(2, 1, NULL),
|
||||||
|
(3, 2, NULL),
|
||||||
|
(23, 1, NULL);
|
||||||
|
|
||||||
INSERT INTO `vn`.`parking` (`column`, `row`, `sectorFk`, `code`, `pickingOrder`)
|
INSERT INTO `vn`.`parking` (`column`, `row`, `sectorFk`, `code`, `pickingOrder`)
|
||||||
VALUES
|
VALUES
|
||||||
('100', '01', 1, '100-01', 1);
|
('100', '01', 1, '100-01', 1);
|
||||||
|
|
||||||
INSERT INTO `vn`.`ticketCollection` (`ticketFk`, `collectionFk`, `level`)
|
|
||||||
VALUES
|
|
||||||
(1, 1, 1);
|
|
||||||
|
|
||||||
INSERT INTO `vn`.`genus`(`id`, `name`)
|
INSERT INTO `vn`.`genus`(`id`, `name`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'Abelia'),
|
(1, 'Abelia'),
|
||||||
|
@ -2594,3 +2592,19 @@ INSERT INTO `vn`.`mdbVersion` (`app`, `branchFk`, `version`)
|
||||||
VALUES
|
VALUES
|
||||||
('tpv', 'test', '1'),
|
('tpv', 'test', '1'),
|
||||||
('lab', 'master', '1');
|
('lab', 'master', '1');
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`saleGroup` (`userFk`, `parkingFk`, `sectorFk`)
|
||||||
|
VALUES
|
||||||
|
(1, 1, 1);
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`saleGroupDetail` (`saleFk`, `saleGroupFk`)
|
||||||
|
VALUES
|
||||||
|
(31, 1);
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`sectorCollection` (`userFk`, `sectorFk`)
|
||||||
|
VALUES
|
||||||
|
(1, 1);
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`sectorCollectionSaleGroup` (`sectorCollectionFk`, `saleGroupFk`)
|
||||||
|
VALUES
|
||||||
|
(1, 1);
|
||||||
|
|
|
@ -142,6 +142,25 @@ module.exports = Self => {
|
||||||
|
|
||||||
const updatedTicket = await ticket.updateAttribute('isDeleted', true, myOptions);
|
const updatedTicket = await ticket.updateAttribute('isDeleted', true, myOptions);
|
||||||
|
|
||||||
|
const [ticketCollection] = await models.TicketCollection.find({
|
||||||
|
fields: ['id'],
|
||||||
|
where: {
|
||||||
|
ticketFk: ticket.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (ticketCollection)
|
||||||
|
await models.TicketCollection.destroyById(ticketCollection.id, myOptions);
|
||||||
|
|
||||||
|
await Self.rawSql(`
|
||||||
|
DELETE sc
|
||||||
|
FROM vn.saleGroup sg
|
||||||
|
JOIN vn.sectorCollectionSaleGroup scsg ON scsg.saleGroupFk = sg.id
|
||||||
|
JOIN vn.sectorCollection sc ON sc.id = scsg.sectorCollectionFk
|
||||||
|
JOIN vn.saleGroupDetail sgd ON sgd.saleGroupFk = sg.id
|
||||||
|
JOIN vn.sale s ON s.id = sgd.saleFk
|
||||||
|
WHERE s.ticketFk = ?;`, [ticket.id], myOptions);
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
return updatedTicket;
|
return updatedTicket;
|
||||||
|
|
|
@ -213,7 +213,7 @@ describe('ticket filter()', () => {
|
||||||
const filter = {};
|
const filter = {};
|
||||||
const result = await models.Ticket.filter(ctx, filter, options);
|
const result = await models.Ticket.filter(ctx, filter, options);
|
||||||
|
|
||||||
expect(result.length).toEqual(2);
|
expect(result.length).toEqual(3);
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -8,6 +8,12 @@ describe('ticket setDeleted()', () => {
|
||||||
accessToken: {userId: userId},
|
accessToken: {userId: userId},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
|
active: activeCtx
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should throw an error if the given ticket has a claim', async() => {
|
it('should throw an error if the given ticket has a claim', async() => {
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
|
||||||
|
@ -29,6 +35,70 @@ describe('ticket setDeleted()', () => {
|
||||||
expect(error.message).toEqual('You must delete the claim id %d first');
|
expect(error.message).toEqual('You must delete the claim id %d first');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should delete a sectorCollection row', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
headers: {origin: 'http://localhost:5000'},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ctx.req.__ = value => {
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
const ticketId = 23;
|
||||||
|
|
||||||
|
await models.Ticket.setDeleted(ctx, ticketId, options);
|
||||||
|
|
||||||
|
const [sectorCollection] = await models.Ticket.rawSql(
|
||||||
|
`SELECT COUNT(*) numberRows
|
||||||
|
FROM vn.sectorCollection`, [], options);
|
||||||
|
|
||||||
|
expect(sectorCollection.numberRows).toEqual(0);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should delete a ticketCollection row', async() => {
|
||||||
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
const ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {userId: 9},
|
||||||
|
headers: {origin: 'http://localhost:5000'},
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ctx.req.__ = value => {
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
const ticketId = 23;
|
||||||
|
|
||||||
|
await models.Ticket.setDeleted(ctx, ticketId, options);
|
||||||
|
|
||||||
|
const [ticketCollection] = await models.Ticket.rawSql(
|
||||||
|
`SELECT COUNT(*) numberRows
|
||||||
|
FROM vn.ticketCollection`, [], options);
|
||||||
|
|
||||||
|
expect(ticketCollection.numberRows).toEqual(3);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('should delete ticket, remove stowaway and itemshelving then change stowaway state to "FIXING" ', async() => {
|
it('should delete ticket, remove stowaway and itemshelving then change stowaway state to "FIXING" ', async() => {
|
||||||
pending('test excluded by task #3693');
|
pending('test excluded by task #3693');
|
||||||
const tx = await models.Ticket.beginTransaction({});
|
const tx = await models.Ticket.beginTransaction({});
|
||||||
|
|
|
@ -44,6 +44,9 @@
|
||||||
"Ticket": {
|
"Ticket": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
"TicketCollection": {
|
||||||
|
"dataSource": "vn"
|
||||||
|
},
|
||||||
"TicketDms": {
|
"TicketDms": {
|
||||||
"dataSource": "vn"
|
"dataSource": "vn"
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"name": "TicketCollection",
|
||||||
|
"base": "VnModel",
|
||||||
|
"options": {
|
||||||
|
"mysql": {
|
||||||
|
"table": "ticketCollection"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"id": true,
|
||||||
|
"type": "number"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"relations": {
|
||||||
|
"ticket": {
|
||||||
|
"type": "belongsTo",
|
||||||
|
"model": "Ticket",
|
||||||
|
"foreignKey": "ticketFk"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue