-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#165412918 Give a rating to an article #50
Conversation
9570bb4
to
98d8f4e
Compare
91e3e52
to
4069ffc
Compare
package.json
Outdated
@@ -32,6 +32,7 @@ | |||
"chance": "^1.0.18", | |||
"cheke": "^1.0.3", | |||
"cors": "^2.8.5", | |||
"d": "^1.0.0", |
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's this meant for?
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.
The package is no longer needed, I am removing it
src/queries/ratings/create.js
Outdated
export default async (data = {}) => { | ||
const { articleId, userId, rating } = data; | ||
// check if already exist | ||
const result = await db.Rating.findAll({ |
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.
there should be a file for findAll
Ratings then import it here
61b6baf
to
2c39da1
Compare
src/queries/ratings/update.js
Outdated
import db from '../../models'; | ||
|
||
export default async (articleId) => { | ||
const allRatings = await db.Rating.findAll({ |
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.
import this as well
src/models/rating.js
Outdated
@@ -0,0 +1,63 @@ | |||
import * as queries from '../queries'; |
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.
there should not be queries in a model file. Set static data
b671fb2
to
4637946
Compare
@e-liyai made changes, you can check. |
87617c1
to
15cadae
Compare
@e-liyai check this PR is ready. |
15cadae
to
6069e02
Compare
247fe74
to
6350219
Compare
@e-liyai can you check this PR for me. it's ready 👍 |
src/queries/ratings/create.js
Outdated
const response = {}; | ||
if (result && result.length === 0) { | ||
await db.Rating.create({ rating, articleId, userId }, { logging: false }); | ||
response.message = 'Thank you for rating this article'; |
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.
remove message in queries, it should be in controller
src/queries/ratings/create.js
Outdated
{ where: { [db.Op.and]: { articleId, userId } }, logging: false } | ||
); | ||
response.statusCode = status.OK; | ||
response.message = 'Your article rating has been updated'; |
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.
same here
b74ebf6
to
d5fe9e7
Compare
src/controllers/RatingController.js
Outdated
rating: { | ||
message: | ||
response.statusCode === status.OK | ||
? 'Your article rating has been updated' |
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.
the logic here seems flawed if the status is ok article update successful
else even in the case of an error the message displayed is Thank you for rating this article
src/queries/ratings/create.js
Outdated
// check if already exist | ||
const result = await findAll(articleId, userId); | ||
const response = {}; | ||
if (result && result.length === 0) { |
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.
i see a create or update scenario here, update the filename appropriately
be36ac4
to
48de0c6
Compare
48de0c6
to
96a5daf
Compare
What does this PR do?
Give a rating on the article written by others
Description of Task to be completed?
Have the following endpoint accessible to an authenticated user:
POST /api/v1/articles/:slug/rating
give rating to an article identified by its slugGET /api/v1/articles/:slug/rating
Get users who rated a given articleHow should this be manually tested?
cd
into it and typenpm test
->make sure you signup then login to get the access token,
->create an article,
-> Create a rating using this endoint:
/api/v1/articles/:slug/rating
-> Make sure you pass the access token in the header with the following key name:
access-token
,-> Finally, send a JSON object of the following structure : {"rating": 1}
Any background context you want to provide?
Given,
n
: number of rating per articles
: sum of ratings per a given articleWhat are the relevant pivotal tracker stories?
#165412918
Screenshots (if appropriate)
N/A
Questions:
N/A