2021-05-18 06:41:36 +00:00
|
|
|
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) => {
|
2021-05-18 06:41:36 +00:00
|
|
|
const models = Self.app.models;
|
2021-10-22 15:32:10 +00:00
|
|
|
const myOptions = {};
|
|
|
|
let tx;
|
2021-05-18 06:41:36 +00:00
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2021-10-22 15:32:10 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-05-18 06:41:36 +00:00
|
|
|
};
|
|
|
|
};
|