Merge pull request '2282-setDeleted_stowaway' (#287) from 2282-setDeleted_stowaway into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-by: Bernat Exposito <bernat@verdnatura.es>
This commit is contained in:
Bernat Exposito 2020-06-02 08:24:59 +00:00
commit 0fe2212f64
3 changed files with 84 additions and 3 deletions

View File

@ -83,7 +83,7 @@ module.exports = Self => {
}
const ticket = await models.Ticket.findById(id, {
include: {
include: [{
relation: 'client',
scope: {
fields: ['id', 'salesPersonFk'],
@ -97,9 +97,27 @@ module.exports = Self => {
}
}
}
}
}, {
relation: 'ship'
}, {
relation: 'stowaway'
}]
});
// Change state to "fixing" if contains an stowaway
let otherTicketId;
if (ticket.stowaway())
otherTicketId = ticket.stowaway().shipFk;
else if (ticket.ship())
otherTicketId = ticket.ship().id;
if (otherTicketId) {
await models.TicketTracking.changeState(ctx, {
ticketFk: otherTicketId,
code: 'FIXING'
});
}
// Send notification to salesPerson
const salesPerson = ticket.client().salesPerson();
if (salesPerson) {

View File

@ -4,6 +4,7 @@ const models = app.models;
describe('ticket deleted()', () => {
let ticket;
let sale;
let deletedClaim;
beforeAll(async done => {
let originalTicket = await models.Ticket.findOne({where: {id: 16}});
@ -27,8 +28,36 @@ describe('ticket deleted()', () => {
});
afterAll(async done => {
const ticketId = 16;
const stowawayTicketId = 17;
const ctx = {
req: {
accessToken: {userId: 106},
headers: {
origin: 'http://localhost:5000'
},
__: () => {}
}
};
await models.Ticket.destroyById(ticket.id);
const stowaway = await models.Stowaway.findOne({
where: {
id: stowawayTicketId,
shipFk: ticketId
}
});
await stowaway.destroy();
await models.Claim.create(deletedClaim);
await models.TicketTracking.changeState(ctx, {
ticketFk: ticketId,
code: 'OK'
});
await models.TicketTracking.changeState(ctx, {
ticketFk: stowawayTicketId,
code: 'OK'
});
const orgTicket = await models.Ticket.findById(ticketId);
await orgTicket.updateAttribute('isDeleted', false);
done();
});
@ -103,4 +132,35 @@ describe('ticket deleted()', () => {
expect(error.translateArgs[0]).toEqual(2);
expect(error.message).toEqual('You must delete the claim id %d first');
});
it('should delete the ticket and change the state to "FIXING" to the stowaway ticket', async() => {
const ticketId = 16;
const claimIdToRemove = 2;
const stowawayTicketId = 17;
const ctx = {
req: {
accessToken: {userId: 106},
headers: {
origin: 'http://localhost:5000'
},
__: () => {}
}
};
await app.models.Stowaway.rawSql(`
INSERT INTO vn.stowaway(id, shipFk)
VALUES (?, ?)`, [stowawayTicketId, ticketId]);
deletedClaim = await app.models.Claim.findById(claimIdToRemove);
await app.models.Claim.destroyById(claimIdToRemove);
await app.models.Ticket.setDeleted(ctx, ticketId);
const stowawayTicket = await app.models.TicketState.findOne({
where: {
ticketFk: stowawayTicketId
}
});
expect(stowawayTicket.code).toEqual('FIXING');
});
});

View File

@ -17,6 +17,9 @@
},
"alertLevel": {
"type": "Number"
},
"code": {
"type": "string"
}
},
"relations": {