andela/codepirates-ah-backend

View on GitHub

Showing 67 of 142 total issues

File user.controller.js has 367 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import UserService from '../services/user.service';
import Helper from '../helpers/helper';
import EmailHelper from '../helpers/verification-email';
import sendPasswordResetEmailHelper from '../services/resetpassword.service';
import errorMiddleware from '../middlewares/error.middleware';
Severity: Minor
Found in src/controllers/user.controller.js - About 4 hrs to fix

    Function up has 72 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      up: (queryInterface, Sequelize) => {
        return queryInterface.createTable('users', {
          id: {
            allowNull: false,
            autoIncrement: true,
    Severity: Major
    Found in src/migrations/20190805142252-create-user.js - About 2 hrs to fix

      Function createAdmin has 65 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        static async createAdmin(req, res) {
          try {
            const theUser = await UserService.findOne(req.body.email, '');
            const theUserName = await UserService.findOne('', req.body.username);
            if (theUser) {
      Severity: Major
      Found in src/controllers/user.controller.js - About 2 hrs to fix

        Function up has 64 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          up: (queryInterface, Sequelize) => {
            return queryInterface.createTable('Articles', {
              id: {
                allowNull: false,
                autoIncrement: true,
        Severity: Major
        Found in src/migrations/20190813125249-create-article.js - About 2 hrs to fix

          Function getOneArticle has 56 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            static async getOneArticle(req, res) {
              const findArticle = await db.findOne({
                where: { slug: req.params.slug }
              });
              if (!findArticle) {
          Severity: Major
          Found in src/controllers/articles.controller.js - About 2 hrs to fix

            Function getAllArticles has 54 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              static async getAllArticles(req, res) {
                const counter = await db.count();
                if (req.offset >= counter) {
                  req.offset = 0;
                }
            Severity: Major
            Found in src/controllers/articles.controller.js - About 2 hrs to fix

              Function processSearchQuery has 53 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                static async processSearchQuery(req, res) {
                  const { q, offset, limit } = req.query;
                  const searchQuery = JSON.parse(q);
                  const articles = await ArticleModel.searchArticle(searchQuery.keyword, offset, limit);
                  const foundArticles = _.map(
              Severity: Major
              Found in src/controllers/search.controller.js - About 2 hrs to fix

                Function updateProfile has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  static async updateProfile(req, res) {
                    let filename = '';
                    if (req.files.image) {
                      filename = req.files.image.path;
                    }
                Severity: Minor
                Found in src/controllers/profile.controller.js - About 2 hrs to fix

                  Function signup has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    static async signup(req, res) {
                      const newUser = req.body;
                      newUser.email = req.body.email.toLowerCase();
                      try {
                        const theUser = await UserService.findOne(req.body.email, '');
                  Severity: Minor
                  Found in src/controllers/user.controller.js - About 1 hr to fix

                    Function up has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      up: (queryInterface, Sequelize) => {
                        return queryInterface.createTable('Likes', {
                          id: {
                            allowNull: false,
                            autoIncrement: true,
                    Severity: Minor
                    Found in src/migrations/20190816132215-create-likes.js - About 1 hr to fix

                      Function login has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        static async login(req, res) {
                          try {
                            let theUser;
                      
                            if (req.body.email) {
                      Severity: Minor
                      Found in src/controllers/user.controller.js - About 1 hr to fix

                        Function up has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          up: (queryInterface, Sequelize) => {
                            return queryInterface.createTable('Comments', {
                              id: {
                                allowNull: false,
                                autoIncrement: true,
                        Severity: Minor
                        Found in src/migrations/20190816101310-create-comment.js - About 1 hr to fix

                          Function exports has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          module.exports = (sequelize, DataTypes) => {
                            const user = sequelize.define('user', {
                              firstname: DataTypes.STRING,
                              lastname: DataTypes.STRING,
                              email: DataTypes.STRING,
                          Severity: Minor
                          Found in src/models/user.js - About 1 hr to fix

                            Function notifyViaEmailAndPush has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                              static async notifyViaEmailAndPush(req, res, slug) {
                                try {
                                  const followedUser = await models.user.findOne({ where: { email: req.auth.email } });
                                  const myFollowers = await models.Follow.findAll({
                                    where: { followedUserId: followedUser.id },
                            Severity: Minor
                            Found in src/services/notification.service.js - About 1 hr to fix

                              Function handlePasswordReset has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                static async handlePasswordReset(req, res) {
                                  // verify token and if its not expired
                                  const { token } = req.params;
                                  const tokenDecoded = Helper.verifyToken(token);
                                  if (tokenDecoded === 'invalid token') {
                              Severity: Minor
                              Found in src/controllers/user.controller.js - About 1 hr to fix

                                Function up has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                  up: (queryInterface, Sequelize) => {
                                    return queryInterface.createTable('reportings', {
                                      id: {
                                        allowNull: false,
                                        autoIncrement: true,
                                Severity: Minor
                                Found in src/migrations/20190823185735-create-reporting.js - About 1 hr to fix

                                  Function login has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                    static async login(req, res) {
                                      data = req.user;
                                      const type = data.provider;
                                      try {
                                        let user;
                                  Severity: Minor
                                  Found in src/controllers/social.js - About 1 hr to fix

                                    Function dislike has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                      static async dislike(req, res) {
                                        try {
                                          if (req.body.author === req.body.userId) {
                                            util.setError(401, 'You can not dislike to your own post');
                                            return util.send(res);
                                    Severity: Minor
                                    Found in src/controllers/likes.controller.js - About 1 hr to fix

                                      Function validateToken has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                      const validateToken = async (req, res, next) => {
                                        let token = req.headers['x-access-token'] || req.headers.authorization;
                                        if (!token) {
                                          return res.status(401).send({
                                            status: 401,
                                      Severity: Minor
                                      Found in src/middlewares/auth.js - About 1 hr to fix

                                        Function up has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                                        Open

                                          up: (queryInterface, Sequelize) => {
                                            return queryInterface.createTable('Rates', {
                                              id: {
                                                allowNull: false,
                                                autoIncrement: true,
                                        Severity: Minor
                                        Found in src/migrations/20190814093719-create-rate.js - About 1 hr to fix
                                          Severity
                                          Category
                                          Status
                                          Source
                                          Language