fix(setSaleQuantity): save originalQuantity
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2022-05-06 13:09:37 +02:00
parent 798147ea99
commit d34a8629f7
3 changed files with 17 additions and 19 deletions

View File

@ -1,5 +1,5 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx('setSaleQuantity', { Self.remoteMethod('setSaleQuantity', {
description: 'Update sale quantity', description: 'Update sale quantity',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [{
@ -24,11 +24,13 @@ module.exports = Self => {
} }
}); });
Self.setSaleQuantity = async ctx => { Self.setSaleQuantity = async(saleId, quantity) => {
const args = ctx.args;
const models = Self.app.models; const models = Self.app.models;
const sale = await models.Sale.findById(args.saleId,); const sale = await models.Sale.findById(saleId);
return await sale.updateAttribute('quantity', args.quantity); return await sale.updateAttributes({
originalQuantity: sale.quantity,
quantity: quantity
});
}; };
}; };

View File

@ -5,19 +5,12 @@ describe('setSaleQuantity()', () => {
const saleId = 30; const saleId = 30;
const newQuantity = 10; const newQuantity = 10;
const ctx = {
args: {
saleId: saleId,
quantity: newQuantity
}
};
const originalSale = await models.Sale.findById(saleId); const originalSale = await models.Sale.findById(saleId);
await models.Collection.setSaleQuantity(ctx); await models.Collection.setSaleQuantity(saleId, newQuantity);
const updateSale = await models.Sale.findById(saleId); const updateSale = await models.Sale.findById(saleId);
expect(updateSale.quantity).toBeLessThan(originalSale.quantity); expect(updateSale.originalQuantity).toEqual(originalSale.quantity);
expect(updateSale.quantity).toEqual(newQuantity); expect(updateSale.quantity).toEqual(newQuantity);
}); });
}); });

View File

@ -14,7 +14,7 @@
"properties": { "properties": {
"id": { "id": {
"id": true, "id": true,
"type": "Number", "type": "number",
"description": "Identifier" "description": "Identifier"
}, },
"concept": { "concept": {
@ -22,22 +22,25 @@
"required": true "required": true
}, },
"quantity": { "quantity": {
"type": "Number" "type": "number"
}, },
"price": { "price": {
"type": "Number" "type": "number"
}, },
"discount": { "discount": {
"type": "Number" "type": "number"
}, },
"reserved": { "reserved": {
"type": "boolean" "type": "boolean"
}, },
"isPicked": { "isPicked": {
"type": "Number" "type": "number"
}, },
"created": { "created": {
"type": "date" "type": "date"
},
"originalQuantity":{
"type": "number"
} }
}, },
"relations": { "relations": {