andela/team-odd-bn-backend

View on GitHub

Showing 54 of 137 total issues

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

const validateSearchQueries = (req, res, next) => {
  const { query } = req;
  const allKeys = Object.keys(query);
  if (allKeys.length === 0) {
    return Response.errorMessage(req, res, 'Please provide a search query key parameter', 400);
Severity: Minor
Found in src/middlewares/validateSearchQueries.js - About 1 hr to fix

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

      static async getUserRequests(req) {
        const requestsUsersObject = {
          where: { userId: req.user.id },
          order: [
            ['updatedAt', 'DESC'],
    Severity: Minor
    Found in src/services/TripService.js - About 1 hr to fix

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

        up: (queryInterface, Sequelize) => {
          return queryInterface.bulkInsert('rooms',[
            {
              accommodationId: 1,
              name: 'maisai mara',
      Severity: Minor
      Found in src/database/seeders/20191204092003-rooms.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('ratings', {
              id: {
                allowNull: false,
                autoIncrement: true,
        Severity: Minor
        Found in src/database/migrations/20191203155338-create-ratings.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('accommodationImages', {
                id: {
                  allowNull: false,
                  autoIncrement: true,

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

              static async newBookingNotification(req) {
                const userQueryObject = {
                  where: { id: req.user.id }
                };
                const travelAdminQueryObject = {
            Severity: Minor
            Found in src/services/NotificationService.js - About 1 hr to fix

              Function associate has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                tripRequests.associate = function(models) {
                  tripRequests.belongsTo(
                    models.users,
                     {foreignKey: 'userId'},
                     { onDelete: 'cascade'},
              Severity: Minor
              Found in src/database/models/tripRequests.js - About 1 hr to fix

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

                  up: (queryInterface, Sequelize) => {
                    return queryInterface.sequelize.transaction((t) => {
                      return Promise.all([
                        queryInterface.addColumn('notifications', 'commentsId', {
                          type: Sequelize.INTEGER,

                  Consider simplifying this complex logical expression.
                  Open

                      if (key === 'originId'
                      || key === 'destinationId'
                      || key === 'startDate'
                      || key === 'returnDate'
                      || key === 'firstName'
                  Severity: Major
                  Found in src/middlewares/validateSearchQueries.js - About 1 hr to fix

                    Function findMostTraveledDestination has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                      static async findMostTraveledDestination() {
                        const destinationObj = {
                          attributes: ['destinationId'], raw: true
                        };
                        const getAllDestinations = await CommonQueries.findAll(trips, destinationObj);
                    Severity: Minor
                    Found in src/helpers/TripHelper.js - About 45 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

                    Consider simplifying this complex logical expression.
                    Open

                      if (query.originId === ''
                      || query.destinationId === ''
                      || query.startDate === ''
                      || query.returnDate === ''
                      || query.firstName === ''
                    Severity: Major
                    Found in src/middlewares/validateSearchQueries.js - About 40 mins to fix

                      Function isLoggedViaSocialLogin has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                      const isLoggedViaSocialLogin = async (req, res, next) => {
                        const { email } = req.body;
                        if (email) {
                          const findSignupType = await users.findOne({ where: { email } });
                          if (findSignupType) {
                      Severity: Minor
                      Found in src/middlewares/isLoggedViaSocialLogin.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 validateSearchQueries has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                      const validateSearchQueries = (req, res, next) => {
                        const { query } = req;
                        const allKeys = Object.keys(query);
                        if (allKeys.length === 0) {
                          return Response.errorMessage(req, res, 'Please provide a search query key parameter', 400);
                      Severity: Minor
                      Found in src/middlewares/validateSearchQueries.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 operateAcceptOrReject has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                      const operateAcceptOrReject = async (req, res, next) => {
                        const { id } = req.user;
                        const { tripRequestId } = req.params;
                        const users = await userProfiles.findAll({
                          where: { managerId: id }
                      Severity: Minor
                      Found in src/middlewares/approveOrReject.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

                      Severity
                      Category
                      Status
                      Source
                      Language