Emapic/emapic

View on GitHub
routes/api-engine_routes.js

Summary

Maintainability
F
2 wks
Test Coverage

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

module.exports = function(app) {

    function handleInternalError(req, res) {
        return function(err) {
            logger.error('Internal server error during API request: ' + err.message);
Severity: Major
Found in routes/api-engine_routes.js - About 2 days to fix

    File api-engine_routes.js has 585 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    var fs = require('fs'),
        Promise = require('bluebird'),
        bases = require('bases'),
        RateLimit = require('express-rate-limit'),
        logger = require('../utils/logger'),
    Severity: Major
    Found in routes/api-engine_routes.js - About 1 day to fix

      Consider simplifying this complex logical expression.
      Open

                  if ((survey.active === false) ||
                  // Data required by the owner
                  (req.user && survey.owner.id === req.user.id) ||
                  // Survey is active and results are always public or shown after vote
                  (survey.active === true && (survey.public_results || survey.results_after_vote)) ||
      Severity: Critical
      Found in routes/api-engine_routes.js - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

                    if ((survey.active === false) ||
                    // Data required by the owner
                    (req.user && survey.owner.id === req.user.id) ||
                    // Survey is active and results are always public or shown after vote
                    (survey.active === true && (survey.public_results || survey.results_after_vote)) ||
        Severity: Critical
        Found in routes/api-engine_routes.js - About 1 hr to fix

          Consider simplifying this complex logical expression.
          Open

                      if ((survey.active === false) ||
                      // Data required by the owner
                      (req.user && survey.owner.id === req.user.id) ||
                      // Survey is active and results are always public or shown after vote
                      (survey.active === true && (survey.public_results || survey.results_after_vote)) ||
          Severity: Critical
          Found in routes/api-engine_routes.js - About 1 hr to fix

            Consider simplifying this complex logical expression.
            Open

                        if ((survey.active === false) ||
                        // Data required by the owner
                        (req.user && survey.owner.id === req.user.id) ||
                        // Survey is active and results are always public or shown after vote
                        (survey.active === true && (survey.public_results || survey.results_after_vote)) ||
            Severity: Critical
            Found in routes/api-engine_routes.js - About 1 hr to fix

              Consider simplifying this complex logical expression.
              Open

                          if ((survey.active === false) ||
                          // Data required by the owner
                          (req.user && survey.owner.id === req.user.id) ||
                          // Survey is active and results are always public or shown after vote
                          (survey.active === true && (survey.public_results || survey.results_after_vote)) ||
              Severity: Critical
              Found in routes/api-engine_routes.js - About 1 hr to fix

                Consider simplifying this complex logical expression.
                Open

                            if ((survey.active === false) ||
                            // Data required by the owner
                            (req.user && survey.owner.id === req.user.id) ||
                            // Survey is active and results are always public or shown after vote
                            (survey.active === true && (survey.public_results || survey.results_after_vote)) ||
                Severity: Critical
                Found in routes/api-engine_routes.js - About 1 hr to fix

                  Consider simplifying this complex logical expression.
                  Open

                              if ((survey.active === false) ||
                              // Data required by the owner
                              (req.user && survey.owner.id === req.user.id) ||
                              // Survey is active and results are always public or shown after vote
                              (survey.active === true && (survey.public_results || survey.results_after_vote)) ||
                  Severity: Critical
                  Found in routes/api-engine_routes.js - About 1 hr to fix

                    Consider simplifying this complex logical expression.
                    Open

                                if ((survey.active === false) ||
                                // Data required by the owner
                                (req.user && survey.owner.id === req.user.id) ||
                                // Survey is active and results are always public or shown after vote
                                (survey.active === true && (survey.public_results || survey.results_after_vote)) ||
                    Severity: Critical
                    Found in routes/api-engine_routes.js - About 1 hr to fix

                      Consider simplifying this complex logical expression.
                      Open

                                  if ((survey.active === false) ||
                                  // Data required by the owner
                                  (req.user && survey.owner.id === req.user.id) ||
                                  // Survey is active and results are always public
                                  (survey.active === true && survey.public_results) ||
                      Severity: Critical
                      Found in routes/api-engine_routes.js - About 1 hr to fix

                        Missing radix parameter.
                        Open

                                    if (params.limit && !isNaN(parseInt(params.limit))) {
                        Severity: Minor
                        Found in routes/api-engine_routes.js by eslint

                        Require Radix Parameter (radix)

                        When using the parseInt() function it is common to omit the second argument, the radix, and let the function try to determine from the first argument what type of number it is. By default, parseInt() will autodetect decimal and hexadecimal (via 0x prefix). Prior to ECMAScript 5, parseInt() also autodetected octal literals, which caused problems because many developers assumed a leading 0 would be ignored.

                        This confusion led to the suggestion that you always use the radix parameter to parseInt() to eliminate unintended consequences. So instead of doing this:

                        var num = parseInt("071");      // 57

                        Do this:

                        var num = parseInt("071", 10);  // 71

                        ECMAScript 5 changed the behavior of parseInt() so that it no longer autodetects octal literals and instead treats them as decimal literals. However, the differences between hexadecimal and decimal interpretation of the first parameter causes many developers to continue using the radix parameter to ensure the string is interpreted in the intended way.

                        On the other hand, if the code is targeting only ES5-compliant environments passing the radix 10 may be redundant. In such a case you might want to disallow using such a radix.

                        Rule Details

                        This rule is aimed at preventing the unintended conversion of a string to a number of a different base than intended or at preventing the redundant 10 radix if targeting modern environments only.

                        Options

                        There are two options for this rule:

                        • "always" enforces providing a radix (default)
                        • "as-needed" disallows providing the 10 radix

                        always

                        Examples of incorrect code for the default "always" option:

                        /*eslint radix: "error"*/
                        
                        var num = parseInt("071");
                        
                        var num = parseInt(someValue);
                        
                        var num = parseInt("071", "abc");
                        
                        var num = parseInt();

                        Examples of correct code for the default "always" option:

                        /*eslint radix: "error"*/
                        
                        var num = parseInt("071", 10);
                        
                        var num = parseInt("071", 8);
                        
                        var num = parseFloat(someValue);

                        as-needed

                        Examples of incorrect code for the "as-needed" option:

                        /*eslint radix: ["error", "as-needed"]*/
                        
                        var num = parseInt("071", 10);
                        
                        var num = parseInt("071", "abc");
                        
                        var num = parseInt();

                        Examples of correct code for the "as-needed" option:

                        /*eslint radix: ["error", "as-needed"]*/
                        
                        var num = parseInt("071");
                        
                        var num = parseInt("071", 8);
                        
                        var num = parseFloat(someValue);

                        When Not To Use It

                        If you don't want to enforce either presence or omission of the 10 radix value you can turn this rule off.

                        Further Reading

                        Expected error to be handled.
                        Open

                                }).catch({ message: 'NULL_USER' }, function(err) {
                        Severity: Minor
                        Found in routes/api-engine_routes.js by eslint

                        Enforce Callback Error Handling (handle-callback-err)

                        In Node.js, a common pattern for dealing with asynchronous behavior is called the callback pattern. This pattern expects an Error object or null as the first argument of the callback. Forgetting to handle these errors can lead to some really strange behavior in your application.

                        function loadData (err, data) {
                            doSomething(); // forgot to handle error
                        }

                        Rule Details

                        This rule expects that when you're using the callback pattern in Node.js you'll handle the error.

                        Options

                        The rule takes a single string option: the name of the error parameter. The default is "err".

                        Examples of incorrect code for this rule with the default "err" parameter name:

                        /*eslint handle-callback-err: "error"*/
                        
                        function loadData (err, data) {
                            doSomething();
                        }

                        Examples of correct code for this rule with the default "err" parameter name:

                        /*eslint handle-callback-err: "error"*/
                        
                        function loadData (err, data) {
                            if (err) {
                                console.log(err.stack);
                            }
                            doSomething();
                        }
                        
                        function generateError (err) {
                            if (err) {}
                        }

                        Examples of correct code for this rule with a sample "error" parameter name:

                        /*eslint handle-callback-err: ["error", "error"]*/
                        
                        function loadData (error, data) {
                            if (error) {
                               console.log(error.stack);
                            }
                            doSomething();
                        }

                        regular expression

                        Sometimes (especially in big projects) the name of the error variable is not consistent across the project, so you need a more flexible configuration to ensure that the rule reports all unhandled errors.

                        If the configured name of the error variable begins with a ^ it is considered to be a regexp pattern.

                        • If the option is "^(err|error|anySpecificError)$", the rule reports unhandled errors where the parameter name can be err, error or anySpecificError.
                        • If the option is "^.+Error$", the rule reports unhandled errors where the parameter name ends with Error (for example, connectionError or validationError will match).
                        • If the option is "^.*(e|E)rr", the rule reports unhandled errors where the parameter name matches any string that contains err or Err (for example, err, error, anyError, some_err will match).

                        When Not To Use It

                        There are cases where it may be safe for your application to ignore errors, however only ignore errors if you are confident that some other form of monitoring will help you catch the problem.

                        Further Reading

                        Missing radix parameter.
                        Open

                                    if (params.offset && !isNaN(parseInt(params.offset))) {
                        Severity: Minor
                        Found in routes/api-engine_routes.js by eslint

                        Require Radix Parameter (radix)

                        When using the parseInt() function it is common to omit the second argument, the radix, and let the function try to determine from the first argument what type of number it is. By default, parseInt() will autodetect decimal and hexadecimal (via 0x prefix). Prior to ECMAScript 5, parseInt() also autodetected octal literals, which caused problems because many developers assumed a leading 0 would be ignored.

                        This confusion led to the suggestion that you always use the radix parameter to parseInt() to eliminate unintended consequences. So instead of doing this:

                        var num = parseInt("071");      // 57

                        Do this:

                        var num = parseInt("071", 10);  // 71

                        ECMAScript 5 changed the behavior of parseInt() so that it no longer autodetects octal literals and instead treats them as decimal literals. However, the differences between hexadecimal and decimal interpretation of the first parameter causes many developers to continue using the radix parameter to ensure the string is interpreted in the intended way.

                        On the other hand, if the code is targeting only ES5-compliant environments passing the radix 10 may be redundant. In such a case you might want to disallow using such a radix.

                        Rule Details

                        This rule is aimed at preventing the unintended conversion of a string to a number of a different base than intended or at preventing the redundant 10 radix if targeting modern environments only.

                        Options

                        There are two options for this rule:

                        • "always" enforces providing a radix (default)
                        • "as-needed" disallows providing the 10 radix

                        always

                        Examples of incorrect code for the default "always" option:

                        /*eslint radix: "error"*/
                        
                        var num = parseInt("071");
                        
                        var num = parseInt(someValue);
                        
                        var num = parseInt("071", "abc");
                        
                        var num = parseInt();

                        Examples of correct code for the default "always" option:

                        /*eslint radix: "error"*/
                        
                        var num = parseInt("071", 10);
                        
                        var num = parseInt("071", 8);
                        
                        var num = parseFloat(someValue);

                        as-needed

                        Examples of incorrect code for the "as-needed" option:

                        /*eslint radix: ["error", "as-needed"]*/
                        
                        var num = parseInt("071", 10);
                        
                        var num = parseInt("071", "abc");
                        
                        var num = parseInt();

                        Examples of correct code for the "as-needed" option:

                        /*eslint radix: ["error", "as-needed"]*/
                        
                        var num = parseInt("071");
                        
                        var num = parseInt("071", 8);
                        
                        var num = parseFloat(someValue);

                        When Not To Use It

                        If you don't want to enforce either presence or omission of the 10 radix value you can turn this rule off.

                        Further Reading

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

                            app.get('/api/survey/:surveyId/legend', function(req, res) {
                                models.Survey.scope('includeAuthor').findByPk(Utils.decryptSurveyId(req.params.surveyId)).then(function(survey) {
                                    if (survey === null) {
                                        return res.status(404).json({ error_code: 'invalid_resource', error: 'requested survey doesn\'t exist.' });
                                    }
                        Severity: Major
                        Found in routes/api-engine_routes.js and 2 other locations - About 1 day to fix
                        routes/api-engine_routes.js on lines 167..187
                        routes/api-engine_routes.js on lines 246..266

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

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

                            app.get('/api/survey/:surveyId/description', function(req, res) {
                                models.Survey.scope('includeAuthor').findByPk(Utils.decryptSurveyId(req.params.surveyId)).then(function(survey) {
                                    if (survey === null) {
                                        return res.status(404).json({ error_code: 'invalid_resource', error: 'requested survey doesn\'t exist.' });
                                    }
                        Severity: Major
                        Found in routes/api-engine_routes.js and 2 other locations - About 1 day to fix
                        routes/api-engine_routes.js on lines 246..266
                        routes/api-engine_routes.js on lines 325..345

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

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

                            app.get('/api/survey/:surveyId/totals', function(req, res) {
                                models.Survey.scope('includeAuthor').findByPk(Utils.decryptSurveyId(req.params.surveyId)).then(function(survey) {
                                    if (survey === null) {
                                        return res.status(404).json({ error_code: 'invalid_resource', error: 'requested survey doesn\'t exist.' });
                                    }
                        Severity: Major
                        Found in routes/api-engine_routes.js and 2 other locations - About 1 day to fix
                        routes/api-engine_routes.js on lines 167..187
                        routes/api-engine_routes.js on lines 325..345

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

                        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

                                    return sequelize.query('SELECT a.gid id, a.codigo AS adm_code, a.' + municipalityName + ' AS name, a.cod_prov, a.provincia, a.cod_ccaa, ' +
                                        'a.comautonom, b.adm1_code as province_adm_code, lower(b.iso_a2) AS country_iso_code, a.province_gid province_id ' +
                                        'FROM base_layers.municipalities a JOIN base_layers.provinces b ON a.province_gid = b.gid ' +
                                        'WHERE st_intersects(a.geom, st_setsrid(st_makepoint(:lon, :lat), 4326)) LIMIT 1', {
                                        replacements: {
                        Severity: Major
                        Found in routes/api-engine_routes.js and 1 other location - About 6 hrs to fix
                        routes/api-engine_routes.js on lines 605..648

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

                        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

                                models.Survey.findSurveys(req.user.id, false, status, query, tag, order, pageSize, pageNr).then(function(surveys) {
                                    var results = [];
                                    for (var i = 0, len = surveys.rows.length; i<len; i++) {
                                        results.push(surveys.rows[i].getDescription());
                                    }
                        Severity: Major
                        Found in routes/api-engine_routes.js and 1 other location - About 3 hrs to fix
                        routes/api-engine_routes.js on lines 134..143

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

                        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

                                surveysPromise.then(function(surveys) {
                                    var results = [];
                                    for (var i = 0, len = surveys.rows.length; i<len; i++) {
                                        results.push(surveys.rows[i].getDescription());
                                    }
                        Severity: Major
                        Found in routes/api-engine_routes.js and 1 other location - About 3 hrs to fix
                        routes/api-engine_routes.js on lines 155..164

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

                        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

                                        return survey.getCustomSingleMarkerImageData().then(function(data) {
                                            if (data === null || data.path === null || data.mime_type === null) {
                                                return res.send(404);   // HTTP status 404: NotFound
                                            }
                                            res.contentType(data.mime_type);
                        Severity: Major
                        Found in routes/api-engine_routes.js and 1 other location - About 2 hrs to fix
                        routes/api-engine_routes.js on lines 233..239

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

                        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

                                        return survey.getAnswerImageData(qstnId, answrId).then(function(data) {
                                            if (data === null || data.path === null || data.mime_type === null) {
                                                return res.send(404);   // HTTP status 404: NotFound
                                            }
                                            res.contentType(data.mime_type);
                        Severity: Major
                        Found in routes/api-engine_routes.js and 1 other location - About 2 hrs to fix
                        routes/api-engine_routes.js on lines 202..208

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

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

                                            sql = 'SELECT a.gid id, a.diss_me AS province_world_id, a.iso_3166_2 AS iso_code, a.adm1_code AS adm_code, a.' + nameCol + ' AS name, a.type_en AS type, lower(a.iso_a2) AS country_iso_code, country_gid country_id' + geom + ' FROM base_layers.provinces a' + (where.length > 0 ? ' WHERE ' + where.join(' AND ') : '') + ' ORDER BY ' + (order ? order : 'adm_code');
                        Severity: Major
                        Found in routes/api-engine_routes.js and 2 other locations - About 1 hr to fix
                        routes/api-engine_routes.js on lines 532..532
                        routes/api-engine_routes.js on lines 550..550

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

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

                                            sql = 'SELECT a.gid id, lower(a.iso_code_2) AS iso_code, a.' + nameCol + ' AS name' + geom + ' FROM base_layers.countries a' + (where.length > 0 ? ' WHERE ' + where.join(' AND ') : '') + ' ORDER BY ' + (order ? order : 'iso_code');
                        Severity: Major
                        Found in routes/api-engine_routes.js and 2 other locations - About 1 hr to fix
                        routes/api-engine_routes.js on lines 532..532
                        routes/api-engine_routes.js on lines 542..542

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

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

                                            sql = 'SELECT a.gid id, a.codigo AS adm_code, a.' + nameCol + ' AS name, a.cod_prov, a.provincia, a.cod_ccaa, a.comautonom, b.adm1_code as province_adm_code, province_gid province_id, lower(b.iso_a2) AS country_iso_code' + geom + ' FROM base_layers.municipalities a JOIN base_layers.provinces b ON a.province_gid = b.gid' + (where.length > 0 ? ' WHERE ' + where.join(' AND ') : '') + ' ORDER BY ' + (order ? order : 'cod_ccaa, cod_prov, adm_code');
                        Severity: Major
                        Found in routes/api-engine_routes.js and 2 other locations - About 1 hr to fix
                        routes/api-engine_routes.js on lines 542..542
                        routes/api-engine_routes.js on lines 550..550

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

                        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

                                        if (features && features.length > 0) {
                                            if ('geojson' in features[0]) {
                                                results = postGISQueryToFeatureCollection(features);
                                            } else {
                                                results = features;
                        Severity: Major
                        Found in routes/api-engine_routes.js and 1 other location - About 1 hr to fix
                        routes/api-engine_routes.js on lines 286..292

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

                        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

                                            if (features && features.length > 0) {
                                                if ('geojson' in features[0]) {
                                                    results = postGISQueryToFeatureCollection(features);
                                                } else {
                                                    results = features;
                        Severity: Major
                        Found in routes/api-engine_routes.js and 1 other location - About 1 hr to fix
                        routes/api-engine_routes.js on lines 567..573

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

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

                                            for (var i = 0, iLen = questions.length; i<iLen; i++) {
                                                answers.push(questions[i].Answers);
                                            }
                        Severity: Major
                        Found in routes/api-engine_routes.js and 2 other locations - About 50 mins to fix
                        models/question.js on lines 404..406
                        models/survey.js on lines 888..890

                        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

                        There are no issues that match your filters.

                        Category
                        Status