salix/services/order/common/methods/order-row/removes.js

37 lines
1013 B
JavaScript
Raw Normal View History

2018-08-07 13:48:55 +00:00
const UserError = require('vn-loopback/common/helpers').UserError;
module.exports = Self => {
Self.remoteMethod('removes', {
description: 'Delete an Order Row',
accessType: '',
accepts: [{
arg: 'params',
type: 'object',
required: true,
description: '[Row IDs], actualOrderId',
http: {source: 'body'}
}],
returns: {
type: 'string',
root: true
},
http: {
path: `/removes`,
verb: 'post'
}
});
Self.removes = async params => {
if (!params.rows || !params.rows.length)
throw new Error('There is nothing delete');
await Self.app.models.Order.isEditable(params.actualOrderId);
let promises = [];
for (let i = 0; i < params.rows.length; i++) {
promises.push(Self.app.models.OrderRow.destroyById(params.rows[i]));
}
return await Promise.all(promises);
};
};