43 lines
1.0 KiB
JavaScript
43 lines
1.0 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;
|
|
|
|
let tx;
|
|
let myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
try {
|
|
const deleted = models.Order.destroyAll({
|
|
id: {inq: deletes}
|
|
}, myOptions);
|
|
|
|
if (tx) await tx.commit();
|
|
return deleted;
|
|
} catch (e) {
|
|
if (tx) await tx.rollback();
|
|
throw e;
|
|
}
|
|
};
|
|
};
|