salix/modules/monitor/back/methods/sales-monitor/deleteOrders.js

48 lines
1.2 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('deleteOrders', {
description: 'Deletes the selected orders',
accessType: 'WRITE',
accepts: [{
arg: 'deletes',
type: ['number'],
required: true,
description: 'The order ids to delete'
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/deleteOrders`,
verb: 'POST'
}
});
Self.deleteOrders = async(deletes = [], 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 deletedSales = await models.Order.destroyAll({
id: {inq: deletes}
}, myOptions);
if (tx) await tx.commit();
return deletedSales;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};