Skip to content

Commit

Permalink
Merge pull request #50 from Looking-To-Game/Caleb
Browse files Browse the repository at this point in the history
working on the put for the post object update route
  • Loading branch information
mmpadget authored Jun 23, 2017
2 parents 1ac1a38 + b552437 commit 8af2b9f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/component/feed/feed-view/feed-view-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ module.exports = {
this.viewPost = function(postId){
return postService.viewPost(postId)
.then(post => {
console.log('post id', post._id);
console.log('post object', post);
// console.log('post id', post._id);
// console.log('post object', post);
$window.localStorage.removeItem('currentPost');
$window.localStorage.setItem('currentPost', JSON.stringify(postService.post));
})
Expand Down
21 changes: 15 additions & 6 deletions app/component/post/edit-post/edit-post-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = {
'$log',
'$window',
'$location',
'postService', function($log, $window, $location, postService){
'postService',
function($log, $window, $location, postService){
this.$onInit = () => {
$log.debug('#editPostCtrl');

Expand All @@ -20,21 +21,29 @@ module.exports = {
};

this.showEditPost = true;

this.editedPost = JSON.parse($window.localStorage.currentPost);
console.log('THE EDITED POST MOTHA FUCKA', this.editedPost);

this.updatePost = () => {
postService.updatePost(this.post._id, this.post)
return postService.updatePost(this.editedPost._id, this.editedPost)
.then(post => {
$window.localStorage.removeItem('currentPost');
$window.localStorage.setItem('currentPost', JSON.stringify(post.data));
// $window.localStorage.removeItem('currentPost');
this.editedPost = $window.localStorage.currentPost = JSON.stringify(postService.post);
() => $log.log('Edit successful'), err => $log.error(err);
}
)
.then(
() => $location.url('/post')
() => {
// this.editedPost = JSON.parse($window.localStorage.currentPost);
$location.url('/post');
}
);
};
};





}],
};
4 changes: 2 additions & 2 deletions app/component/post/edit-post/edit-post.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
ng-model="editPostCtrl.editedPost.endTime">
</fieldset>
<button type="submit" ng-if="editPostCtrl.showEditPost"
ng-click="editPostCtrl.showEditPost = false"
ng-click="editPostCtrl.updatePost()">submit</button>
ng-click="editPostCtrl.showEditPost = false; editPostCtrl.updatePost()">
submit</button>
</form>
</section>
7 changes: 5 additions & 2 deletions app/service/post-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,26 @@ module.exports = [

service.updatePost = (groupId, post) => {
$log.debug('#postservice.updatePost');

return authService.getToken()
.then(token => {
let url = `${__API_URL__}/api/group/${groupId}`;
let url = `${__API_URL__}/api/group/${groupId}/update`;
let config = {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
};
console.log(groupId, post);
return $http.put(url, post, config);
})
.then(res => {
console.log('this is what we\'re getting back:', res.data);
service.posts.forEach((ele, index) => {
if(ele._id === res.data._id) service.posts[index] = res.data;
});
service.post = res.data;// NOTE: just changed
console.log('this is the service.post:', service.post);
return res.data;
})
.catch(err => {
Expand Down

0 comments on commit 8af2b9f

Please sign in to comment.