diff --git a/backend/app/people/inquisitor-validator.js b/backend/app/people/inquisitor-validator.js index d6fcf64399f193e398e7c018af582904af50c72b..0a9937c97d05c04247f8047f66a11cc4d3477d19 100644 --- a/backend/app/people/inquisitor-validator.js +++ b/backend/app/people/inquisitor-validator.js @@ -6,7 +6,7 @@ var areBadPetsHere = function (pets) { return false } var m = pets.map(function (pet) { - return pet == '' + return pet == '' || pet == undefined }) return m.reduce(function (i,j) { return i || j @@ -14,6 +14,7 @@ var areBadPetsHere = function (pets) { } var inquisitor = function (next) { + console.log(this) if(this.name == ''){ next(erroneous_name) } diff --git a/backend/app/people/people.js b/backend/app/people/people.js index 1aefc2c12fdf10c9580520dc77236ae90ef8fcb8..4c918eac35fd1f6f0a7832104be0e887f621f57d 100644 --- a/backend/app/people/people.js +++ b/backend/app/people/people.js @@ -54,10 +54,10 @@ db.once('open',function () { } people.modifyPet = function (id, old_pet_name, new_pet_name, callback) { - people.removePet(id,old_pet_name,function () { - people.addPet(id,new_pet_name,function () { - callback() - }) + people.model.findById(id).then(function (person) { + person.pets.splice(person.pets.indexOf(old_pet_name),1) + person.pets.push(new_pet_name) + person.save(callback) }) } diff --git a/frontend/app/core/people.js b/frontend/app/core/people.js index d1702565bea31607b1a9c0337e1b4019ecdf40fe..319fc18b8df410af2a16f8088e58381a46cfa7c5 100644 --- a/frontend/app/core/people.js +++ b/frontend/app/core/people.js @@ -8,6 +8,12 @@ app.controller('peopleCtrl',function ($scope,ngDialog,people) { }) } + $scope.badData = function () { + ngDialog.open({ + template:'../error-partial.html' + }) + } + this.load() $scope.remove = function (item) { @@ -16,7 +22,7 @@ app.controller('peopleCtrl',function ($scope,ngDialog,people) { $scope.add = function () { console.log("adding") - people.add($scope.name,self.load) + people.add($scope.name,self.load,$scope.badData) $scope.name = '' } @@ -34,7 +40,7 @@ app.controller('peopleCtrl',function ($scope,ngDialog,people) { people.addPet(person, pet, function () { self.load() $scope.pet = '' - }) + }, $scope.badData) } $scope.do = function (person,pet) { diff --git a/frontend/app/core/peopleService.js b/frontend/app/core/peopleService.js index 5447619f73c1306cfa31340bdb918e9b9538c276..fbb582a7fec0295ae3b96975eb4bc4aaed421aa0 100644 --- a/frontend/app/core/peopleService.js +++ b/frontend/app/core/peopleService.js @@ -7,18 +7,18 @@ app.service('people', function ($http) { $http.delete('http://127.0.0.1:8000/people/'+item._id).then(callback) } - this.add = function (n,callback) { - $http.post('http://127.0.0.1:8000/people',{name:n}).then(callback) + this.add = function (n,callback,reject) { + $http.post('http://127.0.0.1:8000/people',{name:n}).then(callback).catch(reject) } - this.modify = function (item,callback) { + this.modify = function (item,callback,reject) { $http.put('http://127.0.0.1:8000/people',{person_id: item._id, name: item.name}) - .then(callback) + .then(callback).catch(reject) } - this.addPet = function (item,pet_name,callback) { + this.addPet = function (item,pet_name,callback,reject) { $http.post('http://127.0.0.1:8000/people/pets',{person_id: item._id, petname: pet_name}) - .then(callback) + .then(callback).catch(reject) } this.removePet = function (item, pet_name, callback) { @@ -26,12 +26,12 @@ app.service('people', function ($http) { .then(callback) } - this.modifyPet = function (item,old_pet_name,new_petname,callback) { + this.modifyPet = function (item,old_pet_name,new_petname,callback,reject) { $http.put('http://127.0.0.1:8000/people/pets', { person_id: item._id, old_petname: old_pet_name, new_petname: new_petname - }).then(callback) + }).then(callback).catch(reject) } }) diff --git a/frontend/app/error-partial.html b/frontend/app/error-partial.html new file mode 100644 index 0000000000000000000000000000000000000000..7194fcbf0eb150241c50acdcc711430a926588e1 --- /dev/null +++ b/frontend/app/error-partial.html @@ -0,0 +1,9 @@ +