Merge branch 'dev' into 8387-itemTagCrudModel
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
46a22733e2
|
@ -157,4 +157,52 @@ describe('Address updateAddress', () => {
|
|||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should update ticket observations when updateObservations is true', async() => {
|
||||
const tx = await models.Client.beginTransaction({});
|
||||
const client = 1103;
|
||||
const address = 123;
|
||||
const ticket = 31;
|
||||
const observationType = 3;
|
||||
|
||||
const salesAssistantId = 21;
|
||||
const addressObservation = 'nuevo texto';
|
||||
const ticketObservation = 'texto a modificar';
|
||||
|
||||
try {
|
||||
const options = {transaction: tx};
|
||||
ctx.req.accessToken.userId = salesAssistantId;
|
||||
ctx.args = {
|
||||
updateObservations: true,
|
||||
incotermsFk: incotermsId,
|
||||
provinceFk: provinceId,
|
||||
customsAgentFk: customAgentOneId
|
||||
};
|
||||
|
||||
await models.AddressObservation.create({
|
||||
addressFk: address,
|
||||
observationTypeFk: observationType,
|
||||
description: addressObservation
|
||||
}, options);
|
||||
|
||||
await models.TicketObservation.create({
|
||||
ticketFk: ticket,
|
||||
observationTypeFk: observationType,
|
||||
description: ticketObservation
|
||||
}, options);
|
||||
|
||||
await models.Client.updateAddress(ctx, client, address, options);
|
||||
|
||||
const updatedObservation = await models.TicketObservation.findOne({
|
||||
where: {ticketFk: ticket, observationTypeFk: observationType}
|
||||
}, options);
|
||||
|
||||
expect(updatedObservation.description).toEqual(addressObservation);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -80,6 +80,10 @@ module.exports = function(Self) {
|
|||
{
|
||||
arg: 'latitude',
|
||||
type: 'any',
|
||||
},
|
||||
{
|
||||
arg: 'updateObservations',
|
||||
type: 'boolean'
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
|
@ -135,6 +139,17 @@ module.exports = function(Self) {
|
|||
delete args.ctx; // Remove unwanted properties
|
||||
|
||||
const updatedAddress = await address.updateAttributes(ctx.args, myOptions);
|
||||
if (args.updateObservations) {
|
||||
const ticket = await Self.rawSql(`
|
||||
UPDATE ticketObservation to2
|
||||
JOIN ticket t ON t.id = to2.ticketFk
|
||||
JOIN address a ON a.id = t.addressFk
|
||||
JOIN addressObservation ao ON ao.addressFk = a.id
|
||||
SET to2.description = ao.description
|
||||
WHERE ao.observationTypeFk = to2.observationTypeFk
|
||||
AND a.id = ?
|
||||
AND t.shipped >= util.VN_CURDATE()`, [addressId], myOptions);
|
||||
}
|
||||
|
||||
return updatedAddress;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue