andela/codepirates-ah-backend

View on GitHub

Showing 142 of 142 total issues

Function checkDuplicate has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  static async checkDuplicate(req, res, next) {
    const { articleId, name } = req.body;
    const existing = await checkItem({ userId: req.auth.id, articleId });
    const existingName = await checkItem({ name });
    const bookmark = await checkItem({ userId: req.auth.id, name, articleId });
Severity: Minor
Found in src/middlewares/bookmarks.js - About 1 hr to fix

    Function login has a Cognitive Complexity of 11 (exceeds 5 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

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function notifyUsersWhoFavorited has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static async notifyUsersWhoFavorited(req, res, articleId, slug) {
        try {
          // returns an array of userIDs have favorited the article commented on
          const arrayOfUserIDs = await models.Favorites.findAll({ where: { articleId } }).map(item => item.dataValues.userId);
    
    
    Severity: Minor
    Found in src/services/notification.service.js - About 1 hr to fix

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

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

        Function createArticles has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          static async createArticles(req, res) {
            const userId = req.auth.id;
            const findUser = await Userservice.getOneUser(userId);
            // const images = await cloudinaryHelper.generateCloudinaryUrl(req.files);
            const { images } = req.body;
        Severity: Minor
        Found in src/controllers/articles.controller.js - About 1 hr to fix

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

          module.exports = (sequelize, DataTypes) => {
            const Rate = sequelize.define('Rate', {
              userEmail: {
                type: DataTypes.STRING,
                references: {
          Severity: Minor
          Found in src/models/rate.js - About 1 hr to fix

            Function sendEmail has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const sendEmail = (email, username, url) => {
              sgMail.setApiKey(process.env.SendGridApiKey);
            
              const msg = {
                to: `${email}`,
            Severity: Minor
            Found in src/services/resetpassword.service.js - About 1 hr to fix

              Function sendEmail has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export const sendEmail = (email, username, url) => {
                sgMail.setApiKey(process.env.SendGridApiKey);
              
                const msg = {
                  to: `${email}`,
              Severity: Minor
              Found in src/helpers/verification-email.js - About 1 hr to fix

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

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

                  Function updateUser has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

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

                    Function deleteComment has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      static async deleteComment(req, res) {
                        const userId = req.auth.id;
                        const getUser = await CommentsDb.findOne({ where: { userId } });
                        const commentAuthor = getUser && getUser.get().userId;
                        const { id } = req.params;
                    Severity: Minor
                    Found in src/controllers/comments.controller.js - About 1 hr to fix

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

                            if (theUser) {
                              return res.status(409).send({
                                status: 409,
                                message: `Cannot register admin with an email ${req.body.email} which is already in use.`
                              });
                      Severity: Minor
                      Found in src/controllers/user.controller.js and 1 other location - About 55 mins to fix
                      src/controllers/user.controller.js on lines 92..99

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

                      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 (theUserName) {
                              return res.status(409).send({
                                status: 409,
                                message: `Cannot register admin with the username ${
                                  req.body.username
                      Severity: Minor
                      Found in src/controllers/user.controller.js and 1 other location - About 55 mins to fix
                      src/controllers/user.controller.js on lines 86..91

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

                      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 a Cognitive Complexity of 9 (exceeds 5 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 55 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

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

                          {
                            firstname: 'userfour',
                            lastname: 'userfour',
                            email: 'userfour@gmail.com',
                            password: hashPassword,
                      Severity: Major
                      Found in src/seeders/20190808074800-normal-user.js and 5 other locations - About 55 mins to fix
                      src/seeders/20190808074800-normal-user.js on lines 21..31
                      src/seeders/20190808074800-normal-user.js on lines 32..42
                      src/seeders/20190808074800-normal-user.js on lines 54..64
                      src/seeders/20190808074800-normal-user.js on lines 65..75
                      src/seeders/20190808074800-normal-user.js on lines 76..86

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

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

                          {
                            firstname: 'usersix',
                            lastname: 'usersix',
                            email: 'usersix@gmail.com',
                            password: hashPassword,
                      Severity: Major
                      Found in src/seeders/20190808074800-normal-user.js and 5 other locations - About 55 mins to fix
                      src/seeders/20190808074800-normal-user.js on lines 21..31
                      src/seeders/20190808074800-normal-user.js on lines 32..42
                      src/seeders/20190808074800-normal-user.js on lines 43..53
                      src/seeders/20190808074800-normal-user.js on lines 54..64
                      src/seeders/20190808074800-normal-user.js on lines 76..86

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

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

                          {
                            firstname: 'userfive',
                            lastname: 'userfive',
                            email: 'userfive@gmail.com',
                            password: hashPassword,
                      Severity: Major
                      Found in src/seeders/20190808074800-normal-user.js and 5 other locations - About 55 mins to fix
                      src/seeders/20190808074800-normal-user.js on lines 21..31
                      src/seeders/20190808074800-normal-user.js on lines 32..42
                      src/seeders/20190808074800-normal-user.js on lines 43..53
                      src/seeders/20190808074800-normal-user.js on lines 65..75
                      src/seeders/20190808074800-normal-user.js on lines 76..86

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

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

                          {
                            firstname: 'userthree',
                            lastname: 'userthree',
                            email: 'userthree@gmail.com',
                            password: hashPassword,
                      Severity: Major
                      Found in src/seeders/20190808074800-normal-user.js and 5 other locations - About 55 mins to fix
                      src/seeders/20190808074800-normal-user.js on lines 21..31
                      src/seeders/20190808074800-normal-user.js on lines 43..53
                      src/seeders/20190808074800-normal-user.js on lines 54..64
                      src/seeders/20190808074800-normal-user.js on lines 65..75
                      src/seeders/20190808074800-normal-user.js on lines 76..86

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

                      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 (req.auth.id !== findArticle.authorId) {
                            return res.status(403).json({
                              status: 403,
                              message: 'Sorry you can not DELETE an article that does not belong to you.'
                            });
                      Severity: Minor
                      Found in src/controllers/articles.controller.js and 1 other location - About 55 mins to fix
                      src/controllers/articles.controller.js on lines 258..263

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

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

                          {
                            firstname: 'usertwo',
                            lastname: 'usertwo',
                            email: 'usertwo@gmail.com',
                            password: hashPassword,
                      Severity: Major
                      Found in src/seeders/20190808074800-normal-user.js and 5 other locations - About 55 mins to fix
                      src/seeders/20190808074800-normal-user.js on lines 32..42
                      src/seeders/20190808074800-normal-user.js on lines 43..53
                      src/seeders/20190808074800-normal-user.js on lines 54..64
                      src/seeders/20190808074800-normal-user.js on lines 65..75
                      src/seeders/20190808074800-normal-user.js on lines 76..86

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

                      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