This repository has been archived by the owner on Aug 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Pramith/backend routes #61
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
01b5517
working on user liked stuff
pramithready a4f3150
Merge branch 'master' of https://github.com/daniel-d-truong/tag.it
pramithready 052f225
started user controller with course
pramithready 9ecb40c
Merge branch 'master' of https://github.com/daniel-d-truong/tag.it
pramithready 35e51c4
added user likes stuff and user/courseID routes
pramithready f157c8f
modified with ronak's req.user
pramithready 5a607e6
Fixed weird user issues
daniel-d-truong a424b2f
route now sends json for user type
pramithready File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,34 @@ class User { | |
await this.push(); | ||
} | ||
|
||
addLikedPost = async (postId) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a future PR let's write tests for these to make sure that they work |
||
this.props.likedPostList.push(postId); | ||
let post = await getPostById(postId); | ||
post.incrementScore(); | ||
await this.push(); | ||
} | ||
|
||
removeLikedPost = async (postId) => { | ||
this.props.likedPostList.splice(likedPostList.indexOf(postId), 1); | ||
let post = await getPostById(postId); | ||
post.decrementScore(); | ||
await this.push(); | ||
} | ||
|
||
addLikedComment = async (commentId) => { | ||
this.props.likedCommentList.push(commentId); | ||
let comment = await getCommentById(commentId); | ||
comment.incrementScore(); | ||
await this.push(); | ||
} | ||
|
||
removeLikedComment = async (commentId) => { | ||
this.props.likedCommentList.splice(likedCommentList.indexOf(commentId), 1); | ||
let comment = await getCommentById(commentId); | ||
comment.decrementScore(); | ||
await this.push(); | ||
} | ||
|
||
getName() { | ||
return this.props.name; | ||
} | ||
|
@@ -67,6 +95,14 @@ class User { | |
return this.props.followingList.slice(1, this.props.followingList.length); | ||
} | ||
|
||
getLikedPostList() { | ||
return this.props.likedPostList.slice(1, this.props.likedPostList.length); | ||
} | ||
|
||
getLikedCommentList() { | ||
return this.props.likedCommentList.slice(1, this.props.likedCommentList.length); | ||
} | ||
|
||
getIcon() { | ||
return this.props.icon; | ||
} | ||
|
@@ -88,6 +124,9 @@ class User { | |
postList: this.props.postList, | ||
commentList: this.props.commentList, | ||
followingList: this.props.followingList, | ||
// Add this ternary for new fields to prevent old data from crashing | ||
likedPostList: this.props.likedPostList ? this.props.likedPostList : [], | ||
likedCommentList: this.props.likedCommentList ? this.props.likedCommentList : [], | ||
icon: this.props.icon | ||
}); | ||
} | ||
|
@@ -109,6 +148,8 @@ module.exports.pushUserToFirebase = (updateParams) => { | |
postList: ["dummy_post_id"], | ||
commentList: ["dummy_comment_id"], | ||
followingList: ["dummy_post_id"], | ||
likedPostList: ["dummy_post_id"], | ||
likedCommentList: ["dummy_comment_id"], | ||
icon: "anonymous.jpg" | ||
}); | ||
resolve("Everything worked"); | ||
|
@@ -128,7 +169,6 @@ getUserById = async (uuid) => { | |
return new Promise((resolve, reject) => { | ||
ref.once("value", function(snapshot) { | ||
const r = new User(snapshot.val()); | ||
//console.log(r.props.name); | ||
resolve(r); | ||
}, function (errorObject) { | ||
reject(errorObject); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the purpose of this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rohith said that he and Pawan were going to initialize each list with a dummy string element to make sure Javascript knew that the list was a list of Strings. They wanted the list getters implemented this way to ignore that first dummy string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting okay I must not have caught that in a previous PR. Honestly that shouldn't be necessary but that could also be a refactor for later. Let's make a comment or something about that in the code to prevent future confusion.