Skip to content

Commit

Permalink
Merge cd019ca into f37ea46
Browse files Browse the repository at this point in the history
  • Loading branch information
salviosage committed Oct 24, 2019
2 parents f37ea46 + cd019ca commit 859ce8b
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js

node_js:
- 'stable'
- '10.16.0'

cache:
directories:
Expand Down
114 changes: 57 additions & 57 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,65 @@
"author": "Andela Simulations Programme",
"license": "MIT",
"dependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/node": "^7.5.5",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.5.5",
"@babel/runtime": "^7.5.5",
"@sendgrid/mail": "^6.4.0",
"bcrypt": "^3.0.6",
"body-parser": "^1.19.0",
"cloudinary": "^1.14.0",
"connect-multiparty": "^2.2.0",
"cors": "^2.8.5",
"dotenv": "^6.2.0",
"express": "^4.17.1",
"express-async-errors": "^3.1.1",
"express-session": "^1.15.6",
"joi": "^14.3.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.15",
"method-override": "^2.3.10",
"moment": "^2.24.0",
"multer": "^1.4.2",
"nyc": "^14.1.1",
"open": "^6.4.0",
"passport": "^0.4.0",
"passport-facebook": "^3.0.0",
"passport-google-oauth": "^2.0.0",
"passport-twitter": "^1.0.4",
"pg": "^7.12.0",
"pg-hstore": "^2.3.3",
"pusher": "^2.2.2",
"request": "^2.87.0",
"sequelize": "^5.11.0",
"sequelize-cli": "^5.5.0",
"slug": "^1.1.0",
"swagger-jsdoc": "^3.3.0",
"swagger-ui-express": "^4.0.7",
"uniqid": "^5.0.3",
"validator": "^11.1.0",
"winston": "^3.2.1"
"@babel/cli": "7.5.5",
"@babel/core": "7.5.5",
"@babel/node": "7.5.5",
"@babel/plugin-transform-runtime": "7.5.5",
"@babel/polyfill": "7.4.4",
"@babel/preset-env": "7.5.5",
"@babel/register": "7.5.5",
"@babel/runtime": "7.5.5",
"@sendgrid/mail": "6.4.0",
"bcrypt": "3.0.6",
"body-parser": "1.19.0",
"cloudinary": "1.14.0",
"connect-multiparty": "2.2.0",
"cors": "2.8.5",
"dotenv": "6.2.0",
"express": "4.17.1",
"express-async-errors": "3.1.1",
"express-session": "1.15.6",
"joi": "14.3.1",
"jsonwebtoken": "8.5.1",
"lodash": "4.17.15",
"method-override": "2.3.10",
"moment": "2.24.0",
"multer": "1.4.2",
"nyc": "14.1.1",
"open": "6.4.0",
"passport": "0.4.0",
"passport-facebook": "3.0.0",
"passport-google-oauth": "2.0.0",
"passport-twitter": "1.0.4",
"pg": "7.12.0",
"pg-hstore": "2.3.3",
"pusher": "2.2.2",
"request": "2.87.0",
"sequelize": "5.11.0",
"sequelize-cli": "5.5.0",
"slug": "1.1.0",
"swagger-jsdoc": "3.3.0",
"swagger-ui-express": "4.0.7",
"uniqid": "5.0.3",
"validator": "11.1.0",
"winston": "3.2.1"
},
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/node": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.5.5",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"coveralls": "^3.0.5",
"eslint": "^6.1.0",
"eslint-config-airbnb-base": "^13.2.0",
"eslint-plugin-import": "^2.18.2",
"mocha": "^6.2.0",
"nodemon": "^1.19.1",
"sinon": "^7.4.1",
"sinon-chai": "^3.3.0"
"@babel/cli": "7.5.5",
"@babel/core": "7.5.5",
"@babel/node": "7.5.5",
"@babel/preset-env": "7.5.5",
"@babel/register": "7.5.5",
"chai": "4.2.0",
"chai-http": "4.3.0",
"coveralls": "3.0.5",
"eslint": "6.1.0",
"eslint-config-airbnb-base": "13.2.0",
"eslint-plugin-import": "2.18.2",
"mocha": "6.2.0",
"nodemon": "1.19.1",
"sinon": "7.4.1",
"sinon-chai": "3.3.0"
},
"nyc": {
"exclude": [
Expand Down
74 changes: 47 additions & 27 deletions src/controllers/articles.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import Userservice from '../services/user.service';
import articleService from '../services/article.service';
import Helper from '../helpers/helper';
import NotificationServices from '../services/notification.service';
import cloudinaryHelper from '../helpers/cloudinaryHelper';
// import cloudinaryHelper from '../helpers/cloudinaryHelper';
import OpenUrlHelper from '../helpers/share.article.helper';
import Util from '../helpers/util';
import statsService from '../services/db.service';
import likeService from '../services/likes.service';
import RateService from '../services/rate.service';

const { notifyViaEmailAndPush } = NotificationServices;
const util = new Util();
Expand Down Expand Up @@ -116,13 +118,27 @@ class Articles {
allArticles.map(async (article) => {
try {
const userDetails = await Userservice.getOneUser(article.authorId);
const { username, image } = userDetails;
const {
username, firstname, lastname, image
} = userDetails;
const user = {
username,
firstname,
lastname,
image
};
const rating = await RateService.getArticleRatingStatistic(article.slug);
let claps = await likeService.getAllAClaps(req.params.Article);
claps = Object.values(claps)[0];
const readTime = Helper.calculateReadTime(article.body);
const timeAgo = moment(article.createdAt).fromNow();
article.readtime = readTime;
article.username = username;
article.userImage = image;
article.timeCreated = timeAgo;
article.claps = claps;
article.rating = rating.dataValues.rating;
article.author = user;
return true;
} catch (error) {
throw error;
Expand Down Expand Up @@ -229,6 +245,7 @@ class Articles {
}

const article = _.pick(findArticle, [
'authorId',
'slug',
'title',
'description',
Expand All @@ -240,10 +257,26 @@ class Articles {
'images',
'views'
]);
const userDetails = await Userservice.getOneUser(article.authorId);
const {
username, firstname, lastname, image
} = userDetails;
const user = {
username,
firstname,
lastname,
image
};
const timeAgo = moment(article.createdAt).fromNow();
const readTime = Helper.calculateReadTime(article.body);
const rating = await RateService.getArticleRatingStatistic(article.slug);
let claps = await likeService.getAllAClaps(req.params.Article);
claps = Object.values(claps)[0];
article.readtime = readTime;
article.createdAt = timeAgo;
article.rating = rating.dataValues.rating;
article.claps = claps;
article.author = user;
if (req.auth) {
const { description } = article;
const readerId = req.auth.id;
Expand Down Expand Up @@ -293,25 +326,18 @@ class Articles {
where: { slug: req.params.slug }
});
if (!findArticle) {
return res.status(200).json({
status: 200,
message: 'That article does not exist!'
});
util.setError(404, 'That article does not exist!');
return util.send(res);
}
if (req.auth.id !== findArticle.authorId) {
return res.status(403).json({
status: 403,
message:
'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({
where: { slug: req.params.slug }
});
return res.status(200).json({
status: 200,
message: 'Article was deleted succussfully!'
});
util.setSuccess(200, 'Article was deleted succussfully!');
return util.send(res);
}

/**
Expand All @@ -328,16 +354,12 @@ class Articles {
where: { slug: req.params.slug }
});
if (!findArticle) {
return res
.status(200)
.json({ status: 200, message: 'That article does not exist' });
util.setError(404, 'That article does not exist!');
return util.send(res);
}
if (req.auth.id !== findArticle.authorId) {
return res.status(403).json({
status: 403,
message:
'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 updatedArticle = await articleService.updateArticle(req.params.slug, {
Expand All @@ -347,10 +369,8 @@ class Articles {
description,
taglist: req.body.taglist.split(' ')
});
return res.status(200).json({
status: 200,
updatedArticle
});
util.setSuccess(200, 'Article Updated successfully!', updatedArticle);
return util.send(res);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class UserController {

const token = await Helper.generateToken(payload, (60 * 60));
// create password reset link
const resetUrl = `${process.env.FRONT_END_URL}/reset?token=${token}`;
const resetUrl = `${process.env.FRONT_END_URL}/resetpassword?token=${token}`;

// send email to user email address
const emailSent = await sendPasswordResetEmailHelper.sendEmail(user.email, user.username, resetUrl);
Expand Down

0 comments on commit 859ce8b

Please sign in to comment.