Skip to content

Commit

Permalink
Merge 4639ce1 into ac4be16
Browse files Browse the repository at this point in the history
  • Loading branch information
codeBlock-1984 committed Jul 18, 2019
2 parents ac4be16 + 4639ce1 commit 347cee4
Show file tree
Hide file tree
Showing 29 changed files with 287 additions and 242 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build": "babel src -d lib",
"pretest": "npm run undo:migrate && npm run migrate && npm run seed",
"test": "NODE_ENV=test mocha --timeout 50000 --require @babel/register --exit",
"tes": "NODE_ENV=test mocha --timeout 50000 --require @babel/register ./test/user.test.js --exit",
"generate-lcov": "nyc report --reporter=text-lcov > lcov.info",
"coveralls-coverage": "coveralls < lcov.info",
"coverage": "nyc npm test && npm run generate-lcov && npm run coveralls-coverage",
Expand Down
41 changes: 25 additions & 16 deletions src/controllers/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class AuthController {
message: 'A link has been sent to your mailbox for verification',
token
});
} catch (err) {
} catch (error) {
return res.status(500).json({
status: 500,
message: 'Internal server error'
error: error.message
});
}
}
Expand Down Expand Up @@ -80,7 +80,7 @@ class AuthController {
return res.status(200).json({
status: '200',
message: 'Your account has been verified',
data: [verifiedUser]
token: verifiedUser.token
});
}
return res.status(400).json({
Expand Down Expand Up @@ -132,14 +132,23 @@ class AuthController {
status: 200,
message: 'User Login successful',
token,
data: user
data: [ user ]
});
}
return res.status(401).json({ error: true, message: 'Invalid email or password' });
return res.status(401).json({
status: 401,
message: 'Invalid email or password'
});
}
return res.status(401).json({ error: true, message: 'Invalid email or password' });
} catch (err) {
return res.status(500).json({ error: true, message: 'Internal Server error' });
return res.status(401).json({
status: 401,
message: 'Invalid email or password'
});
} catch (error) {
return res.status(500).json({
status: 500,
error: error.message
});
}
}

Expand All @@ -160,12 +169,12 @@ class AuthController {
});
return res.status(200).json({
status: 200,
message: 'User successfully Logged Out',
message: 'User successfully logged out',
});
} catch (error) {
return res.status(500).json({
status: 500,
data: error,
error: error.message,
});
}
}
Expand Down Expand Up @@ -228,12 +237,12 @@ class AuthController {
// RETURN SUCCESS IF SUCCESS
return res.status(200).json({
status: 200,
message: 'reset code resent to your email',
message: 'A reset code has been resent to your email',
});
} catch (err) {
} catch (error) {
return res.status(500).json({
status: 500,
message: 'Internal server error',
error: error.message,
});
}
}
Expand Down Expand Up @@ -268,12 +277,12 @@ class AuthController {
// RETURN SUCCESS IF SUCCESS
return res.status(200).json({
status: 200,
message: 'password reset successful',
message: 'Password reset successful',
});
} catch (err) {
} catch (error) {
return res.status(500).json({
status: 500,
message: 'Internal server error',
error: error.message,
});
}
}
Expand Down
42 changes: 26 additions & 16 deletions src/controllers/CommentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@ class CommentController {
const { id, createdAt, updatedAt } = comment;
return res.status(201).json({
status: 201,
message: 'Comment Added Successfully',
id,
commentBody,
createdAt,
updatedAt,
author: {
userName,
bio,
imageUrl
}
message: 'Comment added successfully',
data: [
{
id,
commentBody,
createdAt,
updatedAt,
author: {
userName,
bio,
imageUrl
}
}
]
});
} catch (error) {
return res.status(500).json({
status: 500,
message: error.message
error: error.message
});
}
}
Expand All @@ -67,21 +71,27 @@ class CommentController {
limit: defaultLimit,
offset
});

const pages = Math.ceil(count / limit) || 1;
offset = limit * (defaultPage - 1);

