Skip to content

Commit

Permalink
ft(create-article): create user article
Browse files Browse the repository at this point in the history
- Create model for article

ft(article): create article
	- create helper function to generate slug from title

feat(articles): update and delete artices

- modify article model
- add method to edit article
- add method to delete article
- restrict update to just (3) times

[Delivers #159206054]

feat(validate-input): Validate user input

- validate user input
- create user controller class
- check if email is unique
- check if username is unique
- fix Hound CI file extension error
- test for signup route

[Delivers #159206048]

chore(coverage): Increase coverage by 75%

- add tests for user profile modifications
- modify a utility function
- modify validate.js

[Delivers #159403248]

ft(create-article): create user article
- Write unit tests
- Create model for article and association with user model
- Create middleware to validate data to create article
- Create helper function to create article
- Create helper function to generate unique slugs
- Add image upload feature using cloudinary
- Create route and controller to create article
- Create route and controller get an article using slug parameter
- Create route and controller to get all articles

[Delivers #159206054]
  • Loading branch information
Olumide Ogundele authored and OKiMaureen committed Aug 27, 2018
1 parent 5d4bbaf commit 376cc51
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 11,007 deletions.
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/helpers/vsDebug.js"
}
]
}
15 changes: 15 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import dotenv from 'dotenv';

dotenv.config();

const config = {
secret: process.env.SECRET,
jwtSecret: process.env.JWT_TOKEN_SECRET,
cloudinary: {
cloud_name: process.env.CLOUD_NAME,
api_key: process.env.API_KEY,
api_secret: process.env.API_SECRET,
}
};

export default config;
8 changes: 4 additions & 4 deletions controllers/ArticleController.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ArticleController {
let offset = null;

if (page || limit) {
// calculate offset
// calculate offset
offset = limit * (page - 1);
}

Expand All @@ -105,9 +105,9 @@ class ArticleController {
})
.then((articles) => {
if (articles.length === 0) {
/** check if there was no article created
* for the page query
*/
/** check if there was no article created
* for the page query
*/
const message = page ? 'articles limit exceeded'
: 'Sorry, no articles created';
return res.status(200).json({
Expand Down
1 change: 0 additions & 1 deletion helpers/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ export default class Utilities {
})
.catch(next);
}

/**
* @function increaseCount
* @summary: A funtion to increase count
Expand Down
7 changes: 7 additions & 0 deletions helpers/vsDebug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const addsum = (a, b) => {
const sum = a + b;
const multiply = a * b;
const addMultilpy = sum + multiply;
return addMultilpy;
};
console.log(addsum(4, 3));
19 changes: 19 additions & 0 deletions middlewares/validateArticle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,33 @@
* or continue to the next middleware using next()
*/
const validateArticle = (req, res, next) => {
<<<<<<< HEAD
if (!req.body.article) {
return res.status(400).json({
errors: {
body: [
'Please check that article field is present'
=======
let { title, description, body } = req.body.article;
try {
title = title.trim();
description = description.trim();
body = body.trim();
} catch (error) {
return res.status(400).json({
errors: {
body: [
'Please check that your title, description or body field is not empty'
>>>>>>> ft(create-article): create user article
]
}
});
}
<<<<<<< HEAD
const { title, description, body } = req.body.article;

=======
>>>>>>> ft(create-article): create user article
if (!title || !description || !body) {
return res.status(400).json({
errors: {
Expand All @@ -27,9 +43,12 @@ const validateArticle = (req, res, next) => {
}
});
}
<<<<<<< HEAD
req.body.article.title = title.trim();
req.body.article.description = description.trim();
req.body.article.body = body.trim();
=======
>>>>>>> ft(create-article): create user article

next();
};
Expand Down
8 changes: 8 additions & 0 deletions migrations/20180730142739-create-article.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@ module.exports = {
type: Sequelize.STRING
},
body: {
<<<<<<< HEAD
type: Sequelize.TEXT
=======
type: Sequelize.STRING
>>>>>>> ft(create-article): create user article
},
updatedCount: {
type: Sequelize.INTEGER,
defaultValue: '0'
},
tagList: {
<<<<<<< HEAD
type: Sequelize.ARRAY(Sequelize.STRING)
=======
type: Sequelize.ARRAY(Sequelize.TEXT)
>>>>>>> ft(create-article): create user article
},
favorited: {
type: Sequelize.BOOLEAN
Expand Down
Loading

0 comments on commit 376cc51

Please sign in to comment.