andela/team-odd-bn-backend

View on GitHub

Showing 137 of 137 total issues

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

  static async isTravelAdministrator(req, res, next) {
    const dbRoleId = await UserHelper.userRoleType(req, roles);
    if (dbRoleId !== 4) {
      return Response.errorMessage(req, res, 'you are not a travel administrator', 403);
    }
Severity: Major
Found in src/middlewares/VerifyUserRoles.js and 3 other locations - About 1 hr to fix
src/middlewares/VerifyUserRoles.js on lines 41..47
src/middlewares/VerifyUserRoles.js on lines 75..81
src/middlewares/VerifyUserRoles.js on lines 92..98

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

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

  static async socialCallBack(accessToken, refreshToken, profile, signupTypeParameter, done) {
    try {
      const data = {
        id: profile.id,
        firstName: profile.name.givenName,
Severity: Minor
Found in src/helpers/UserHelper.js - About 1 hr to fix

    Function editTripRequestToUser has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static async editTripRequestToUser(req) {
        const itinerary = req.body.itinerary ? req.body.itinerary : [req.body];
    
        const findAllObjQuery = {
          attributes: ['id'],
    Severity: Minor
    Found in src/services/TripService.js - About 1 hr to fix

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

          try {
            const result = await LocationService.getLocations();
            if (result.length === 0) {
              return Response.errorMessage(req, res, 'No city is available at the moment', 404);
            }
      Severity: Major
      Found in src/controllers/LocationController.js and 1 other location - About 1 hr to fix
      src/controllers/UserController.js on lines 172..178

      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

        static async availableUsers(req, res) {
          const allUsers = await UserService.availableUsers();
          if (allUsers.length === 0) {
            return Response.errorMessage(req, res, 'no users are available', 404);
          }
      Severity: Major
      Found in src/controllers/UserController.js and 1 other location - About 1 hr to fix
      src/controllers/LocationController.js on lines 41..47

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

        static async addCommentNotification(req) {
          const { user, params } = req;
          const tripRequestInfoObject = {
            where: {
              id: params.tripRequestId
      Severity: Minor
      Found in src/services/NotificationService.js - About 1 hr to fix

        Function getSingleTrip has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          static async getSingleTrip(tripRequestId) {
            const singleTripObject = {
              where: { id: tripRequestId },
              include: [
                {
        Severity: Minor
        Found in src/services/TripService.js - About 1 hr to fix

          Function managerRequests has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              let managerRequests = managerUsers.map(async user => {
                const managerRequestsObj = {
                  where: { userId: user.userId, statusId: 1 },
                  attributes: ['id', 'updatedAt', 'createdAt'],
                  order: [
          Severity: Minor
          Found in src/services/TripService.js - About 1 hr to fix

            Function bookAccommodationService has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              static async bookAccommodationService(req, res) {
                try {
                  const accommodationObj = {
                    raw: true
                  };
            Severity: Minor
            Found in src/services/BookingService.js - About 1 hr to fix

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

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

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

                  up: (queryInterface, Sequelize) => {
                    return queryInterface.bulkInsert('users', [{
                        firstName: 'John',
                        lastName: 'Doe',
                        email: 'admin@gmail.com',
                Severity: Minor
                Found in src/database/seeders/20191115043919-super-admin.js - About 1 hr to fix

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

                    static async getSpecificComments(req) {
                      const { commentId } = req.params;
                      const queryObj = {
                        where: {
                          commentId,
                  Severity: Major
                  Found in src/services/CommentService.js and 1 other location - About 1 hr to fix
                  src/services/CommentService.js on lines 99..108

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

                    static async deleteComment(req) {
                      const { commentId } = req.params;
                      const queryObject = {
                        where: {
                          id: commentId,
                  Severity: Major
                  Found in src/services/CommentService.js and 1 other location - About 1 hr to fix
                  src/services/CommentService.js on lines 76..87

                  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

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

                      const allCitiess = await trips.findAll({
                        include: [{
                          model: tripRequests,
                          where: { userId: req.user.id, statusId: 1 }
                        }],
                  Severity: Major
                  Found in src/middlewares/ValidateTrip.js and 1 other location - About 1 hr to fix
                  src/middlewares/ValidateTrip.js on lines 176..182

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

                  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 createNewAccomodation(req, res) {
                      try {
                        const newAccommodation = await createAccomodation(req);
                        return Response.successMessage(req, res, 'Accommodation successfully posted', newAccommodation, 201);
                      } catch (err) {
                  Severity: Major
                  Found in src/controllers/AccommodationController.js and 1 other location - About 1 hr to fix
                  src/controllers/AccommodationController.js on lines 83..90

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

                  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

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

                      const allCitiess = await trips.findAll({
                        include: [{
                          model: tripRequests,
                          where: { userId: req.user.id, statusId: 1 }
                        }],
                  Severity: Major
                  Found in src/middlewares/ValidateTrip.js and 1 other location - About 1 hr to fix
                  src/middlewares/ValidateTrip.js on lines 128..134

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

                  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 getAccommodations(req, res) {
                      try {
                        const accommodations = await getAccommodations(req);
                        return Response.successMessage(req, res, 'Accommodation(s) successfully fetched', accommodations, 200);
                      } catch (err) {
                  Severity: Major
                  Found in src/controllers/AccommodationController.js and 1 other location - About 1 hr to fix
                  src/controllers/AccommodationController.js on lines 66..73

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

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

                    static async checkForSimilarRequests(req, res, next) {
                      const itinerary = req.body.itinerary ? req.body.itinerary : [req.body];
                  
                      const allCitiess = await trips.findAll({
                        include: [{
                  Severity: Minor
                  Found in src/middlewares/ValidateTrip.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('rooms', {
                          id: {
                            allowNull: false,
                            autoIncrement: true,
                    Severity: Minor
                    Found in src/database/migrations/20191203145124-create-rooms.js - About 1 hr to fix

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