correciones varias

This commit is contained in:
Daniel Herrero 2017-10-19 09:12:27 +02:00
parent 070cd764b6
commit 9159af69f4
5 changed files with 24 additions and 25 deletions

View File

@ -30,7 +30,7 @@ module.exports = function(Client) {
}); });
Client.addressesPropagateRe = (id, data, callback) => { Client.addressesPropagateRe = (id, data, callback) => {
if(data.hasOwnProperty('isEqualizated')) { if (data.hasOwnProperty('isEqualizated')) {
Client.app.models.Address.updateAll({clientFk: id}, data, (err, info) => { Client.app.models.Address.updateAll({clientFk: id}, data, (err, info) => {
if (err) if (err)
return callback(err, null); return callback(err, null);

View File

@ -134,10 +134,10 @@ module.exports = function(Client) {
JOIN RoleMapping rm ON (rm.principalId = ac.id) JOIN RoleMapping rm ON (rm.principalId = ac.id)
JOIN Role r on (r.id = rm.roleId) JOIN Role r on (r.id = rm.roleId)
WHERE rm.principalType = 'USER' WHERE rm.principalType = 'USER'
AND cc.employeeFk = ${instances[0].employeeFk} AND cc.employeeFk = ?
AND r.\`name\` = 'manager'`; 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) { function clientCreditCb(_, instance) {

View File

@ -36,7 +36,7 @@ module.exports = function(Client) {
function formatCard(card) { function formatCard(card) {
let cardFormated = JSON.parse(JSON.stringify(card)); let cardFormated = JSON.parse(JSON.stringify(card));
if(cardFormated.salesPersonFk) if (cardFormated.salesPersonFk)
cardFormated.salesPerson = { cardFormated.salesPerson = {
id: card.salesPerson().id, id: card.salesPerson().id,
name: `${card.salesPerson().name} ${card.salesPerson().surname}` name: `${card.salesPerson().name} ${card.salesPerson().surname}`

View File

@ -33,7 +33,7 @@ module.exports = (Client) => {
ORDER BY em.name ASC ORDER BY em.name ASC
LIMIT ? OFFSET ?`; LIMIT ? OFFSET ?`;
Client.rawSql(query, [where.value, limit, skip], callback) Client.rawSql(query, [where.value, parseInt(limit, 10), parseInt(skip, 10)], callback)
.then(response => { .then(response => {
callback(null, formatSalesPerson(response)); callback(null, formatSalesPerson(response));
}) })

View File

@ -1,23 +1,23 @@
module.exports = function(Self) { 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) { 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; var data = ctx.req.body;
create(data, next); create(data, next);
}); });
function create(data, next){ function create(data, next) {
if(data.isDefaultAddress){ if (data.isDefaultAddress) {
removeAllDefault(data.client, next); removeAllDefault(data.client, next);
} else { } else {
next(); next();
} }
} }
Self.beforeRemote('prototype.patchAttributes',function(ctx, modelInstance, next){ Self.beforeRemote('prototype.patchAttributes', function(ctx, modelInstance, next) {
let newData = ctx.req.body; let newData = ctx.req.body;
newData.id = ctx.req.params.id; newData.id = ctx.req.params.id;
getAddress(ctx, newData, next); getAddress(ctx, newData, next);
@ -35,35 +35,34 @@ module.exports = function(Self) {
next(); next();
}); });
function getAddress(ctx, newData, next){ function getAddress(ctx, newData, next) {
Self.findOne( {where: { id: newData.id}}, function (err, oldData){ Self.findOne({where: {id: newData.id}}, (_, oldData) => {
if(oldData) if (oldData)
callbackGetAddress(ctx, newData, oldData, next); callbackGetAddress(ctx, newData, oldData, next);
}); });
} }
function callbackGetAddress(ctx, newData, oldData, next){ function callbackGetAddress(ctx, newData, oldData, next) {
if (newData.isDefaultAddress){ if (newData.isDefaultAddress) {
removeAllDefault(oldData.client, next); removeAllDefault(oldData.client, next);
} } else if (oldData.isDefaultAddress && newData.hasOwnProperty('isDefaultAddress') && !newData.isDefaultAddress) {
else if (oldData.isDefaultAddress && newData.hasOwnProperty('isDefaultAddress') && !newData.isDefaultAddress)
next(generateErrorDefaultAddress()); next(generateErrorDefaultAddress());
else } else
next(); next();
} }
function getData(ctx){ function getData(ctx) {
if (ctx.data) if (ctx.data)
return ctx.data; return ctx.data;
else else
return ctx.instance; return ctx.instance;
} }
function removeAllDefault(client, next){ function removeAllDefault(client, next) {
Self.updateAll({clientFk: client.id, isDefaultAddress: true}, {isDefaultAddress: false}, next); Self.updateAll({clientFk: client.id, isDefaultAddress: true}, {isDefaultAddress: false}, next);
} }
function generateErrorDefaultAddress(){ function generateErrorDefaultAddress() {
var error = new Error(); var error = new Error();
error.message = "No se puede desmarcar el consignatario predeterminado"; error.message = "No se puede desmarcar el consignatario predeterminado";
error.status = 500; error.status = 500;