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

View File

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

View File

@ -22,19 +22,24 @@ module.exports = Self => {
});
Self.delete = async(ctx, params) => {
let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}});
if (claimOfATicket)
throw new UserError('You must delete the claim id %d first', 'DELETE_CLAIM_FIRST', claimOfATicket.id);
const transaction = await Self.beginTransaction({});
try {
let claimOfATicket = await Self.app.models.Claim.findOne({where: {ticketFk: params.id}});
if (claimOfATicket)
throw new UserError('You must delete the claim id %d first', 'DELETE_CLAIM_FIRST', claimOfATicket.id);
let currentTicket = await Self.app.models.Ticket.findById(params.id);
await currentTicket.updateAttributes({isDeleted: true});
let currentTicket = await Self.app.models.Ticket.findById(params.id);
await currentTicket.updateAttributes({isDeleted: true});
let userId = ctx.req.accessToken.userId;
let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}});
params.workerFk = worker.id;
let state = await Self.app.models.State.findOne({where: {code: 'ERASED'}});
let userId = ctx.req.accessToken.userId;
let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}});
params.workerFk = worker.id;
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;
}
};
};