correciones varias
This commit is contained in:
parent
070cd764b6
commit
9159af69f4
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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}`
|
||||
|
|
|
@ -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));
|
||||
})
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue