From 05fc1f08a8e9f67d78b7f05301610ef2b0b52b54 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 5 Jun 2019 07:41:20 +0200 Subject: [PATCH] renamed vars according to convention --- .../ticket/back/methods/sale/updatePrice.js | 16 ++++++++-------- .../methods/ticket-tracking/changeState.js | 18 +++++++++--------- .../ticket/back/methods/ticket/makeInvoice.js | 8 ++++---- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index dd6d64c59..007e17954 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -29,7 +29,7 @@ module.exports = Self => { }); Self.updatePrice = async(id, newPrice) => { - let $ = Self.app.models; + let models = Self.app.models; let transaction = await Self.beginTransaction({}); let options = {transaction}; @@ -49,17 +49,17 @@ module.exports = Self => { } } }; - let sale = await $.Sale.findById(id, filter, options); + let sale = await models.Sale.findById(id, filter, options); - let isEditable = await $.Ticket.isEditable(sale.ticketFk); + let isEditable = await models.Ticket.isEditable(sale.ticketFk); if (!isEditable) throw new UserError(`The sales of this ticket can't be modified`); let salesPerson = sale.ticket().client().salesPersonFk; - let usesMana = await $.WorkerMana.findOne({where: {workerFk: salesPerson}, fields: 'amount'}, options); + let usesMana = await models.WorkerMana.findOne({where: {workerFk: salesPerson}, fields: 'amount'}, options); let componentCode = usesMana ? 'mana' : 'buyerDiscount'; - let discount = await $.ComponentRate.findOne({where: {code: componentCode}}, options); + let discount = await models.ComponentRate.findOne({where: {code: componentCode}}, options); let componentId = discount.id; let componentValue = newPrice - sale.price; @@ -67,14 +67,14 @@ module.exports = Self => { componentFk: componentId, saleFk: id }; - let saleComponent = await $.SaleComponent.findOne({where}, options); + let saleComponent = await models.SaleComponent.findOne({where}, options); if (saleComponent) { - await $.SaleComponent.updateAll(where, { + await models.SaleComponent.updateAll(where, { value: saleComponent.value + componentValue }, options); } else { - await $.SaleComponent.create({ + await models.SaleComponent.create({ saleFk: id, componentFk: componentId, value: componentValue diff --git a/modules/ticket/back/methods/ticket-tracking/changeState.js b/modules/ticket/back/methods/ticket-tracking/changeState.js index f70ae93a5..9a4c63ece 100644 --- a/modules/ticket/back/methods/ticket-tracking/changeState.js +++ b/modules/ticket/back/methods/ticket-tracking/changeState.js @@ -25,26 +25,26 @@ module.exports = Self => { Self.changeState = async(ctx, params) => { let userId = ctx.req.accessToken.userId; - let $ = Self.app.models; + let models = Self.app.models; if (!params.stateFk && !params.code) throw new UserError('State cannot be blank'); if (params.code) { - let state = await $.State.findOne({where: {code: params.code}, fields: ['id']}); + let state = await models.State.findOne({where: {code: params.code}, fields: ['id']}); params.stateFk = state.id; } - let isProduction = await $.Account.hasRole(userId, 'production'); - let isSalesPerson = await $.Account.hasRole(userId, 'salesPerson'); + let isProduction = await models.Account.hasRole(userId, 'production'); + let isSalesPerson = await models.Account.hasRole(userId, 'salesPerson'); - let ticket = await $.TicketState.findById( + let ticket = await models.TicketState.findById( params.ticketFk, {fields: ['stateFk']} ); - let oldState = await $.State.findById(ticket.stateFk); - let newState = await $.State.findById(params.stateFk); + let oldState = await models.State.findById(ticket.stateFk); + let newState = await models.State.findById(params.stateFk); let isAllowed = isProduction || isSalesPerson && oldState.isEditable() @@ -54,10 +54,10 @@ module.exports = Self => { throw new UserError(`You don't have enough privileges`, 'ACCESS_DENIED'); if (newState.code != 'PICKER_DESIGNED') { - let worker = await $.Worker.findOne({where: {userFk: userId}}); + let worker = await models.Worker.findOne({where: {userFk: userId}}); params.workerFk = worker.id; } - return await $.TicketTracking.create(params); + return await models.TicketTracking.create(params); }; }; diff --git a/modules/ticket/back/methods/ticket/makeInvoice.js b/modules/ticket/back/methods/ticket/makeInvoice.js index 1bc514990..cbfe8e531 100644 --- a/modules/ticket/back/methods/ticket/makeInvoice.js +++ b/modules/ticket/back/methods/ticket/makeInvoice.js @@ -26,19 +26,19 @@ module.exports = function(Self) { Self.makeInvoice = async(ctx, id) => { let userId = ctx.req.accessToken.userId; - let $ = Self.app.models; + let models = Self.app.models; let options = {}; options.transaction = await Self.beginTransaction({}); try { - let ticket = await $.Ticket.findById(id, {fields: ['id', 'clientFk', 'companyFk']}); + let ticket = await models.Ticket.findById(id, {fields: ['id', 'clientFk', 'companyFk']}); - let clientCanBeInvoiced = await $.Client.canBeInvoiced(ticket.clientFk); + let clientCanBeInvoiced = await models.Client.canBeInvoiced(ticket.clientFk); if (!clientCanBeInvoiced) throw new UserError(`This client can't be invoiced`); - let ticketCanBeInvoiced = await $.Ticket.canBeInvoiced(ticket.id); + let ticketCanBeInvoiced = await models.Ticket.canBeInvoiced(ticket.id); if (!ticketCanBeInvoiced) throw new UserError(`This ticket can't be invoiced`);