diff --git a/client/core/src/lib/crud.js b/client/core/src/lib/crud.js
index f515009b5..df5c5d062 100644
--- a/client/core/src/lib/crud.js
+++ b/client/core/src/lib/crud.js
@@ -3,7 +3,7 @@ import {module} from '../module';
index.$inject = ['mgIndex'];
function index(mgIndex) {
return Object.assign({}, mgIndex, {
- init: 'index.filter={page: 1, size: 4}'
+ init: 'index.filter={page: 1, size: 5}'
});
}
module.factory('vnIndex', index);
diff --git a/services/client/common/methods/client/addresses.js b/services/client/common/methods/client/addresses.js
index 5c11274b7..970c52d4b 100644
--- a/services/client/common/methods/client/addresses.js
+++ b/services/client/common/methods/client/addresses.js
@@ -37,7 +37,8 @@ module.exports = function(Client) {
clientFk: id
},
skip: (params.page - 1) * params.size,
- limit: params.size
+ limit: params.size,
+ order: ['default DESC', 'enabled DESC']
};
Client.app.models.Address.find(filter, function(err, instances) {
diff --git a/services/client/common/models/address.js b/services/client/common/models/address.js
index c9bcfb0d8..09f95209c 100644
--- a/services/client/common/models/address.js
+++ b/services/client/common/models/address.js
@@ -16,10 +16,10 @@ module.exports = function(Address) {
next();
}
- Address.beforeRemote('prototype.updateAttributes',function(ctx, modelInstance, next){
- var data = ctx.req.body;
- data.id = ctx.req.params.id;
- getAddress(ctx, data, next);
+ Address.beforeRemote('prototype.patchAttributes',function(ctx, modelInstance, next){
+ let newData = ctx.req.body;
+ newData.id = ctx.req.params.id;
+ getAddress(ctx, newData, next);
});
Address.beforeRemote('findById', function(ctx, modelInstance, next) {
@@ -34,19 +34,18 @@ module.exports = function(Address) {
next();
});
- function getAddress(ctx, data, next){
- var address = Address.findOne( {where: { id: data.id}}, function (err, address){
- if(address)
- callbackGetAddress(ctx, data, address, next);
+ function getAddress(ctx, newData, next){
+ Address.findOne( {where: { id: newData.id}}, function (err, oldData){
+ if(oldData)
+ callbackGetAddress(ctx, newData, oldData, next);
});
}
- function callbackGetAddress(ctx, data, address, next){
- if (data.default){
- removeAllDefault(address.client);
- next();
+ function callbackGetAddress(ctx, newData, oldData, next){
+ if (newData.default){
+ removeAllDefault(oldData.client, next);
}
- else if (address.default && data.hasOwnProperty('default') && !data.default)
+ else if (oldData.default && newData.hasOwnProperty('default') && !newData.default)
next(generateErrorDefaultAddress());
else
next();
@@ -59,8 +58,8 @@ module.exports = function(Address) {
return ctx.instance;
}
- function removeAllDefault(cl){
- Address.update({client: cl}, {default: false});
+ function removeAllDefault(client, next){
+ Address.updateAll({clientFk: client.id, default: true}, {default: false}, next);
}
function generateErrorDefaultAddress(){