dirección por defecto.

This commit is contained in:
nelo 2017-01-30 08:23:18 +01:00
parent 87dda33a20
commit afe2d1ea79
1 changed files with 7 additions and 7 deletions

View File

@ -20,25 +20,25 @@ module.exports = function(Address) {
Address.beforeRemote('prototype.updateAttributes',function(ctx, modelInstance, next){
var data = ctx.req.body;
data.id = ctx.req.params.id;
update(ctx, data, next);
getAddress(ctx, data, next);
});
function update(ctx, data, next){
var address = Address.findOne( {filter: { where: { id: data.id}}}, function (err, address){
function getAddress(ctx, data, next){
var address = Address.findOne( {where: { id: data.id}}, function (err, address){
if(address)
callbackGetAddress(ctx, data, address, next)
else
next();
});
}
function callbackGetAddress(ctx, data, address, next){
if (data.default){
removeAllDefault(ctx, address.client);
removeAllDefault(address.client);
next();
}
else
else if (address.default && !data.default)
next(generateErrorDefaultAddress());
else
next();
}
function getData(ctx){