Skip to content

Commit

Permalink
rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
Anguandia committed Aug 23, 2019
1 parent 3532a00 commit 122987c
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 120 deletions.
14 changes: 0 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
"bcrypt": "^3.0.6",
"body-parser": "^1.19.0",
"cloudinary": "^1.14.0",
<<<<<<< HEAD
"connect-multiparty": "^2.2.0",
=======
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]
"cors": "^2.8.5",
"dotenv": "^6.2.0",
"express": "^4.17.1",
Expand All @@ -42,10 +39,6 @@
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.15",
"method-override": "^2.3.10",
<<<<<<< HEAD
=======
"methods": "^1.1.2",
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]
"multer": "^1.4.2",
"nyc": "^14.1.1",
"passport": "^0.4.0",
Expand All @@ -60,16 +53,9 @@
"slug": "^1.1.0",
"swagger-jsdoc": "^3.3.0",
"swagger-ui-express": "^4.0.7",
<<<<<<< HEAD
"uniqid": "^5.0.3",
"validator": "^11.1.0",
"winston": "^3.2.1"
=======
"underscore": "^1.9.1",
"winston": "^3.2.1",
"zombie": "^6.1.4",
"uniqid": "^5.0.3"
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]
},
"devDependencies": {
"coveralls": "^3.0.5",
Expand Down
4 changes: 0 additions & 4 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import express from 'express';
import logging from './helpers/logging';
import routes from './routes/index';
import './config/cloudinary.config';
<<<<<<< HEAD
import { mock } from './middlewares/validators/socialLogin-mock';
=======

>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]

const app = express();

Expand Down
71 changes: 0 additions & 71 deletions src/controllers/articles.controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<<<<<<< HEAD
import 'dotenv/config';
import slug from 'slug';
import _ from 'lodash';
Expand All @@ -9,16 +8,6 @@ import articleService from '../services/article.service';
import Helper from '../helpers/helper';
import cloudinaryHelper from '../helpers/cloudinaryHelper';

=======
/* eslint-disable camelcase */
import 'dotenv/config';
import slug from 'slug';
import uniqid from 'uniqid';
import cloudinary from 'cloudinary';
import models from '../models';
import Userservice from '../services/user.service';
import articleService from '../services/article.service';
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]

const db = models.Article;
/**
Expand All @@ -39,33 +28,15 @@ class Articles {
static async createArticles(req, res) {
const userId = req.auth.id;
const findUser = await Userservice.getOneUser(userId);
<<<<<<< HEAD
const images = await cloudinaryHelper(req.files);

if (findUser) {
const { title } = req.body;
=======
let images = req.files;
images = await Promise.all(
images.map(async (file) => {
const { secure_url } = await cloudinary.v2.uploader.upload(file.path);
return secure_url;
})
);

if (findUser) {
const { title } = req.body;
const tags = req.body.taglist.split(' ');
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]
const article = {
slug: `${slug(title)}-${uniqid()}`,
title,
description: req.body.description,
body: req.body.body,
<<<<<<< HEAD
=======
taglist: tags,
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]
authorId: req.auth.id,
images
};
Expand All @@ -77,22 +48,12 @@ class Articles {
title: createdArticle.title,
description: createdArticle.description,
body: createdArticle.body,
<<<<<<< HEAD
flagged: createdArticle.flagged,
favorited: createdArticle.favorited,
favoritedcount: createdArticle.favoritedcount,
images: createdArticle.images,
createdAt: createdArticle.createdAt,
updatedAt: createdArticle.updatedAt
=======
taglist: createdArticle.taglist,
createdAt: createdArticle.createdAt,
updatedAt: createdArticle.updatedAt,
favorited: createdArticle.favorited,
favoritesCount: createdArticle.favoritesCount,
authorId: createdArticle.authorId,
images: createdArticle.images
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]
}
});
}
Expand All @@ -112,7 +73,6 @@ class Articles {
if (!articles) {
return res.status(200).json({ status: 200, message: 'There is no article.' });
}
<<<<<<< HEAD
const allArticles = _.map(articles, _.partialRight(_.pick, ['slug', 'title', 'description', 'body', 'taglist', 'favorited', 'favoritedcount', 'flagged', 'images', 'views']));

allArticles.map((article) => {
Expand All @@ -125,12 +85,6 @@ class Articles {
status: 200,
message: 'List of all articles',
data: allArticles
=======
return res.status(200).json({
status: 200,
articles,
message: 'List of all articles'
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]
});
}

Expand All @@ -147,7 +101,6 @@ class Articles {
const findArticle = await db.findOne({
where: { slug: req.params.slug }
});
<<<<<<< HEAD
if (!findArticle) {
return res.status(200).json({
status: 200,
Expand All @@ -161,17 +114,6 @@ class Articles {
status: 200,
message: 'Article successfully retrieved',
data: article
=======
if (findArticle) {
return res.status(200).json({
status: 200,
findArticle
});
}
return res.status(200).json({
status: 200,
message: 'That article does not exist!'
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]
});
}

Expand Down Expand Up @@ -244,19 +186,6 @@ class Articles {
updatedArticle
});
}
<<<<<<< HEAD
=======

/**
*
*
* @static
* @param {*} req
* @param {*} res
* @return {Object} articles
* @memberof Articles
*/
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]
}

export default Articles;
25 changes: 9 additions & 16 deletions src/controllers/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import Util from '../helpers/util';
import result from '../helpers/tags';

