Skip to content

Commit

Permalink
Merge b66c2f6 into 6b2ec24
Browse files Browse the repository at this point in the history
  • Loading branch information
amaechi-chuks committed Apr 11, 2019
2 parents 6b2ec24 + b66c2f6 commit 04811e8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 13 deletions.
8 changes: 2 additions & 6 deletions server/controllers/follow.controllers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import model from '../models';
import validations from '../helpers/validations';

const { User, Follower } = model;

Expand All @@ -17,10 +16,8 @@ const followController = {
*/
async followUser(req, res) {
try {
const token = validations.verifyAuthHeader(req);
const { id: followerId } = token.userObj;
const followerId = req.user.userObj.id;
const { followeeId } = req.params;
// Get followee from followee table
const findUnFollowee = await User.findOne({ where: { id: followeeId } });
if (!findUnFollowee) {
return res.status(404).json({
Expand Down Expand Up @@ -67,8 +64,7 @@ const followController = {

async unFollowUser(req, res) {
try {
const token = validations.verifyAuthHeader(req);
const { id: followerId } = token.userObj;
const followerId = req.user.userObj.id;
const { unFolloweeId } = req.params;
const findFollowee = await User.findOne({
where: { id: unFolloweeId },
Expand Down
7 changes: 2 additions & 5 deletions server/controllers/get-followers.controllers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import models from '../models';
import validations from '../helpers/validations';
import serverError from '../helpers/server-error';

const { User, Follower } = models;
Expand All @@ -14,8 +13,7 @@ const { User, Follower } = models;
*/
const getFollowers = async (req, res) => {
try {
const token = validations.verifyAuthHeader(req);
const { id: userId } = token.userObj;
const userId = req.user.userObj.id;
const users = await Follower.findAll({
where: {
followee_id: userId,
Expand Down Expand Up @@ -57,8 +55,7 @@ const getFollowers = async (req, res) => {
* @return {undefined}
*/
const getFollowing = async (req, res) => {
const token = validations.verifyAuthHeader(req);
const { id: userId } = token.userObj;
const userId = req.user.userObj.id;
try {
const users = await Follower.findAll({
where: { follower_id: userId },
Expand Down
3 changes: 1 addition & 2 deletions server/controllers/like.controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import serverError from '../helpers/server-error';
const { Article, User } = model;

const toggleLike = async (req, res) => {
const token = validations.verifyAuthHeader(req);
const { id: userId } = token.userObj;
const userId = req.user.userObj.id;
const { articleId } = req.params;
try {
// validate article and user Id
Expand Down

0 comments on commit 04811e8

Please sign in to comment.