andela/team-odd-bn-backend

View on GitHub
src/services/TripService.js

Summary

Maintainability
D
2 days
Test Coverage

Function getUserTrips has 73 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  static async getUserTrips(req) {
    const { Op } = Sequelize;
    const { from, to, user } = req.query;
    const { id, roleId } = req.user;
    let userTripsObject, requests;
Severity: Major
Found in src/services/TripService.js - About 2 hrs to fix

    File TripService.js has 256 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import Sequelize, { Promise } from 'sequelize';
    import {
      tripRequests, trips, userProfile, users, accommodations, cities, tripTypes, status
    } from '../database/models';
    import TripHelper from '../helpers/TripHelper';
    Severity: Minor
    Found in src/services/TripService.js - About 2 hrs to fix

      Function availtripRequestsToManager has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        static async availtripRequestsToManager(id) {
          const userObj = {
            where: { managerId: id },
            attributes: ['userId'],
            raw: true
      Severity: Minor
      Found in src/services/TripService.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

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

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

                    const tripsWithCityName = requests.map((tripss) => tripss.trips.map(async (trip) => {
                      const { originId, destinationId } = trip;
                      const { origin, destination } = await TripHelper.getCityName({ originId, destinationId });
                      trip.originId = origin.city;
                      trip.destinationId = destination.city;
                Severity: Major
                Found in src/services/TripService.js and 1 other location - About 3 hrs to fix
                src/services/TripService.js on lines 187..193

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

                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 tripsWithCityName = await requests.map(async (trip) => {
                        const { originId, destinationId } = trip;
                        const { origin, destination } = await TripHelper.getCityName({ originId, destinationId });
                        trip.originId = origin.city;
                        trip.destinationId = destination.city;
                Severity: Major
                Found in src/services/TripService.js and 1 other location - About 3 hrs to fix
                src/services/TripService.js on lines 140..146

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

                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

                      trip.dataValues
                        .user.dataValues
                        .tripRequests[0].dataValues
                        .trips[0].dataValues
                        .originId = origin.city;
                Severity: Minor
                Found in src/services/TripService.js and 1 other location - About 50 mins to fix
                src/services/TripService.js on lines 231..235

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

                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

                      trip.dataValues
                        .user.dataValues
                        .tripRequests[0].dataValues
                        .trips[0].dataValues
                        .destinationId = destination.city;
                Severity: Minor
                Found in src/services/TripService.js and 1 other location - About 50 mins to fix
                src/services/TripService.js on lines 226..230

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

                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

                        {
                          originId: item.originId,
                          destinationId: item.destinationId,
                          reason: item.reason,
                          startDate: item.startDate,
                Severity: Minor
                Found in src/services/TripService.js and 1 other location - About 35 mins to fix
                src/database/models/notifications.js on lines 3..9

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

                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

                There are no issues that match your filters.

                Category
                Status