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 => {
|
||||
require('../methods/viaexpress-config/internationalExpedition')(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",
|
||||
"Try again": "Try again",
|
||||
"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",
|
||||
"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",
|
||||
"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 => {
|
||||
Self.remoteMethod('deleteExpeditions', {
|
||||
Self.remoteMethodCtx('deleteExpeditions', {
|
||||
description: 'Delete the selected expeditions',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
|
@ -9,44 +10,51 @@ module.exports = Self => {
|
|||
required: true,
|
||||
description: 'The expeditions ids to delete'
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/deleteExpeditions`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.deleteExpeditions = async(expeditionIds, options) => {
|
||||
Self.deleteExpeditions = async(ctx, expeditionIds) => {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
const $t = ctx.req.__;
|
||||
const notDeletedExpeditions = [];
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
for (let expeditionId of expeditionIds) {
|
||||
const filter = {
|
||||
fields: [],
|
||||
where: {
|
||||
id: expeditionId
|
||||
},
|
||||
include: [
|
||||
{
|
||||
relation: 'agencyMode',
|
||||
scope: {
|
||||
fields: ['code'],
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
const expedition = await models.Expedition.findOne(filter);
|
||||
const {code} = expedition.agencyMode();
|
||||
|
||||
if (code && code.toLowerCase().substring(0, 10) == 'viaexpress') {
|
||||
const isDeleted = await models.ViaexpressConfig.deleteShipment(expeditionId);
|
||||
|
||||
if (isDeleted === 'true')
|
||||
await models.Expedition.destroyById(expeditionId);
|
||||
|
||||
else if (!isDeleted)
|
||||
notDeletedExpeditions.push(expeditionId);
|
||||
} else
|
||||
await models.Expedition.destroyById(expeditionId);
|
||||
}
|
||||
|
||||
try {
|
||||
const promises = [];
|
||||
for (let expeditionId of expeditionIds) {
|
||||
const deletedExpedition = models.Expedition.destroyById(expeditionId, myOptions);
|
||||
promises.push(deletedExpedition);
|
||||
}
|
||||
|
||||
const deletedExpeditions = await Promise.all(promises);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return deletedExpeditions;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
if (notDeletedExpeditions.length) {
|
||||
throw new UserError(
|
||||
$t(`It was not able to remove the next expeditions:`, {expeditions: notDeletedExpeditions.join()})
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
},
|
||||
"agencyMode": {
|
||||
"type": "belongsTo",
|
||||
"model": "agency-mode",
|
||||
"model": "AgencyMode",
|
||||
"foreignKey": "agencyModeFk"
|
||||
},
|
||||
"worker": {
|
||||
|
|
Loading…
Reference in New Issue