Tarea #355 ticket.lineas Modificar cantidad
This commit is contained in:
parent
4bc391e083
commit
ffc8c54899
|
@ -0,0 +1,34 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('updateQuantity', {
|
||||
description: 'Changes the quantity of a sale',
|
||||
accessType: '',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'sale ID',
|
||||
http: {source: 'path'}
|
||||
}, {
|
||||
arg: 'quantity',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'newQuantity'
|
||||
}],
|
||||
returns: {
|
||||
type: 'string',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/updateQuantity`,
|
||||
verb: 'post'
|
||||
}
|
||||
});
|
||||
|
||||
Self.updateQuantity = async(id, quantity) => {
|
||||
let currentLine = await Self.app.models.Sale.findOne({where: {id: id}, fields: ['quantity']});
|
||||
if (quantity > currentLine.quantity)
|
||||
throw new Error('The new quantity should be smaller than the old one');
|
||||
|
||||
return await Self.app.models.Sale.update({id: id}, {quantity: quantity});
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue