andela/codepirates-ah-backend

View on GitHub

Showing 67 of 142 total issues

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

    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

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

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

    Avoid too many return statements within this function.
    Open

          return util.send(res);
    Severity: Major
    Found in src/controllers/highlight.controller.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

            return util.send(res);
      Severity: Major
      Found in src/middlewares/validators/signup.validation.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

              return res.status(404).send({
                status: 404,
                message: errors[0].message
              });
        Severity: Major
        Found in src/controllers/user.controller.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                return util.send(res);
          Severity: Major
          Found in src/middlewares/validators/signup.validation.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                  return util.send(res);
            Severity: Major
            Found in src/middlewares/validators/signup.validation.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                    return util.send(res);
              Severity: Major
              Found in src/middlewares/validators/signup.validation.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                      return res.send({
                        message: error.message
                      });
                Severity: Major
                Found in src/controllers/comments.controller.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                        return res.status(404).send({
                          status: 404,
                          message: error
                        });
                  Severity: Major
                  Found in src/controllers/user.controller.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                          return util.send(res);
                    Severity: Major
                    Found in src/middlewares/validators/signup.validation.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            return util.send(res);
                      Severity: Major
                      Found in src/middlewares/validators/signup.validation.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              return res.status(404).send({
                                status: 404,
                                message: error.message
                              });
                        Severity: Major
                        Found in src/controllers/user.controller.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                return util.send(res);
                          Severity: Major
                          Found in src/middlewares/validators/signup.validation.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                  return res.status(200).send({
                                    status: 200,
                                    message: 'Password reset successfully'
                                  });
                            Severity: Major
                            Found in src/controllers/user.controller.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                    return util.send(res);
                              Severity: Major
                              Found in src/middlewares/validators/signup.validation.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                      return res.status(500).send({
                                        status: 500,
                                        message: error.message
                                      });
                                Severity: Major
                                Found in src/controllers/user.controller.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                        return res.status(400).send({
                                          status: 400,
                                          message: 'Failed to fetch user'
                                        });
                                  Severity: Major
                                  Found in src/controllers/user.controller.js - About 30 mins to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language