Commit 0601e276 authored by fvieira's avatar fvieira

preliminar validation done

parent de45cff6
...@@ -6,7 +6,7 @@ var areBadPetsHere = function (pets) { ...@@ -6,7 +6,7 @@ var areBadPetsHere = function (pets) {
return false return false
} }
var m = pets.map(function (pet) { var m = pets.map(function (pet) {
return pet == '' return pet == '' || pet == undefined
}) })
return m.reduce(function (i,j) { return m.reduce(function (i,j) {
return i || j return i || j
...@@ -14,6 +14,7 @@ var areBadPetsHere = function (pets) { ...@@ -14,6 +14,7 @@ var areBadPetsHere = function (pets) {
} }
var inquisitor = function (next) { var inquisitor = function (next) {
console.log(this)
if(this.name == ''){ if(this.name == ''){
next(erroneous_name) next(erroneous_name)
} }
......
...@@ -54,10 +54,10 @@ db.once('open',function () { ...@@ -54,10 +54,10 @@ db.once('open',function () {
} }
people.modifyPet = function (id, old_pet_name, new_pet_name, callback) { people.modifyPet = function (id, old_pet_name, new_pet_name, callback) {
people.removePet(id,old_pet_name,function () { people.model.findById(id).then(function (person) {
people.addPet(id,new_pet_name,function () { person.pets.splice(person.pets.indexOf(old_pet_name),1)
callback() person.pets.push(new_pet_name)
}) person.save(callback)
}) })
} }
......
...@@ -8,6 +8,12 @@ app.controller('peopleCtrl',function ($scope,ngDialog,people) { ...@@ -8,6 +8,12 @@ app.controller('peopleCtrl',function ($scope,ngDialog,people) {
}) })
} }
$scope.badData = function () {
ngDialog.open({
template:'../error-partial.html'
})
}
this.load() this.load()
$scope.remove = function (item) { $scope.remove = function (item) {
...@@ -16,7 +22,7 @@ app.controller('peopleCtrl',function ($scope,ngDialog,people) { ...@@ -16,7 +22,7 @@ app.controller('peopleCtrl',function ($scope,ngDialog,people) {
$scope.add = function () { $scope.add = function () {
console.log("adding") console.log("adding")
people.add($scope.name,self.load) people.add($scope.name,self.load,$scope.badData)
$scope.name = '' $scope.name = ''
} }
...@@ -34,7 +40,7 @@ app.controller('peopleCtrl',function ($scope,ngDialog,people) { ...@@ -34,7 +40,7 @@ app.controller('peopleCtrl',function ($scope,ngDialog,people) {
people.addPet(person, pet, function () { people.addPet(person, pet, function () {
self.load() self.load()
$scope.pet = '' $scope.pet = ''
}) }, $scope.badData)
} }
$scope.do = function (person,pet) { $scope.do = function (person,pet) {
......
...@@ -7,18 +7,18 @@ app.service('people', function ($http) { ...@@ -7,18 +7,18 @@ app.service('people', function ($http) {
$http.delete('http://127.0.0.1:8000/people/'+item._id).then(callback) $http.delete('http://127.0.0.1:8000/people/'+item._id).then(callback)
} }
this.add = function (n,callback) { this.add = function (n,callback,reject) {
$http.post('http://127.0.0.1:8000/people',{name:n}).then(callback) $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}) $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}) $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) { this.removePet = function (item, pet_name, callback) {
...@@ -26,12 +26,12 @@ app.service('people', function ($http) { ...@@ -26,12 +26,12 @@ app.service('people', function ($http) {
.then(callback) .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', $http.put('http://127.0.0.1:8000/people/pets',
{ {
person_id: item._id, person_id: item._id,
old_petname: old_pet_name, old_petname: old_pet_name,
new_petname: new_petname new_petname: new_petname
}).then(callback) }).then(callback).catch(reject)
} }
}) })
<div>
<h1>Error</h1>
Erroneous data.
<div class="row">
<div class="6u align-center">
<button ng-click='closeThisDialog()' >Oops</button>
</div>
</div>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment