2022-04-12 08:09:00 +00:00
|
|
|
module.exports = Self => {
|
2022-04-21 07:34:13 +00:00
|
|
|
Self.remoteMethodCtx('deleteClamedSales', {
|
|
|
|
description: 'Deletes the claimed sales',
|
2022-04-12 08:09:00 +00:00
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'sales',
|
|
|
|
type: ['object'],
|
|
|
|
required: true,
|
|
|
|
description: 'The sales to remove'
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: ['object'],
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
2022-04-21 07:34:13 +00:00
|
|
|
path: `/deleteClamedSales`,
|
2022-04-12 08:09:00 +00:00
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-04-21 07:34:13 +00:00
|
|
|
Self.deleteClamedSales = async(ctx, sales, options) => {
|
2022-04-12 08:09:00 +00:00
|
|
|
const models = Self.app.models;
|
|
|
|
const myOptions = {};
|
2022-04-12 10:44:46 +00:00
|
|
|
const tx = await Self.beginTransaction({});
|
2022-04-12 08:09:00 +00:00
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2022-04-12 10:44:46 +00:00
|
|
|
if (!myOptions.transaction)
|
2022-04-12 08:09:00 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|