Skip to content

Commit

Permalink
Merge pull request #71 from andela/bg-fix-update-article-image-bug
Browse files Browse the repository at this point in the history
fix missing images ptoperty bug in article update
  • Loading branch information
bdushimi committed Nov 7, 2019
2 parents 1cb2e38 + 4dfa2a7 commit e219388
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/controllers/articles.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ class Articles {
lastname,
image
};
const rating = await RateService.getArticleRatingStatistic(article.slug);
const rating = await RateService.getArticleRatingStatistic(
article.slug
);
let claps = await likeService.getAllAClaps(article.slug);
claps = Object.values(claps)[0];
const readTime = Helper.calculateReadTime(article.body);
Expand Down Expand Up @@ -333,7 +335,10 @@ class Articles {
return util.send(res);
}
if (req.auth.id !== findArticle.authorId) {
util.setError(403, 'Sorry you can not DELETE an article that does not belong to you.');
util.setError(
403,
'Sorry you can not DELETE an article that does not belong to you.'
);
return util.send(res);
}
await db.destroy({
Expand Down Expand Up @@ -361,15 +366,20 @@ class Articles {
return util.send(res);
}
if (req.auth.id !== findArticle.authorId) {
util.setError(401, 'Sorry you can not UPDATE an article that does not belong to you.');
util.setError(
401,
'Sorry you can not UPDATE an article that does not belong to you.'
);
return util.send(res);
}
const { title, body, description } = req.body;
const {
title, body, description, images
} = req.body;
const updatedArticle = await articleService.updateArticle(req.params.slug, {
slug: `${slug(title)}-${uniqid()}`,
title,
body,
description,
images,
taglist: req.body.taglist.split(' ')
});
util.setSuccess(200, 'Article Updated successfully!', updatedArticle);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api/article/article.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ router.delete(
[auth, confirmEmailAuth],
articleController.deleteArticle
);
router.patch(
router.put(
'/:slug',
[auth, confirmEmailAuth],
imageUpload.array('images', 10),
Expand Down

0 comments on commit e219388

Please sign in to comment.