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

48 lines
1.2 KiB
JavaScript
Raw Normal View History

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'
}
});
2021-08-12 07:23:19 +00:00
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;
}
};
};