salix/back/methods/collection/setSaleQuantity.js

37 lines
930 B
JavaScript
Raw Normal View History

module.exports = Self => {
Self.remoteMethod('setSaleQuantity', {
description: 'Update sale quantity',
accessType: 'WRITE',
accepts: [{
arg: 'saleId',
type: 'number',
required: true,
description: 'The sale id'
},
{
arg: 'quantity',
type: 'number',
required: true,
description: 'The quantity to picked'
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/setSaleQuantity`,
verb: 'POST'
}
});
Self.setSaleQuantity = async(saleId, quantity) => {
const models = Self.app.models;
const sale = await models.Sale.findById(saleId);
return await sale.updateAttributes({
originalQuantity: sale.quantity,
quantity: quantity
});
};
};