return res.status(200).json({
status: 200,
message: 'All comments fetched successfully',
article,
comments,
pages
data: [
{
articleId,
comments,
totalComments: count,
currentPage,
limit,
totalPages: pages
}
]
});
} catch (error) {
return res.status(500).json({
status: 500,
message: error.message
error: error.message
});
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/controllers/articleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ class ArticleController {
await Tag.bulkCreate(newTagDetails);

return res.status(201).json({
message: 'article successfully created',
article: newArticle
status: 201,
message: 'Article successfully created',
data: [ newArticle ]
});
} catch (error) {
return res.status(500).json({
message: 'Internal server error',
error
return res.status(500).json({
status: 500,
error: error.message
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/likeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ class LikeController {
await likedArticle.destroy();
return res.status(200).json({
status: 200,
data: article,
message: 'You just unliked this article',
data: [ article ],
});
}

await Like.create({ userId, articleId: article.id });

return res.status(201).json({
status: 201,
data: article,
message: 'You just liked this article',
data: [ article ],
});
} catch (error) {
return res.status(500).json({
Expand Down
41 changes: 28 additions & 13 deletions src/controllers/ratingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ class RatingController {
return res.status(200).json({
status: 200,
message: `Article rating has been updated as ${value} star`,
article,
rating: previousRating.value
data: [
{
articleId,
rating: previousRating.value
}
]
});
}
const rating = await Rating.create({
Expand All @@ -42,13 +46,17 @@ class RatingController {
return res.status(200).json({
status: 200,
message: `Article has been rated as ${value} star`,
article,
rating: rating.value,
data: [
{
articleId,
rating: rating.value,
}
]
});
} catch (err) {
} catch (error) {
return res.status(500).json({
status: 500,
message: 'Internal server error'
error: error.message
});
}
}
Expand All @@ -58,8 +66,8 @@ class RatingController {
* @returns { object } res
* @description - paginate article ratings
* @static
* @param {*} req
* @param {*} res
* @param {object} req
* @param {object} res
* @memberof RatingController
*/
static async getAllArticlesRating(req, res){
Expand All @@ -85,15 +93,22 @@ static async getAllArticlesRating(req, res){
return res.status(200).json({
status: 200,
message: 'All Ratings fetched successfully',
article,
rating,
pages
data: [
{
articleId,
rating,
totalRating: count,
currentPage,
limit,
totalPages: pages
}
]
});

} catch(err){
} catch(error){
return res.status(500).json({
status: 500,
message: 'Internal server error'
error: error.message
})
}
}
Expand Down
27 changes: 16 additions & 11 deletions src/controllers/socialController.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export default class socialController {
});

if (!user) {
return res.status(404).send('user not found');
return res.status(404).json({
status: 404,
message: 'User not found'
});
}

const {
Expand All @@ -74,18 +77,20 @@ export default class socialController {

return res.status(200).json({
message: 'successful',
data: {
token,
firstname,
lastname,
bio,
image
}
data: [
{
token,
firstname,
lastname,
bio,
image
}
]
});
} catch (err) {
} catch (error) {
return res.status(500).json({
status: 'error',
message: err.message
status: 500,
error: error.message
});
}
}
Expand Down
18 changes: 10 additions & 8 deletions src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ class UserController {
if (!userData) {
return res.status(404).json({
status: 404,
error: 'User not found',
message: 'User not found',
});
}

return res.status(200).json({
status: 200,
users: userData,
message: 'Operation successful',
data: [ userData ],
});
} catch (error) {
return res.status(500).json({
Expand Down Expand Up @@ -86,18 +87,19 @@ class UserController {

return res.status(200).json({
status: 200,
user: userDetails,
message: 'Profile updated successfully',
data: [userDetails],
});
}
return res.status(401).json({
status: 401,
error: 'You do not have permission to perform that operation',
message: 'You do not have permission to perform that operation',
});
} catch (error) {
if (error.routine === '_bt_check_unique') {
return res.status(400).json({
status: 400,
error: 'User with that username already exists',
message: 'User with that username already exists',
});
}
return res.status(500).json({
Expand Down Expand Up @@ -136,7 +138,7 @@ class UserController {
});
return res.status(200).json({
status: 200,
data: `you just followed ${user.userName}`,
message: `You just followed ${user.userName}`,
});
}

Expand All @@ -149,12 +151,12 @@ class UserController {
});
return res.status(200).json({
status: 200,
data: `you just unfollowed ${user.userName}`,
message: `You just unfollowed ${user.userName}`,
});
} catch (error) {
return res.status(500).json({
status: 500,
data: error,
error: error.message,
});
}
}
Expand Down
Loading

0 comments on commit 347cee4

Please sign in to comment.