Skip to content

Commit

Permalink
- modify controller
Browse files Browse the repository at this point in the history
- refactoring
  • Loading branch information
chikeozulumba committed May 24, 2019
1 parent d33117d commit d91ed91
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/controllers/article.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ import { saveNotifications } from '../services/notificationHandler';
export const addArticle = async (req, res) => {
try {
const { body, user } = req;
const { id: userId, fullName } = req.user;
const { id: userId, fullName, email, imageUrl, username, } = req.user;
delete body.isDeletedByAuthor;
let article = await Article.create({ userId, slug: slug(body.title), ...body });
const { dataValues } = article;
article = { authorName: fullName, ...dataValues };
article = { author: { id: userId, fullName, email, imageUrl, username, }, ...dataValues };
responseHandler(res, 201, {
status: 'success',
message: 'Your article was successfully created!',
Expand Down Expand Up @@ -72,7 +72,8 @@ export const addArticle = async (req, res) => {
*/
export const editArticle = async (req, res) => {
const success = 1;
const { body } = req;
const { body, user } = req;
const { id: userId, fullName, email, imageUrl, username, } = user;
delete body.isDeletedByAuthor;
try {
const { id } = req.params;
Expand All @@ -82,7 +83,10 @@ export const editArticle = async (req, res) => {
return responseHandler(res, 202, {
status: 'success',
message: 'Article updated successfully!',
data: updatedArticle,
data: {
...updatedArticle.get({ plain: true }),
author: { id: userId, fullName, email, imageUrl, username, },
},
});
}
} catch (error) {
Expand Down
1 change: 0 additions & 1 deletion src/controllers/authentication/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const viewUser = async (req, res) => {
'createdAt',
'updatedAt',
'notification',
'role',
],
},
});
Expand Down

0 comments on commit d91ed91

Please sign in to comment.