modificaciones servidor consignatarios

This commit is contained in:
nelo 2017-01-23 07:23:16 +01:00
parent 47fec183a7
commit 83632dc3f1
2 changed files with 42 additions and 8 deletions

View File

@ -29,11 +29,6 @@ export const COMPONENT = {
}
);
};
$http.get('/client/api/Addresses').then(
json => {
this.addresses = json.data;
}
);
this.getNumPages = () => {
var nPages = numRecords / numPerPage;

View File

@ -7,10 +7,23 @@ module.exports = function(Address) {
Address.observe('before save', function (ctx, next) {
var data = getData(ctx);
if (data.isEnabled && data.default) {
ctx.Model.update({client: data.client}, {default: false});
var address = Address.findOne( getFilterAddress(data), function (err, address){
if(address){
var id = address.id;
}
if (data.enabled && data.default) {
ctx.Model.update({client: data.client}, {default: false});
}
next();
});
if(!data.default && isDefaultAddress(ctx, data)){
next(generateErrorDefaultAddress());
}
next();
});
function getData(ctx){
@ -20,4 +33,30 @@ module.exports = function(Address) {
return ctx.instance;
}
function generateErrorDefaultAddress(){
var error = new Error();
error.message = "No se puede desmarcar el consignatario predeterminado";
error.status = 500;
return error;
}
function isDefaultAddress(ctx, data){
}
function getFilterAddress(data){
var filter = {
filter: {
where: {
and: [
{client: data.client},
{default: true}
]
}
}
}
return filter;
}
};