andela/codepirates-ah-backend

View on GitHub

Showing 142 of 142 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  static async listOfFollowers(req, res, next) {
    try {
      const followedUser = await models.user.findOne({ where: { email: req.auth.email } });
      const myFollowers = await models.Follow.findAll({
        where: { followedUserId: followedUser.id },
Severity: Major
Found in src/controllers/follow.controller.js and 1 other location - About 1 day to fix
src/controllers/follow.controller.js on lines 61..95

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 292.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  static async listOfFollowedUsers(req, res, next) {
    try {
      const follower = await models.user.findOne({ where: { email: req.auth.email } });
      const usersIfollow = await models.Follow.findAll({
        where: { followerId: follower.id },
Severity: Major
Found in src/controllers/follow.controller.js and 1 other location - About 1 day to fix
src/controllers/follow.controller.js on lines 107..141

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 292.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    await Promise.all(allArticles.map(async (article) => {
      try {
        const userDetails = await Userservice.getOneUser(article.authorId);
        const { username, image } = userDetails;
        const readTime = Helper.calculateReadTime(article.body);
Severity: Major
Found in src/controllers/articles.controller.js and 1 other location - About 7 hrs to fix
src/controllers/search.controller.js on lines 47..61

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 179.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    await Promise.all(foundArticles.map(async (article) => {
      try {
        const userDetails = await UserModel.getOneUser(article.authorId);
        const { username, image } = userDetails;
        const readTime = Helper.calculateReadTime(article.body);
Severity: Major
Found in src/controllers/search.controller.js and 1 other location - About 7 hrs to fix
src/controllers/articles.controller.js on lines 108..122

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 179.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

export default (req, res, next) => {
  const { userId } = req.params;

  const schema = {
    userId: Joi.number().positive().required()
Severity: Major
Found in src/middlewares/validators/userId.validation.js and 1 other location - About 7 hrs to fix
src/middlewares/validators/articleId.validation.js on lines 6..26

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 177.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

export default (req, res, next) => {
  const { articleId } = req.params;

  const schema = {
    articleId: Joi.number().positive().required()
Severity: Major
Found in src/middlewares/validators/articleId.validation.js and 1 other location - About 7 hrs to fix
src/middlewares/validators/userId.validation.js on lines 6..26

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 177.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('Follows', {
      id: {
        allowNull: false,
Severity: Major
Found in src/migrations/20190813140342-create-follow.js and 1 other location - About 6 hrs to fix
src/migrations/20190822015903-create-favorites.js on lines 2..30

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 160.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('Favorites', {
      id: {
        allowNull: false,
Severity: Major
Found in src/migrations/20190822015903-create-favorites.js and 1 other location - About 6 hrs to fix
src/migrations/20190813140342-create-follow.js on lines 2..30

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 160.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        if (userColumn === 'subscribed') {
          const { subscribed } = updatedUser[1][0].dataValues;
          if (subscribed === newNotificationStatus) {
            const message = subscribed === true ? 'You have successfully subscribed to our email notifications' : 'You will no longer receive email notifications from us';
            return res.status(200).json({ message, statusCode: 200 });
    Severity: Major
    Found in src/helpers/notification.helper.js and 1 other location - About 2 hrs to fix
    src/helpers/notification.helper.js on lines 30..36

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 94.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        if (userColumn === 'inAppNotification') {
          const { inAppNotification } = updatedUser[1][0].dataValues;
          if (inAppNotification === newNotificationStatus) {
            const message = inAppNotification === true ? 'You have successfully subscribed to in app notifications' : 'You will no longer receive in-app notifications from us';
            return res.status(200).json({ message, statusCode: 200 });
    Severity: Major
    Found in src/helpers/notification.helper.js and 1 other location - About 2 hrs to fix
    src/helpers/notification.helper.js on lines 23..29

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 94.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            facebook_existing: {
              id: '2467093749978894',
              username: undefined,
              displayName: undefined,
              name: {
          Severity: Major
          Found in src/mock-data.js and 1 other location - About 2 hrs to fix
          src/mock-data.js on lines 47..66

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 83.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            facebook_new: {
              id: '2467093749978894',
              username: undefined,
              displayName: undefined,
              name: {
          Severity: Major
          Found in src/mock-data.js and 1 other location - About 2 hrs to fix
          src/mock-data.js on lines 2..21

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 83.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          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
                  Severity
                  Category
                  Status
                  Source
                  Language