-
Notifications
You must be signed in to change notification settings - Fork 2
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
#167966138 Enable user to update and delete articles #27
#167966138 Enable user to update and delete articles #27
Conversation
@@ -0,0 +1,22 @@ | |||
import bcrypt from 'bcrypt'; |
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.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
@@ -0,0 +1,24 @@ | |||
import { Article } from '../sequelize/models'; |
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.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'
e144bba
to
429b0ca
Compare
swagger.json
Outdated
} | ||
} | ||
}, | ||
"404": { |
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.
In the responses status code, I don't see 403 whereby the user is not allowed to delete an article that does not belong to them for example.
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.
done
src/controllers/articleController.js
Outdated
static async deteleArticle(req, res) { | ||
try { | ||
const deleted = await Article.destroy({ | ||
where: { slug: req.userData.slug } |
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.
Why did you use slug instead of ID to delete 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.
We already had slug from the params, I thought it would be efficient to delete using it rather than going to the DB search for an article using slug so as to get the id. But I have got another way of getting the id which I have implemented it.
src/controllers/articleController.js
Outdated
} | ||
article.description = (description || originalArticle.description).trim(); | ||
article.body = (body || originalArticle.body).trim(); | ||
article.tagList = (tags || originalArticle.tagList.toString()).trim().split(/[ ,]+/); |
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.
trying to update an article that didn't have previous tags throws TypeError: Cannot read property 'toString' of null
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.
Thanks, I found that also and fixed it. I will be pushing the changes in a min.
src/controllers/articleController.js
Outdated
article.description = (description || originalArticle.description).trim(); | ||
article.body = (body || originalArticle.body).trim(); | ||
article.tagList = (tags || originalArticle.tagList.toString()).trim().split(/[ ,]+/); | ||
article.category = (category || originalArticle.category).trim(); |
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.
why trim originalArticle.category
?
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.
Here I am checking for the category from req.body to trim but when I define (category.trim() || originalArticle.category) throws an error when the category is undefined
src/controllers/articleController.js
Outdated
article.title = title.trim(); | ||
article.slug = slugGen(title.trim()); | ||
} | ||
article.description = (description || originalArticle.description).trim(); |
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.
article.description = description.trim() || originalArticle.description;
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 also see that trim has been added to the validation rules, is there a reason we have it here as well?
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.
If the description is undefined it throws an error "can not trim value of undefined"
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 also see that trim has been added to the validation rules, is there a reason we have it here as well?
In the validations am checking for empty fields but in the controller am trimming white spaces before or after a 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.
article.description = description ? description.trim() : originalArticle.description;
src/controllers/articleController.js
Outdated
); | ||
if (updatedArticle) { | ||
return res.status(200).json({ | ||
message: 'Profile updated successfully', |
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.
Article updated successfully
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 am changing that.
src/controllers/articleController.js
Outdated
article.title = title.trim(); | ||
article.slug = slugGen(title.trim()); | ||
} | ||
article.description = (description || originalArticle.description).trim(); |
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 also see that trim has been added to the validation rules, is there a reason we have it here as well?
d9c177e
to
ffe884d
Compare
…rticles [Start #167966138]
ffe884d
to
8fda042
Compare
src/controllers/articleController.js
Outdated
article.title = title.trim(); | ||
article.slug = slugGen(title.trim()); | ||
} | ||
article.description = (description || originalArticle.description).trim(); |
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.
article.description = description ? description.trim() : originalArticle.description;
8fda042
to
0d7d7d9
Compare
…ah-backend into ft-user-update-and-delete-articles-167966138
035cf4a
to
1c657fb
Compare
What does this PR do?
Enables user to update, delete and get single article
How should this be manually tested?
git fetch
git checkout ft-user-update-delete-articles-167966138
npm install
npm run dev
Using postman test using the following endpoints
What are the relevant pivotal tracker stories?
Update or Delete Articles
Screenshots