fix(deletExpeditions): add try catch
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2024-07-17 10:14:41 +02:00
parent b5728b43f0
commit 4ff388198b
1 changed files with 21 additions and 26 deletions

View File

@ -27,38 +27,33 @@ module.exports = Self => {
const deletedExpeditions = [];
for (let expeditionId of expeditionIds) {
const filter = {
fields: [],
where: {
id: expeditionId
},
include: [
{
relation: 'agencyMode',
scope: {
fields: ['code'],
try {
const expedition = await models.Expedition.findById(expeditionId, {
include: [
{
relation: 'agencyMode',
scope: {
fields: ['code'],
}
}
}
]
};
]
});
const {code} = expedition.agencyMode();
const expedition = await models.Expedition.findOne(filter);
const {code} = expedition.agencyMode();
let isDeleted = true;
if (code?.toLowerCase()?.includes('mrw') && expedition.externalId) {
const result = await models.MrwConfig.cancelShipment(expeditionId);
if (!result) throw new Error('not deleted');
}
if (code?.toLowerCase()?.includes('mrw'))
isDeleted = await models.MrwConfig.cancelShipment(expeditionId);
if (code?.toLowerCase()?.substring(0, 10) == 'viaexpress') {
const result = await models.ViaexpressConfig.deleteExpedition(expeditionId);
if (result !== 'true') throw new Error('not deleted');
}
if (code?.toLowerCase()?.substring(0, 10) == 'viaexpress') {
const result = await models.ViaexpressConfig.deleteExpedition(expeditionId);
if (result !== 'true') isDeleted = false;
}
if (!isDeleted)
notDeletedExpeditions.push(expeditionId);
else {
const deletedExpedition = await models.Expedition.destroyById(expeditionId);
deletedExpeditions.push(deletedExpedition);
} catch (e) {
notDeletedExpeditions.push(expeditionId);
}
}