bug fixed in address

This commit is contained in:
Daniel Herrero 2017-11-09 13:22:54 +01:00
parent 563c49b785
commit b77395762c
1 changed files with 10 additions and 7 deletions

View File

@ -11,7 +11,7 @@ module.exports = function(Self) {
function create(data, next) {
if (data.isDefaultAddress) {
removeAllDefault(data.client, next);
removeAllDefault({id: data.clientFk}, next);
} else {
next();
}
@ -25,10 +25,10 @@ module.exports = function(Self) {
Self.beforeRemote('findById', function(ctx, modelInstance, next) {
ctx.args.filter = {
"include": {
"relation": "province",
"scope": {
"fields": ["id", "name"]
include: {
relation: "province",
scope: {
fields: ["id", "name"]
}
}
};
@ -44,7 +44,7 @@ module.exports = function(Self) {
function callbackGetAddress(ctx, newData, oldData, next) {
if (newData.isDefaultAddress) {
removeAllDefault(oldData.client, next);
removeAllDefault(oldData, next);
} else if (oldData.isDefaultAddress && newData.hasOwnProperty('isDefaultAddress') && !newData.isDefaultAddress) {
next(generateErrorDefaultAddress());
} else
@ -52,7 +52,10 @@ module.exports = function(Self) {
}
function removeAllDefault(client, next) {
Self.updateAll({clientFk: client.id, isDefaultAddress: {neq: 0}}, {isDefaultAddress: false}, next);
if (client && client.id)
Self.updateAll({clientFk: client.id, isDefaultAddress: {neq: 0}}, {isDefaultAddress: false}, next);
else
next();
}
function generateErrorDefaultAddress() {