refs #5811 delete viaexpress expeditions included
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
6580896dcd
commit
900dffbbba
|
@ -1,4 +1,6 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/viaexpress-config/internationalExpedition')(Self);
|
require('../methods/viaexpress-config/internationalExpedition')(Self);
|
||||||
require('../methods/viaexpress-config/renderer')(Self);
|
require('../methods/viaexpress-config/renderer')(Self);
|
||||||
|
require('../methods/viaexpress-config/deleteShipment')(Self);
|
||||||
|
require('../methods/viaexpress-config/deleteShipmentRenderer')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -199,5 +199,6 @@
|
||||||
"You can only add negative amounts in refund tickets": "You can only add negative amounts in refund tickets",
|
"You can only add negative amounts in refund tickets": "You can only add negative amounts in refund tickets",
|
||||||
"Try again": "Try again",
|
"Try again": "Try again",
|
||||||
"keepPrice": "keepPrice",
|
"keepPrice": "keepPrice",
|
||||||
"Cannot past travels with entries": "Cannot past travels with entries"
|
"Cannot past travels with entries": "Cannot past travels with entries",
|
||||||
|
"It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}"
|
||||||
}
|
}
|
|
@ -328,5 +328,6 @@
|
||||||
"User disabled": "Usuario desactivado",
|
"User disabled": "Usuario desactivado",
|
||||||
"The amount cannot be less than the minimum": "La cantidad no puede ser menor que la cantidad mínima",
|
"The amount cannot be less than the minimum": "La cantidad no puede ser menor que la cantidad mínima",
|
||||||
"quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima",
|
"quantityLessThanMin": "La cantidad no puede ser menor que la cantidad mínima",
|
||||||
"Cannot past travels with entries": "No se pueden pasar envíos con entradas"
|
"Cannot past travels with entries": "No se pueden pasar envíos con entradas",
|
||||||
|
"It was not able to remove the next expeditions:": "No se pudo eliminar las siguientes expediciones: {{expeditions}}"
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('deleteExpeditions', {
|
Self.remoteMethodCtx('deleteExpeditions', {
|
||||||
description: 'Delete the selected expeditions',
|
description: 'Delete the selected expeditions',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
|
@ -9,44 +10,51 @@ module.exports = Self => {
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The expeditions ids to delete'
|
description: 'The expeditions ids to delete'
|
||||||
}],
|
}],
|
||||||
returns: {
|
|
||||||
type: ['object'],
|
|
||||||
root: true
|
|
||||||
},
|
|
||||||
http: {
|
http: {
|
||||||
path: `/deleteExpeditions`,
|
path: `/deleteExpeditions`,
|
||||||
verb: 'POST'
|
verb: 'POST'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.deleteExpeditions = async(expeditionIds, options) => {
|
Self.deleteExpeditions = async(ctx, expeditionIds) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const myOptions = {};
|
const $t = ctx.req.__;
|
||||||
let tx;
|
const notDeletedExpeditions = [];
|
||||||
|
|
||||||
if (typeof options == 'object')
|
|
||||||
Object.assign(myOptions, options);
|
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
|
||||||
tx = await Self.beginTransaction({});
|
|
||||||
myOptions.transaction = tx;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const promises = [];
|
|
||||||
for (let expeditionId of expeditionIds) {
|
for (let expeditionId of expeditionIds) {
|
||||||
const deletedExpedition = models.Expedition.destroyById(expeditionId, myOptions);
|
const filter = {
|
||||||
promises.push(deletedExpedition);
|
fields: [],
|
||||||
|
where: {
|
||||||
|
id: expeditionId
|
||||||
|
},
|
||||||
|
include: [
|
||||||
|
{
|
||||||
|
relation: 'agencyMode',
|
||||||
|
scope: {
|
||||||
|
fields: ['code'],
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
const deletedExpeditions = await Promise.all(promises);
|
const expedition = await models.Expedition.findOne(filter);
|
||||||
|
const {code} = expedition.agencyMode();
|
||||||
|
|
||||||
if (tx) await tx.commit();
|
if (code && code.toLowerCase().substring(0, 10) == 'viaexpress') {
|
||||||
|
const isDeleted = await models.ViaexpressConfig.deleteShipment(expeditionId);
|
||||||
|
|
||||||
return deletedExpeditions;
|
if (isDeleted === 'true')
|
||||||
} catch (e) {
|
await models.Expedition.destroyById(expeditionId);
|
||||||
if (tx) await tx.rollback();
|
|
||||||
throw e;
|
else if (!isDeleted)
|
||||||
|
notDeletedExpeditions.push(expeditionId);
|
||||||
|
} else
|
||||||
|
await models.Expedition.destroyById(expeditionId);
|
||||||
|
}
|
||||||
|
if (notDeletedExpeditions.length) {
|
||||||
|
throw new UserError(
|
||||||
|
$t(`It was not able to remove the next expeditions:`, {expeditions: notDeletedExpeditions.join()})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
},
|
},
|
||||||
"agencyMode": {
|
"agencyMode": {
|
||||||
"type": "belongsTo",
|
"type": "belongsTo",
|
||||||
"model": "agency-mode",
|
"model": "AgencyMode",
|
||||||
"foreignKey": "agencyModeFk"
|
"foreignKey": "agencyModeFk"
|
||||||
},
|
},
|
||||||
"worker": {
|
"worker": {
|
||||||
|
|
Loading…
Reference in New Issue