From 034cf526a6b93811442b1931212d2ba13689b4b9 Mon Sep 17 00:00:00 2001 From: Gerard Date: Mon, 8 Oct 2018 11:02:56 +0200 Subject: [PATCH] =?UTF-8?q?Bug=20#701=20Refactorizar=20los=20m=C3=A9todos?= =?UTF-8?q?=20de=20loopback=20que=20utilicen=20Self.update()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/loopback/common/methods/sale/updatePrice.js | 4 ++-- services/loopback/common/methods/sale/updateQuantity.js | 4 ++-- services/loopback/common/methods/ticket/deleted.js | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/services/loopback/common/methods/sale/updatePrice.js b/services/loopback/common/methods/sale/updatePrice.js index b19bc6c40..a21c13f25 100644 --- a/services/loopback/common/methods/sale/updatePrice.js +++ b/services/loopback/common/methods/sale/updatePrice.js @@ -52,7 +52,7 @@ module.exports = Self => { let ticket = await Self.getTicket(params); let usesMana = await model.WorkerMana.findOne({where: {workerFk: ticket[0].client().salesPersonFk}, fields: 'amount'}); - let currentLine = await Self.app.models.Sale.findOne({where: {id: params.id}, fields: 'price'}); + let currentLine = await Self.app.models.Sale.findOne({where: {id: params.id}}); let componentToUse; if (usesMana) @@ -67,7 +67,7 @@ module.exports = Self => { await Self.rawSql(query, [params.id, componentToUse, value, value]); - await Self.app.models.Sale.update({id: params.id}, {price: params.price}); + await currentLine.updateAttributes({price: params.price}); query = `call vn.manaSpellersRequery(?)`; await Self.rawSql(query, [ticket[0].client().salesPersonFk]); diff --git a/services/loopback/common/methods/sale/updateQuantity.js b/services/loopback/common/methods/sale/updateQuantity.js index a55ce9dee..2ced56dad 100644 --- a/services/loopback/common/methods/sale/updateQuantity.js +++ b/services/loopback/common/methods/sale/updateQuantity.js @@ -30,10 +30,10 @@ module.exports = Self => { if (isNaN(quantity)) throw new UserError(`The value should be a number`); - let currentLine = await Self.app.models.Sale.findOne({where: {id: id}, fields: ['quantity']}); + let currentLine = await Self.app.models.Sale.findOne({where: {id: id}}); if (quantity > currentLine.quantity) throw new UserError('The new quantity should be smaller than the old one'); - return await Self.app.models.Sale.update({id: id}, {quantity: quantity}); + return await currentLine.updateAttributes({quantity: quantity}); }; }; diff --git a/services/loopback/common/methods/ticket/deleted.js b/services/loopback/common/methods/ticket/deleted.js index 2636963a8..9ce9b8ad7 100644 --- a/services/loopback/common/methods/ticket/deleted.js +++ b/services/loopback/common/methods/ticket/deleted.js @@ -20,7 +20,8 @@ module.exports = Self => { }); Self.deleted = async(ctx, params) => { - await Self.app.models.Ticket.update({id: params.id}, {isDeleted: '1'}); + let currentTicket = await Self.app.models.Ticket.findById(params.id); + await currentTicket.updateAttributes({isDeleted: '1'}); if (ctx.req.accessToken) { let token = ctx.req.accessToken;