modifcaciones direcciones

This commit is contained in:
nelo 2017-01-23 10:56:12 +01:00
parent c026619c6d
commit b9c0745b73
2 changed files with 15 additions and 45 deletions

View File

@ -1,7 +1,16 @@
import {module} from './module';
run.$inject = ['$rootScope'];
export function run ($rootScope) {
$rootScope.$on('$viewContentLoaded', () => {})
const HOOK_ABORTED_TRANSITION = 3;
run.$inject = ['$rootScope', '$state'];
export function run ($rootScope, $state) {
$rootScope.$on('$viewContentLoaded', () => {});
window.myAppErrorLog = [];
$state.defaultErrorHandler(function(error) {
if (error.type === HOOK_ABORTED_TRANSITION)
window.myAppErrorLog.push(error);
});
}
module.run(run);

View File

@ -7,23 +7,10 @@ module.exports = function(Address) {
Address.observe('before save', function (ctx, next) {
var data = getData(ctx);
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());
if (data.enabled && data.default) {
ctx.Model.update({client: data.client}, {default: false});
}
next();
});
function getData(ctx){
@ -33,30 +20,4 @@ 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;
}
};