This commit is contained in:
parent
2e67ef4f5d
commit
db15285858
|
@ -13,6 +13,10 @@ module.exports = Self => {
|
||||||
http: {
|
http: {
|
||||||
path: `/deleteExpeditions`,
|
path: `/deleteExpeditions`,
|
||||||
verb: 'POST'
|
verb: 'POST'
|
||||||
|
},
|
||||||
|
returns: {
|
||||||
|
type: ['object'],
|
||||||
|
root: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -20,6 +24,7 @@ module.exports = Self => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const $t = ctx.req.__;
|
const $t = ctx.req.__;
|
||||||
const notDeletedExpeditions = [];
|
const notDeletedExpeditions = [];
|
||||||
|
const deletedExpeditions = [];
|
||||||
|
|
||||||
for (let expeditionId of expeditionIds) {
|
for (let expeditionId of expeditionIds) {
|
||||||
const filter = {
|
const filter = {
|
||||||
|
@ -43,16 +48,21 @@ module.exports = Self => {
|
||||||
if (code && code.toLowerCase().substring(0, 10) == 'viaexpress') {
|
if (code && code.toLowerCase().substring(0, 10) == 'viaexpress') {
|
||||||
const isDeleted = await models.ViaexpressConfig.deleteShipment(expeditionId);
|
const isDeleted = await models.ViaexpressConfig.deleteShipment(expeditionId);
|
||||||
|
|
||||||
if (isDeleted === 'true') await models.Expedition.destroyById(expeditionId);
|
if (isDeleted === 'true') {
|
||||||
|
const deletedExpedition = await models.Expedition.destroyById(expeditionId);
|
||||||
else notDeletedExpeditions.push(expeditionId);
|
deletedExpeditions.push(deletedExpedition);
|
||||||
} else
|
} else notDeletedExpeditions.push(expeditionId);
|
||||||
await models.Expedition.destroyById(expeditionId);
|
} else {
|
||||||
|
const deletedExpedition = await models.Expedition.destroyById(expeditionId);
|
||||||
|
deletedExpeditions.push(deletedExpedition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notDeletedExpeditions.length) {
|
if (notDeletedExpeditions.length) {
|
||||||
throw new UserError(
|
throw new UserError(
|
||||||
$t(`It was not able to remove the next expeditions:`, {expeditions: notDeletedExpeditions.join()})
|
$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');
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('ticket deleteExpeditions()', () => {
|
describe('ticket deleteExpeditions()', () => {
|
||||||
|
let ctx;
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
const activeCtx = {
|
ctx = {
|
||||||
accessToken: {userId: 9},
|
accessToken: {userId: 9},
|
||||||
http: {
|
req: {
|
||||||
req: {
|
headers: {origin: 'http://localhost'}
|
||||||
headers: {origin: 'http://localhost'}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
||||||
active: activeCtx
|
active: ctx
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -23,7 +22,7 @@ describe('ticket deleteExpeditions()', () => {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const expeditionIds = [12, 13];
|
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);
|
expect(result.length).toEqual(2);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue