created "post tweet" API endpoint - #26
Conversation
| payload = { | ||
| id: 1, | ||
| payload.message: "hello" } */ | ||
| user_id: 1, |
There was a problem hiding this comment.
Why the values are hardcoded?
There was a problem hiding this comment.
That was already written. I just changed the name of the parameters.
| <input | ||
| type="button" | ||
| onclick="User.tweet({user:'felix',message:'hello there, this is my tweet.'})" | ||
| onclick="User.tweet({user_id:4,message:'hello there, this is my tweet.'})" |
There was a problem hiding this comment.
onclick should call a function, which in turns post a tweet.
| database.connection.query(q, | ||
| (error, results) =>{ //Check if tweet already exist | ||
| if(error) throw error; | ||
| let result = results[0]; |
There was a problem hiding this comment.
this variable may not be needed.
| (error, results) =>{ //Check if tweet already exist | ||
| if(error) throw error; | ||
| let result = results[0]; | ||
| if (results && results.length != 0 && result.message == payload.message) |
There was a problem hiding this comment.
results[0].messages
sanjaypradeep
left a comment
There was a problem hiding this comment.
Minor code tweak required.
|
Are we ready to merge @sanjaypradeep |
|
Review comments aren't addressed completely. I can give my heads-up once done! Apologize for late intimation @javascriptteacher |
|
@sanjaypradeep can you point out the comments that are not addressed completely. |
| if (results && results.length != 0 && results[0].message == payload.message) | ||
| resolve(`{"success": false, "message": "tweet already exist"}`); | ||
| else { | ||
| // console.log(payload) |
There was a problem hiding this comment.
Remove this line please.
| function action_post_tweet(request, payload) { | ||
| return new Promise((resolve, reject) => { | ||
| let q = ""; // query | ||
| if (!request || !request.headers || !payload) |
There was a problem hiding this comment.
Actually, we wanna throw error early if validation fails here, Isn't it?
Then I prefer doing it as,
function action_post_tweet(request, payload) {
if ( !request || !payload) {
throw error("Some error with proper messages")
}
// can return from promise here..
return new Promise( .. )
}```
| resolve(`{"success": false, "message": "tweet already exist"}`); | ||
| else { | ||
| // console.log(payload) | ||
| let fields = "( `user_id`, `message`, `timestamp` )"; |
There was a problem hiding this comment.
From Line 371 to 379 - code which are available could be in a separate method saveTweet , consume that method here. Code may look clear.
|
Hi @gid-code Thank for spending time in implementing this. I'm trying to help this PR to make more clear. Have given some more suggestion. Please take look, would love to have discussion if required. |
|
Ok. Thank you. I will make the various changes |
Created post tweet API endpoint @javascriptteacher