2022-10-07 08:47:54 +00:00
|
|
|
|
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('deleteExpeditions', {
|
|
|
|
description: 'Delete the selected expeditions',
|
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
2022-10-18 09:47:37 +00:00
|
|
|
arg: 'expeditionIds',
|
2022-10-07 08:47:54 +00:00
|
|
|
type: ['number'],
|
|
|
|
required: true,
|
|
|
|
description: 'The expeditions ids to delete'
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: ['object'],
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/deleteExpeditions`,
|
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-10-18 09:47:37 +00:00
|
|
|
Self.deleteExpeditions = async(expeditionIds, options) => {
|
2022-10-07 08:47:54 +00:00
|
|
|
const models = Self.app.models;
|
|
|
|
const myOptions = {};
|
|
|
|
let tx;
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
|
|
|
if (!myOptions.transaction) {
|
|
|
|
tx = await Self.beginTransaction({});
|
|
|
|
myOptions.transaction = tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-10-26 06:39:07 +00:00
|
|
|
const promises = [];
|
|
|
|
for (let expeditionId of expeditionIds) {
|
|
|
|
const deletedExpedition = models.Expedition.destroyById(expeditionId, myOptions);
|
|
|
|
promises.push(deletedExpedition);
|
|
|
|
}
|
|
|
|
|
|
|
|
const deletedExpeditions = await Promise.all(promises);
|
2022-10-07 08:47:54 +00:00
|
|
|
|
|
|
|
if (tx) await tx.commit();
|
|
|
|
|
|
|
|
return deletedExpeditions;
|
|
|
|
} catch (e) {
|
|
|
|
if (tx) await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|