BerniWittmann/spielplanismaning

View on GitHub
src/routes/helpers.js

Summary

Maintainability
F
6 days
Test Coverage

File helpers.js has 1079 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const logger = require('winston').loggers.get('apiHelper');
const async = require('async');
const messages = require('./messages/messages.js')();
const _ = require('lodash');
const handler = require('./handler.js');
Severity: Major
Found in src/routes/helpers.js - About 2 days to fix

    Function fillSpiele has 76 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function fillSpiele(callback) {
        logger.verbose('Filling Spiele with Team Infos');
        const beachEventID = cls.getBeachEventID();
        const clsSession = cls.getNamespace();
        return clsSession.run(function () {
    Severity: Major
    Found in src/routes/helpers.js - About 3 hrs to fix

      Function fillSpielFromGruppe has 60 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function fillSpielFromGruppe(spiel, cb) {
          logger.verbose('Filling Spiel Nummer %d from Gruppe', spiel.nummer);
          const calculatedTeams = {
              A: undefined,
              B: undefined
      Severity: Major
      Found in src/routes/helpers.js - About 2 hrs to fix

        Function fillSpielFromSpiel has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function fillSpielFromSpiel(spiel, cb) {
            logger.verbose('Filling Spiel Nummer %d from Spiel', spiel.nummer);
            const calculatedTeams = {
                A: undefined,
                B: undefined
        Severity: Major
        Found in src/routes/helpers.js - About 2 hrs to fix

          Function fillTeamFromGruppe has 56 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function fillTeamFromGruppe(team, cb) {
              logger.verbose('Filling Team %s from Gruppe', team._id);
              const beachEventID = cls.getBeachEventID();
              const clsSession = cls.getNamespace();
              return clsSession.run(function () {
          Severity: Major
          Found in src/routes/helpers.js - About 2 hrs to fix

            Function calcSpielDateTimePresets has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function calcSpielDateTimePresets(spielplan, nr, plaetze, delays) {
                const startDatum = moment(spielplan.startdatum, 'DD.MM.YYYY');
                const dailyStartTime = moment(spielplan.startzeit, 'HH:mm');
                const dailyEndTime = moment(spielplan.endzeit, 'HH:mm');
                let spielzeit, pausenzeit;
            Severity: Minor
            Found in src/routes/helpers.js - About 1 hr to fix

              Function reloadAnmeldeObjects has 43 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              function reloadAnmeldeObjects(cb) {
                  const beachEventID = cls.getBeachEventID();
                  const clsSession = cls.getNamespace();
                  return clsSession.run(function () {
                      clsSession.set('beachEventID', beachEventID);
              Severity: Minor
              Found in src/routes/helpers.js - About 1 hr to fix

                Function createGruppeWithTeams has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function createGruppeWithTeams(jugendid, data, cb) {
                    const beachEventID = cls.getBeachEventID();
                    const clsSession = cls.getNamespace();
                    return clsSession.run(function () {
                        clsSession.set('beachEventID', beachEventID);
                Severity: Minor
                Found in src/routes/helpers.js - About 1 hr to fix

                  Function checkSpielOrderChangeAllowed has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function checkSpielOrderChangeAllowed(spiele) {
                      logger.verbose('Check Spiel Order Allowed');
                      const plaetze = parseInt(process.env.PLAETZE, 10);
                      logger.verbose('Calculated %d Plätze', plaetze);
                      let teamsParallel = [];
                  Severity: Minor
                  Found in src/routes/helpers.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 teamCalcErgebnisse has 39 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function teamCalcErgebnisse(team, gruppe, cb) {
                      const query = {
                          beendet: true
                      };
                      if (gruppe) {
                  Severity: Minor
                  Found in src/routes/helpers.js - About 1 hr to fix

                    Function calcSpielDateTime has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function calcSpielDateTime(nr, spielplan, delays) {
                        delays = delays || {};
                        logger.silly('Calculate Date and Time for a Spiel');
                        if (!checkSpielplanZeitenValid(spielplan)) {
                            return undefined;
                    Severity: Minor
                    Found in src/routes/helpers.js - About 1 hr to fix

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

                      function getEntity(model, population, notFoundMessage, res, req) {
                          const queryData = getEntityQuery(model, req);
                          const query = queryData.query;
                          const searchById = queryData.searchById;
                          const beachEventID = cls.getBeachEventID();
                      Severity: Minor
                      Found in src/routes/helpers.js - About 1 hr to fix

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

                        function fill(entity, cb) {
                            const beachEventID = cls.getBeachEventID();
                            const clsSession = cls.getNamespace();
                            return clsSession.run(function () {
                                clsSession.set('beachEventID', beachEventID);
                        Severity: Minor
                        Found in src/routes/helpers.js - About 1 hr to fix

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

                          function checkSpielChangeable(spielid, cb) {
                              const beachEventID = cls.getBeachEventID();
                              const clsSession = cls.getNamespace();
                              return clsSession.run(function () {
                                  clsSession.set('beachEventID', beachEventID);
                          Severity: Minor
                          Found in src/routes/helpers.js - About 1 hr to fix

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

                            function getRequiredRouteConfig(routes, path, method, configKey) {
                                logger.silly('Getting Route Config');
                                path = removeLastSlashFromPath(path);
                                let route = routes[path];
                            
                            
                            Severity: Minor
                            Found in src/routes/helpers.js - About 1 hr to fix

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

                              function getRequiredRouteConfig(routes, path, method, configKey) {
                                  logger.silly('Getting Route Config');
                                  path = removeLastSlashFromPath(path);
                                  let route = routes[path];
                              
                              
                              Severity: Minor
                              Found in src/routes/helpers.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 (foundSpiel.teamA && foundSpiel.teamA._id &&
                                                                  foundSpiel.teamB && foundSpiel.teamB._id &&
                                                                  foundSpiel.gewinner && foundSpiel.gewinner._id) {
                                                                  if (foundSpiel.teamA._id.toString() === foundSpiel.gewinner._id.toString()) {
                                                                      calculatedTeams[letter] = foundSpiel.teamB;
                              Severity: Major
                              Found in src/routes/helpers.js - About 40 mins to fix

                                Function gruppeFindPlace has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                function gruppeFindPlace(teams, spieleDerGruppe, platz, gruppe, callback) {
                                Severity: Minor
                                Found in src/routes/helpers.js - About 35 mins to fix

                                  Function findEntityAndPushTeam has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                  function findEntityAndPushTeam(model, id, team, res, callback) {
                                  Severity: Minor
                                  Found in src/routes/helpers.js - About 35 mins to fix

                                    Function getEntity has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                    Open

                                    function getEntity(model, population, notFoundMessage, res, req) {
                                    Severity: Minor
                                    Found in src/routes/helpers.js - About 35 mins to fix

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

                                      function getEntityQuery(model, req) {
                                          logger.silly('Getting Entity Query');
                                          if (req.query.id) {
                                              return queryId(model, req.query.id);
                                          } else if (req.query.team) {
                                      Severity: Minor
                                      Found in src/routes/helpers.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 routeconfig;
                                      Severity: Major
                                      Found in src/routes/helpers.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                return routeconfig.split(' ');
                                        Severity: Major
                                        Found in src/routes/helpers.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                  return queryIdentifier(model, req.query.identifier);
                                          Severity: Major
                                          Found in src/routes/helpers.js - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                return {
                                                    dailyStartTime: dailyStartTime,
                                                    dailyEndTime: dailyEndTime,
                                                    spielePerDay: spielePerDay,
                                                    offsetDays: offsetDays,
                                            Severity: Major
                                            Found in src/routes/helpers.js - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                  return undefined;
                                              Severity: Major
                                              Found in src/routes/helpers.js - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                        return queryDate(model, req.query.date);
                                                Severity: Major
                                                Found in src/routes/helpers.js - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                          return querySlug(model, req.query.slug);
                                                  Severity: Major
                                                  Found in src/routes/helpers.js - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                        return {
                                                            searchById: false,
                                                            query: model.find({})
                                                        }
                                                    Severity: Major
                                                    Found in src/routes/helpers.js - About 30 mins to fix

                                                      There are no issues that match your filters.

                                                      Category
                                                      Status