refs #5811 feat: al borrar expedicion borrar de viaexpress #1754

Merged
jorgep merged 15 commits from 5811-ticket.expedition_deleteViaexpress into dev 2023-11-27 07:36:28 +00:00
2 changed files with 21 additions and 12 deletions
Showing only changes of commit db15285858 - Show all commits

View File

@ -13,6 +13,10 @@ module.exports = Self => {
http: {
path: `/deleteExpeditions`,
verb: 'POST'
},
returns: {
type: ['object'],
root: true
}
});
@ -20,6 +24,7 @@ module.exports = Self => {
const models = Self.app.models;
const $t = ctx.req.__;
const notDeletedExpeditions = [];
const deletedExpeditions = [];
for (let expeditionId of expeditionIds) {
const filter = {
@ -43,16 +48,21 @@ module.exports = Self => {
if (code && code.toLowerCase().substring(0, 10) == 'viaexpress') {
const isDeleted = await models.ViaexpressConfig.deleteShipment(expeditionId);
if (isDeleted === 'true') await models.Expedition.destroyById(expeditionId);
else notDeletedExpeditions.push(expeditionId);
} else
await models.Expedition.destroyById(expeditionId);
if (isDeleted === 'true') {
const deletedExpedition = await models.Expedition.destroyById(expeditionId);
deletedExpeditions.push(deletedExpedition);
} else notDeletedExpeditions.push(expeditionId);
} else {
const deletedExpedition = await models.Expedition.destroyById(expeditionId);
deletedExpeditions.push(deletedExpedition);
}
}
if (notDeletedExpeditions.length) {
throw new UserError(
$t(`It was not able to remove the next expeditions:`, {expeditions: notDeletedExpeditions.join()})
);
}
return deletedExpeditions;
};
};

View File

@ -2,17 +2,16 @@ const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context');
describe('ticket deleteExpeditions()', () => {
let ctx;
beforeAll(async() => {
const activeCtx = {
ctx = {
accessToken: {userId: 9},
http: {
req: {
headers: {origin: 'http://localhost'}
}
req: {
headers: {origin: 'http://localhost'}
}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx
active: ctx
});
});
@ -23,7 +22,7 @@ describe('ticket deleteExpeditions()', () => {
const options = {transaction: tx};
const expeditionIds = [12, 13];
const result = await models.Expedition.deleteExpeditions(expeditionIds, options);
const result = await models.Expedition.deleteExpeditions(ctx, expeditionIds, options);
expect(result.length).toEqual(2);