andela/codepirates-ah-backend

View on GitHub

Showing 142 of 142 total issues

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

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

          case 'twitter':
            await OpenUrlHelper.openUrl(`https://twitter.com/intent/tweet?url=${url}`);
            util.setSuccess(200, `Article shared to ${req.params.channel}`, url);
            return util.send(res);
    Severity: Major
    Found in src/controllers/articles.controller.js and 1 other location - About 1 hr to fix
    src/controllers/articles.controller.js on lines 299..302

    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 67.

    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

          case 'facebook':
            await OpenUrlHelper.openUrl(`https:www.facebook.com/sharer/sharer.php?u=${url}`);
            util.setSuccess(200, `Article shared to ${req.params.channel}`, url);
            return util.send(res);
    Severity: Major
    Found in src/controllers/articles.controller.js and 1 other location - About 1 hr to fix
    src/controllers/articles.controller.js on lines 303..306

    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 67.

    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 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

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

        export const checkQuery = (req, res, next) => {
          let {
            limit, page, popular, ...searchQueries
          } = req.query;
          const validQueries = ['author', 'keyword', 'tag', 'title'];
        Severity: Minor
        Found in src/middlewares/query.check.js - About 1 hr to fix

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

          module.exports = (sequelize, DataTypes) => {
            const Article = sequelize.define('Article', {
              slug: { type: DataTypes.STRING, allowNull: false },
              title: { type: DataTypes.STRING, allowNull: false },
              description: { type: DataTypes.TEXT, allowNull: false },
          Severity: Minor
          Found in src/models/article.js - About 1 hr to fix

            Function clap has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

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

              Function bodyHighlightedText has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                static async bodyHighlightedText(req, res) {
                  try {
                    const [{ id: userId }, { slug }, { startIndex, endIndex }] = [req.auth, req.params, req.query];
                    const start = Number(startIndex);
                    const end = Number(endIndex);
              Severity: Minor
              Found in src/controllers/highlight.controller.js - About 1 hr to fix

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

                module.exports = (sequelize, DataTypes) => {
                  const Comment = sequelize.define('Comment', {
                    userId: DataTypes.INTEGER,
                    articleSlug: {
                      type: DataTypes.STRING,
                Severity: Minor
                Found in src/models/comment.js - About 1 hr to fix

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

                        {
                          firstname: 'admin',
                          lastname: 'admin',
                          email: 'admin@gmail.com',
                          password: hashedpass,
                  Severity: Major
                  Found in src/seeders/20190805144119-admin.js and 1 other location - About 1 hr to fix
                  src/seeders/20190808074800-normal-user.js on lines 8..20

                  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 63.

                  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

                      {
                        firstname: 'user',
                        lastname: 'user',
                        email: 'user@gmail.com',
                        password: hashPassword,
                  Severity: Major
                  Found in src/seeders/20190808074800-normal-user.js and 1 other location - About 1 hr to fix
                  src/seeders/20190805144119-admin.js on lines 10..22

                  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 63.

                  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 35 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

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

                    Function requestPasswordReset has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      static async requestPasswordReset(req, res) {
                        // check if email provided exists in db
                        const { email } = req.body;
                        if (!email) {
                          return res.status(400).send({
                    Severity: Minor
                    Found in src/controllers/user.controller.js - About 1 hr to fix

                      Function listOfFollowedUsers has 33 lines of code (exceeds 25 allowed). 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: Minor
                      Found in src/controllers/follow.controller.js - About 1 hr to fix

                        Function listOfFollowers has 33 lines of code (exceeds 25 allowed). 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: Minor
                        Found in src/controllers/follow.controller.js - About 1 hr to fix

                          Function getArticleRating has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            static async getArticleRating(req, res) {
                              try {
                                // Initialize rating data
                                const { articleSlug } = req.params;
                                // check if rate is arleady there
                          Severity: Minor
                          Found in src/controllers/rating.controller.js - About 1 hr to fix

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

                                ArticleTag.associate = function (models) {
                                    ArticleTag.belongsTo(models.Article, { foreignKey: 'articleId' })
                                    ArticleTag.belongsTo(models.Tag, { foreignKey: 'tagId' })
                                };
                            Severity: Major
                            Found in src/models/articletag.js and 2 other locations - About 1 hr to fix
                            src/models/bookmark.js on lines 9..12
                            src/models/rate.js on lines 24..31

                            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 61.

                            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 3 locations. Consider refactoring.
                            Open

                              Rate.associate = function (models) {
                                Rate.belongsTo(models.user, {
                                  foreignKey: 'userEmail',
                                });
                                Rate.belongsTo(models.Article, {
                            Severity: Major
                            Found in src/models/rate.js and 2 other locations - About 1 hr to fix
                            src/models/articletag.js on lines 7..10
                            src/models/bookmark.js on lines 9..12

                            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 61.

                            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 3 locations. Consider refactoring.
                            Open

                                BookMark.associate = function (models) {
                                    BookMark.belongsTo(models.Article, { foreignKey: 'articleId' })
                                    BookMark.belongsTo(models.user, { foreignKey: 'userId' })
                                };
                            Severity: Major
                            Found in src/models/bookmark.js and 2 other locations - About 1 hr to fix
                            src/models/articletag.js on lines 7..10
                            src/models/rate.js on lines 24..31

                            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 61.

                            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

                            Severity
                            Category
                            Status
                            Source
                            Language