bug fixed in address
This commit is contained in:
parent
563c49b785
commit
b77395762c
|
@ -11,7 +11,7 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
function create(data, next) {
|
function create(data, next) {
|
||||||
if (data.isDefaultAddress) {
|
if (data.isDefaultAddress) {
|
||||||
removeAllDefault(data.client, next);
|
removeAllDefault({id: data.clientFk}, next);
|
||||||
} else {
|
} else {
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,10 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
Self.beforeRemote('findById', function(ctx, modelInstance, next) {
|
Self.beforeRemote('findById', function(ctx, modelInstance, next) {
|
||||||
ctx.args.filter = {
|
ctx.args.filter = {
|
||||||
"include": {
|
include: {
|
||||||
"relation": "province",
|
relation: "province",
|
||||||
"scope": {
|
scope: {
|
||||||
"fields": ["id", "name"]
|
fields: ["id", "name"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -44,7 +44,7 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
function callbackGetAddress(ctx, newData, oldData, next) {
|
function callbackGetAddress(ctx, newData, oldData, next) {
|
||||||
if (newData.isDefaultAddress) {
|
if (newData.isDefaultAddress) {
|
||||||
removeAllDefault(oldData.client, next);
|
removeAllDefault(oldData, 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
|
||||||
|
@ -52,7 +52,10 @@ module.exports = function(Self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeAllDefault(client, next) {
|
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() {
|
function generateErrorDefaultAddress() {
|
||||||
|
|
Loading…
Reference in New Issue