module.exports = Self => { Self.remoteMethod('deleteExpeditions', { description: 'Delete the selected expeditions', accessType: 'WRITE', accepts: [{ arg: 'expeditionIds', type: ['number'], required: true, description: 'The expeditions ids to delete' }], returns: { type: ['object'], root: true }, http: { path: `/deleteExpeditions`, verb: 'POST' } }); Self.deleteExpeditions = async(expeditionIds, options) => { 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 { 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; } }; };