This commit is contained in:
parent
2e67ef4f5d
commit
db15285858
|
@ -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;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue