salix/modules/claim/back/methods/claim-end/deleteSalesClaimed.js

50 lines
1.3 KiB
JavaScript

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 = {};
const tx = await Self.beginTransaction({});
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction)
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;
}
};
};