module.exports = Self => { Self.remoteMethodCtx('deleteSalesClaimed', { description: 'Deletes the selected sales', accessType: 'WRITE', accepts: [{ arg: 'sales', type: ['object'], required: true, description: 'The sales to remove' }], returns: { type: ['object'], root: true }, http: { path: `/deleteSalesClaimed`, verb: 'POST' } }); Self.deleteSalesClaimed = async(ctx, sales, 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 sale of sales) { const deletedSale = models.ClaimEnd.destroyById(sale.id, myOptions); promises.push(deletedSale); } const deletedSales = await Promise.all(promises); if (tx) await tx.commit(); return deletedSales; } catch (e) { if (tx) await tx.rollback(); throw e; } }; };