diff --git a/services/client/common/methods/client/addressesPropagateRe.js b/services/client/common/methods/client/addressesPropagateRe.js index b5aec246c..ec960a912 100644 --- a/services/client/common/methods/client/addressesPropagateRe.js +++ b/services/client/common/methods/client/addressesPropagateRe.js @@ -30,7 +30,7 @@ module.exports = function(Client) { }); Client.addressesPropagateRe = (id, data, callback) => { - if(data.hasOwnProperty('isEqualizated')) { + if (data.hasOwnProperty('isEqualizated')) { Client.app.models.Address.updateAll({clientFk: id}, data, (err, info) => { if (err) return callback(err, null); diff --git a/services/client/common/methods/client/before-save.js b/services/client/common/methods/client/before-save.js index 56090b8cf..74b9ce7a6 100644 --- a/services/client/common/methods/client/before-save.js +++ b/services/client/common/methods/client/before-save.js @@ -134,10 +134,10 @@ module.exports = function(Client) { JOIN RoleMapping rm ON (rm.principalId = ac.id) JOIN Role r on (r.id = rm.roleId) WHERE rm.principalType = 'USER' - AND cc.employeeFk = ${instances[0].employeeFk} + AND cc.employeeFk = ? AND r.\`name\` = 'manager'`; - Client.dataSource.connector.execute(sql, [], (_, res) => clientCreditCb(_, res)); + Client.dataSource.connector.execute(sql, [instances[0].employeeFk], (_, res) => clientCreditCb(_, res)); } function clientCreditCb(_, instance) { diff --git a/services/client/common/methods/client/card.js b/services/client/common/methods/client/card.js index 4bfc66005..bd2c4ca81 100644 --- a/services/client/common/methods/client/card.js +++ b/services/client/common/methods/client/card.js @@ -36,7 +36,7 @@ module.exports = function(Client) { function formatCard(card) { let cardFormated = JSON.parse(JSON.stringify(card)); - if(cardFormated.salesPersonFk) + if (cardFormated.salesPersonFk) cardFormated.salesPerson = { id: card.salesPerson().id, name: `${card.salesPerson().name} ${card.salesPerson().surname}` diff --git a/services/client/common/methods/client/salesperson.js b/services/client/common/methods/client/salesperson.js index c9e3651f2..dde54fe9f 100644 --- a/services/client/common/methods/client/salesperson.js +++ b/services/client/common/methods/client/salesperson.js @@ -33,7 +33,7 @@ module.exports = (Client) => { ORDER BY em.name ASC LIMIT ? OFFSET ?`; - Client.rawSql(query, [where.value, limit, skip], callback) + Client.rawSql(query, [where.value, parseInt(limit, 10), parseInt(skip, 10)], callback) .then(response => { callback(null, formatSalesPerson(response)); }) diff --git a/services/client/common/models/address.js b/services/client/common/models/address.js index 2d6d38a2b..c8dd86ccf 100644 --- a/services/client/common/models/address.js +++ b/services/client/common/models/address.js @@ -1,23 +1,23 @@ module.exports = function(Self) { - Self.validate('default',isEnabled,{message: 'No se puede poner predeterminado un consignatario desactivado'}); + Self.validate('default', isEnabled, {message: 'No se puede poner predeterminado un consignatario desactivado'}); function isEnabled(err) { - if (!this.isEnabled && this.isDefaultAddress) err(); + if (!this.isEnabled && this.isDefaultAddress) err(); } - Self.beforeRemote('create',function(ctx, modelInstance, next){ + Self.beforeRemote('create', function(ctx, modelInstance, next) { var data = ctx.req.body; create(data, next); }); - function create(data, next){ - if(data.isDefaultAddress){ + function create(data, next) { + if (data.isDefaultAddress) { removeAllDefault(data.client, next); - } else { + } else { next(); } } - Self.beforeRemote('prototype.patchAttributes',function(ctx, modelInstance, next){ + Self.beforeRemote('prototype.patchAttributes', function(ctx, modelInstance, next) { let newData = ctx.req.body; newData.id = ctx.req.params.id; getAddress(ctx, newData, next); @@ -25,7 +25,7 @@ module.exports = function(Self) { Self.beforeRemote('findById', function(ctx, modelInstance, next) { ctx.args.filter = { - "include": { + "include": { "relation": "province", "scope": { "fields": ["id", "name"] @@ -35,35 +35,34 @@ module.exports = function(Self) { next(); }); - function getAddress(ctx, newData, next){ - Self.findOne( {where: { id: newData.id}}, function (err, oldData){ - if(oldData) + function getAddress(ctx, newData, next) { + Self.findOne({where: {id: newData.id}}, (_, oldData) => { + if (oldData) callbackGetAddress(ctx, newData, oldData, next); - }); + }); } - function callbackGetAddress(ctx, newData, oldData, next){ - if (newData.isDefaultAddress){ + function callbackGetAddress(ctx, newData, oldData, next) { + if (newData.isDefaultAddress) { removeAllDefault(oldData.client, next); - } - else if (oldData.isDefaultAddress && newData.hasOwnProperty('isDefaultAddress') && !newData.isDefaultAddress) + } else if (oldData.isDefaultAddress && newData.hasOwnProperty('isDefaultAddress') && !newData.isDefaultAddress) { next(generateErrorDefaultAddress()); - else + } else next(); } - function getData(ctx){ + function getData(ctx) { if (ctx.data) return ctx.data; else return ctx.instance; } - function removeAllDefault(client, next){ + function removeAllDefault(client, next) { Self.updateAll({clientFk: client.id, isDefaultAddress: true}, {isDefaultAddress: false}, next); } - function generateErrorDefaultAddress(){ + function generateErrorDefaultAddress() { var error = new Error(); error.message = "No se puede desmarcar el consignatario predeterminado"; error.status = 500;