2282 - Change stowaway state to FIXING
gitea/salix/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Joan Sanchez 2020-06-01 12:47:04 +02:00
parent b411f49805
commit 052c51cee5
2 changed files with 43 additions and 2 deletions

View File

@ -83,7 +83,7 @@ module.exports = Self => {
} }
const ticket = await models.Ticket.findById(id, { const ticket = await models.Ticket.findById(id, {
include: { include: [{
relation: 'client', relation: 'client',
scope: { scope: {
fields: ['id', 'salesPersonFk'], 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) {
models.TicketTracking.changeState(ctx, {
ticketFk: otherTicketId,
code: 'FIXING'
});
}
// Send notification to salesPerson // Send notification to salesPerson
const salesPerson = ticket.client().salesPerson(); const salesPerson = ticket.client().salesPerson();
if (salesPerson) { if (salesPerson) {

View File

@ -103,4 +103,27 @@ describe('ticket deleted()', () => {
expect(error.translateArgs[0]).toEqual(2); expect(error.translateArgs[0]).toEqual(2);
expect(error.message).toEqual('You must delete the claim id %d first'); expect(error.message).toEqual('You must delete the claim id %d first');
}); });
fit('should delete the ticket and change the state to "FIXING" to the stowaway ticket', async() => {
const ticketId = 16;
const ctx = {
req: {
accessToken: {userId: 106},
headers: {
origin: 'http://localhost:5000'
},
__: () => {}
}
};
let error;
try {
await app.models.Ticket.setDeleted(ctx, ticketId);
} catch (e) {
error = e;
}
expect(error.translateArgs[0]).toEqual(2);
expect(error.message).toEqual('You must delete the claim id %d first');
});
}); });