const util = new Util();
const internalError = () => {
util.setError(500, 'Internal Error');
return util;
};

const notFound = (msg) => {
util.setError(404, `${msg} not found`);
Expand All @@ -35,9 +31,7 @@ class TagController {
return res.status(201).json({ message: `tag ${name} created`, data: tag[0] });
}
res.status(200).json({ message: `tag ${name} exists`, data: tag[0] });
}).catch(() => {
internalError.send(res);
});
})
}

static async createArticleTag(req, res) {
Expand Down Expand Up @@ -67,7 +61,7 @@ class TagController {
returning: true,
}).then(updated => res.status(200).json({
message: `tag ${name} updated to ${newName}`, data: updated[1]
})).catch(() => internalError().send(res));
}))
}

static async editArticleTag(req, res) {
Expand All @@ -91,8 +85,7 @@ class TagController {
res.status(200).json({ message: 'update successful', data: updated[1][0] });
}
notFound(oldTag.name).send(res);
})
.catch(() => internalError());
});
}

static async getTags(req, res) {
Expand All @@ -105,7 +98,7 @@ class TagController {
}
// reduce tags list to give article numbers only
res.status(200).json({ tags });
}).catch(() => internalError().send(res));
});
}

static getTag(req, res) {
Expand All @@ -122,7 +115,7 @@ class TagController {
});
}
notFound('tag').send(res);
}).catch(() => internalError().send(res));
});
}

static async getTagArticles(req, res) {
Expand All @@ -138,7 +131,7 @@ class TagController {
res.status(200).json({
articles: articles.map(element => element.articles)
});
}).catch(() => internalError().send(res));
});
}

static async getArticleTags(req, res) {
Expand All @@ -151,7 +144,7 @@ class TagController {
return res.status(200).json({ message: 'article not tagged' });
}
res.status(200).json({ tags: article.tags.map(tag => tag.name) });
}).catch(() => internalError().send(res));
});
}

static async deleteArticleTag(req, res) {
Expand All @@ -170,7 +163,7 @@ class TagController {
res.status(404).json({
message: `this article has no tag ${req.params.tagId}`
});
}).catch(() => internalError().send(res));
});
}

static async deleteTagArticles(req, res) {
Expand All @@ -187,7 +180,7 @@ class TagController {
res.status(200).json({
message: `all articles about ${req.params.name} deleted`
});
}).catch(() => internalError().send(res));
});
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/helpers/decodeToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import env from 'dotenv';
import jwt from 'jsonwebtoken';

import { Article } from '../models';

const decodeToken = async (req) => {
let userId;
const { articleId } = req.body || '';
let token = req.headers['x-access-token'] || req.headers.authorization; req.headers['x-access-token'] || req.headers.authorization;
const defaultName = request.body.articleId ? await Article.findByPk(articleId): '';
const name = req.baody ? req.body.name || `${defaultName.title}-${new Date()}`: '';
if (token.startsWith('Bearer ')) {
token = token.slice(7, token.length);
}
if (token) {
jwt.verify(token, process.env.SECRET_KEY, (err, decode) => {
if (err) {
return null;
}
userId = decode.id
});
}
return { userId, name, articleId };
}

export default decodeToken;
1 change: 1 addition & 0 deletions src/middlewares/bookmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// block empty update name here
5 changes: 0 additions & 5 deletions src/middlewares/validators/general.validation.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
<<<<<<< HEAD
=======
/* eslint-disable no-useless-escape */
/* eslint-disable no-shadow */
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]
import Joi from 'joi';
import { restrictions } from './schemas';

Expand Down
6 changes: 0 additions & 6 deletions src/migrations/20190813125249-create-article.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ module.exports = {
type: Sequelize.TEXT,
allowNull: false,
},
<<<<<<< HEAD
=======
taglist: {
type: Sequelize.ARRAY(Sequelize.STRING)
},
>>>>>>> feature(create articles): user can create, read, update, and delete an article [Finishes #167313403]
favorited: {
type: Sequelize.BOOLEAN,
allowNull: true,
Expand Down
10 changes: 10 additions & 0 deletions src/routes/api/bookmarks/bookmarks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import BookMarkController from '../../../controllers/bookmarks.controller';
import auth from '../../../middlewares/auth';
import express from 'express';


const router = express.Router();
const { createBookMark, getUserBookMarks, getBookMarks } = BookMarkController;

router.get('/bookmarks', getBookMarks);
router.get('/bookmarks/collections', getCollections);
4 changes: 0 additions & 4 deletions src/seeders/20190816064246-test-articles.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = {
title: 'title1',
description: 'description1',
body: 'body1',
taglist: [''],
favorited: false,
favoritedcount: 0,
flagged: false,
Expand All @@ -22,7 +21,6 @@ module.exports = {
title: 'title2',
description: 'description2',
body: 'body2',
taglist: [''],
favorited: false,
favoritedcount: 0,
flagged: false,
Expand All @@ -37,7 +35,6 @@ module.exports = {
title: 'title3',
description: 'description3',
body: 'body3',
taglist: [''],
favorited: false,
favoritedcount: 0,
flagged: false,
Expand All @@ -52,7 +49,6 @@ module.exports = {
title: 'title4',
description: 'description4',
body: 'body4',
taglist: [''],
favorited: false,
favoritedcount: 0,
flagged: false,
Expand Down

0 comments on commit 122987c

Please sign in to comment.