Tarea #1501 ticket / delete
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat 2019-08-13 12:44:34 +02:00
parent 291578d86a
commit d9c63e3bc0
3 changed files with 20 additions and 17 deletions

View File

@ -13,7 +13,6 @@ describe('Claim action path', () => {
it('should import the claim', async() => { it('should import the claim', async() => {
const result = await nightmare const result = await nightmare
.wait(1000)
.waitToClick(selectors.claimAction.importClaimButton) .waitToClick(selectors.claimAction.importClaimButton)
.waitForLastSnackbar(); .waitForLastSnackbar();
@ -22,7 +21,6 @@ describe('Claim action path', () => {
it('should import the second importable ticket', async() => { it('should import the second importable ticket', async() => {
const result = await nightmare const result = await nightmare
.wait(1000)
.waitToClick(selectors.claimAction.importTicketButton) .waitToClick(selectors.claimAction.importTicketButton)
.waitToClick(selectors.claimAction.secondImportableTicket) .waitToClick(selectors.claimAction.secondImportableTicket)
.waitForLastSnackbar(); .waitForLastSnackbar();

View File

@ -21,9 +21,9 @@ module.exports = Self => {
}); });
Self.delete = async id => { Self.delete = async id => {
const tx = await Self.beginTransaction({}); const transaction = await Self.beginTransaction({});
try { try {
let options = {transaction: tx}; let options = {transaction: transaction};
let invoiceOut = await Self.findById(id); let invoiceOut = await Self.findById(id);
let tickets = await Self.app.models.Ticket.find({where: {refFk: invoiceOut.ref}}); let tickets = await Self.app.models.Ticket.find({where: {refFk: invoiceOut.ref}});
@ -35,10 +35,10 @@ module.exports = Self => {
await Promise.all(promises); await Promise.all(promises);
await invoiceOut.destroy(options); await invoiceOut.destroy(options);
await tx.commit(); await transaction.commit();
return tickets; return tickets;
} catch (e) { } catch (e) {
await tx.rollback(); await transaction.rollback();
throw e; throw e;
} }
}; };

View File

@ -22,6 +22,8 @@ module.exports = Self => {
}); });
Self.delete = async(ctx, params) => { Self.delete = async(ctx, params) => {
const transaction = await Self.beginTransaction({});
try {
let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}}); let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}});
if (claimOfATicket) if (claimOfATicket)
throw new UserError('You must delete the claim id %d first', 'DELETE_CLAIM_FIRST', claimOfATicket.id); throw new UserError('You must delete the claim id %d first', 'DELETE_CLAIM_FIRST', claimOfATicket.id);
@ -34,7 +36,10 @@ module.exports = Self => {
params.workerFk = worker.id; params.workerFk = worker.id;
let state = await Self.app.models.State.findOne({where: {code: 'ERASED'}}); let state = await Self.app.models.State.findOne({where: {code: 'ERASED'}});
return await Self.app.models.TicketTracking.create({ticketFk: params.id, stateFk: state.id, workerFk: params.workerFk}); return await Self.app.models.TicketTracking.create({ticketFk: params.id, stateFk: state.id, workerFk: params.workerFk});
} catch (e) {
await transaction.rollback();
throw e;
}
}; };
}; };