Emapic/emapic

View on GitHub
models/survey.js

Summary

Maintainability
F
2 wks
Test Coverage

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

module.exports = function(sequelize, DataTypes) {
    var Survey = sequelize.define('Survey', {
        id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true },
        title: { type: DataTypes.STRING, allowNull: false },
        description: DataTypes.STRING,
Severity: Major
Found in models/survey.js - About 4 days to fix

    File survey.js has 1037 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    var Promise = require('bluebird'),
        nconf = require('nconf'),
        htmlToText = require('html-to-text'),
        linkifyHtml = require('linkifyjs/html'),
        fsp = require('fs-extra'),
    Severity: Major
    Found in models/survey.js - About 2 days to fix

      Function exports has a Cognitive Complexity of 115 (exceeds 5 allowed). Consider refactoring.
      Open

      module.exports = function(sequelize, DataTypes) {
          var Survey = sequelize.define('Survey', {
              id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true },
              title: { type: DataTypes.STRING, allowNull: false },
              description: DataTypes.STRING,
      Severity: Minor
      Found in models/survey.js - About 2 days 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 getFiltersSQL has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
      Open

      function getFiltersSQL(getFilters, questions) {
          var sqls = [],
              params = {};
          if (getFilters) {
              for (var param in getFilters) {
      Severity: Minor
      Found in models/survey.js - About 6 hrs 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 has too many statements (51). Maximum allowed is 30.
      Open

      module.exports = function(sequelize, DataTypes) {
      Severity: Minor
      Found in models/survey.js by eslint

      enforce a maximum number of statements allowed in function blocks (max-statements)

      The max-statements rule allows you to specify the maximum number of statements allowed in a function.

      function foo() {
        var bar = 1; // one statement
        var baz = 2; // two statements
        var qux = 3; // three statements
      }

      Rule Details

      This rule enforces a maximum number of statements allowed in function blocks.

      Options

      This rule has a number or object option:

      • "max" (default 10) enforces a maximum number of statements allows in function blocks

      Deprecated: The object property maximum is deprecated; please use the object property max instead.

      This rule has an object option:

      • "ignoreTopLevelFunctions": true ignores top-level functions

      max

      Examples of incorrect code for this rule with the default { "max": 10 } option:

      /*eslint max-statements: ["error", 10]*/
      /*eslint-env es6*/
      
      function foo() {
        var foo1 = 1;
        var foo2 = 2;
        var foo3 = 3;
        var foo4 = 4;
        var foo5 = 5;
        var foo6 = 6;
        var foo7 = 7;
        var foo8 = 8;
        var foo9 = 9;
        var foo10 = 10;
      
        var foo11 = 11; // Too many.
      }
      
      let foo = () => {
        var foo1 = 1;
        var foo2 = 2;
        var foo3 = 3;
        var foo4 = 4;
        var foo5 = 5;
        var foo6 = 6;
        var foo7 = 7;
        var foo8 = 8;
        var foo9 = 9;
        var foo10 = 10;
      
        var foo11 = 11; // Too many.
      };

      Examples of correct code for this rule with the default { "max": 10 } option:

      /*eslint max-statements: ["error", 10]*/
      /*eslint-env es6*/
      
      function foo() {
        var foo1 = 1;
        var foo2 = 2;
        var foo3 = 3;
        var foo4 = 4;
        var foo5 = 5;
        var foo6 = 6;
        var foo7 = 7;
        var foo8 = 8;
        var foo9 = 9;
        var foo10 = 10;
        return function () {
      
          // The number of statements in the inner function does not count toward the
          // statement maximum.
      
          return 42;
        };
      }
      
      let foo = () => {
        var foo1 = 1;
        var foo2 = 2;
        var foo3 = 3;
        var foo4 = 4;
        var foo5 = 5;
        var foo6 = 6;
        var foo7 = 7;
        var foo8 = 8;
        var foo9 = 9;
        var foo10 = 10;
        return function () {
      
          // The number of statements in the inner function does not count toward the
          // statement maximum.
      
          return 42;
        };
      }

      ignoreTopLevelFunctions

      Examples of additional correct code for this rule with the { "max": 10 }, { "ignoreTopLevelFunctions": true } options:

      /*eslint max-statements: ["error", 10, { "ignoreTopLevelFunctions": true }]*/
      
      function foo() {
        var foo1 = 1;
        var foo2 = 2;
        var foo3 = 3;
        var foo4 = 4;
        var foo5 = 5;
        var foo6 = 6;
        var foo7 = 7;
        var foo8 = 8;
        var foo9 = 9;
        var foo10 = 10;
        var foo11 = 11;
      }

      Related Rules

      • [complexity](complexity.md)
      • [max-depth](max-depth.md)
      • [max-len](max-len.md)
      • [max-nested-callbacks](max-nested-callbacks.md)
      • [max-params](max-params.md) Source: http://eslint.org/docs/rules/

      Function getAggregatedTotals has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          Survey.prototype.getAggregatedTotals = function(layer, params) {
              var survey = this,
                  namePromise,
                  geom,
                  sql1,
      Severity: Major
      Found in models/survey.js - About 3 hrs to fix

        Function saveResponse has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            Survey.prototype.saveResponse = function(req) {
                var survey = this,
                    date = new Date(),
                    dateUtc = date.toISOString().replace(/T/, ' ').replace(/Z/, ''),
                    body = req.body;
        Severity: Major
        Found in models/survey.js - About 2 hrs to fix

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

              Survey.prototype.getLegend = function() {
                  var survey = this;
                  return this.getQuestions({
                      scope: 'includeAnswers'
                  }).then(function(questions) {
          Severity: Minor
          Found in models/survey.js - About 1 hr to fix

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

            function getFiltersSQL(getFilters, questions) {
                var sqls = [],
                    params = {};
                if (getFilters) {
                    for (var param in getFilters) {
            Severity: Minor
            Found in models/survey.js - About 1 hr to fix

              Consider simplifying this complex logical expression.
              Open

                      if ((body.emapic_experience_comments && body.emapic_experience_comments !== 'null') ||
                      (body.emapic_experience_final_position_reason && body.emapic_experience_final_position_reason !== 'null') ||
                      (body.emapic_experience_geolocation_result && body.emapic_experience_geolocation_result !== 'null')) {
                          var strquery = 'INSERT INTO metadata.emapic_opinions (browser_os, geolocation_result, final_position_reason, comments, geom, "timestamp", accuracy) VALUES (?, ?, ?, ?, ST_SetSRID(ST_MakePoint(?, ?), 4326), now(), ?)',
                              precision = parseFloat(body.precision);
              Severity: Critical
              Found in models/survey.js - About 1 hr to fix

                Function getSurveyResponsesSql has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                function getSurveyResponsesSql(survey, type, getFilters, lang) {
                    var id = survey.id,
                        countryNamePromise,
                        provinceNamePromise,
                        municipalityNamePromise;
                Severity: Minor
                Found in models/survey.js - About 1 hr to fix

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

                      Survey.createFromPost = function(req) {
                          var survey;
                          return Survey.create({
                              owner_id : req.user.id,
                              title : trimSubstringField(req.body.survey_title, 150),
                  Severity: Minor
                  Found in models/survey.js - About 1 hr to fix

                    Function updateFromPost has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        Survey.updateFromPost = function(req) {
                            var survey;
                            return Survey.findByPk(req.body.survey_id).then(function(surv) {
                                survey = surv;
                                var markerPromise = Promise.resolve(survey.custom_single_marker_file_id);
                    Severity: Minor
                    Found in models/survey.js - About 1 hr to fix

                      Function parseTagsFromPost has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function parseTagsFromPost(req) {
                          if (req.body.survey_tags && req.body.survey_tags.trim().length > 0) {
                              tags = req.body.survey_tags.substring(0, 150).trim();
                              var indivTags = tags.split(','),
                              indivTagsClean = [];
                      Severity: Minor
                      Found in models/survey.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 search has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                                  search: function(query, ordering) {
                                      var params = {
                                          where:
                                                  sequelize.where(
                                                      sequelize.fn('ts_match',
                      Severity: Minor
                      Found in models/survey.js - About 1 hr to fix

                        Function getUserFullResponses has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            Survey.prototype.getUserFullResponses = function(userId) {
                                var surv = this,
                                    id = this.id,
                                    questions;
                                return this.getQuestions({ scope: 'includeSurvey' }).then(function(qstns) {
                        Severity: Minor
                        Found in models/survey.js - About 1 hr to fix

                          Function findSurveys has 8 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              Survey.findSurveys = function(userId, onlyPublic, status, query, tag, order, pageSize, pageNr) {
                          Severity: Major
                          Found in models/survey.js - About 1 hr to fix

                            Function findPublicSurveysByUserLogin has 7 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                                Survey.findPublicSurveysByUserLogin = function(login, status, query, tag, order, pageSize, pageNr) {
                            Severity: Major
                            Found in models/survey.js - About 50 mins to fix

                              Function findPublicSurveys has 7 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                  Survey.findPublicSurveys = function(userId, status, query, tag, order, pageSize, pageNr) {
                              Severity: Major
                              Found in models/survey.js - About 50 mins to fix

                                Function getScopes has 6 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                    Survey.getScopes = function(userId, onlyPublic, status, query, tag, order) {
                                Severity: Minor
                                Found in models/survey.js - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                          if (!qstnFound) {
                                                              continue;
                                                          }
                                  Severity: Major
                                  Found in models/survey.js - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                            for (var i = 0, iLen = questions.length; i<iLen; i++) {
                                                                if (questions[i].legend_question && questions[i].question_order === q) {
                                                                    qstnFound = true;
                                                                    break;
                                                                }
                                    Severity: Major
                                    Found in models/survey.js - About 45 mins to fix

                                      Avoid deeply nested control flow statements.
                                      Open

                                                              if (isNaN(q)) {
                                                                  continue;
                                                              }
                                      Severity: Major
                                      Found in models/survey.js - About 45 mins to fix

                                        'i' is already defined.
                                        Open

                                                            for (var i = 0, iLen = order.length; i<iLen; i++) {
                                        Severity: Minor
                                        Found in models/survey.js by eslint

                                        disallow variable redeclaration (no-redeclare)

                                        In JavaScript, it's possible to redeclare the same variable name using var. This can lead to confusion as to where the variable is actually declared and initialized.

                                        Rule Details

                                        This rule is aimed at eliminating variables that have multiple declarations in the same scope.

                                        Examples of incorrect code for this rule:

                                        /*eslint no-redeclare: "error"*/
                                        
                                        var a = 3;
                                        var a = 10;

                                        Examples of correct code for this rule:

                                        /*eslint no-redeclare: "error"*/
                                        
                                        var a = 3;
                                        // ...
                                        a = 10;

                                        Options

                                        This rule takes one optional argument, an object with a boolean property "builtinGlobals". It defaults to false. If set to true, this rule also checks redeclaration of built-in globals, such as Object, Array, Number...

                                        builtinGlobals

                                        Examples of incorrect code for the { "builtinGlobals": true } option:

                                        /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
                                        
                                        var Object = 0;

                                        Examples of incorrect code for the { "builtinGlobals": true } option and the browser environment:

                                        /*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/
                                        /*eslint-env browser*/
                                        
                                        var top = 0;

                                        The browser environment has many built-in global variables (for example, top). Some of built-in global variables cannot be redeclared. Source: http://eslint.org/docs/rules/

                                        Missing radix parameter.
                                        Open

                                                                var q = parseInt(param.substring(8));
                                        Severity: Minor
                                        Found in models/survey.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

                                        The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
                                        Open

                                                for (var param in getFilters) {
                                        Severity: Minor
                                        Found in models/survey.js by eslint

                                        Require Guarding for-in (guard-for-in)

                                        Looping over objects with a for in loop will include properties that are inherited through the prototype chain. This behavior can lead to unexpected items in your for loop.

                                        for (key in foo) {
                                            doSomething(key);
                                        }

                                        Note that simply checking foo.hasOwnProperty(key) is likely to cause an error in some cases; see [no-prototype-builtins](no-prototype-builtins.md).

                                        Rule Details

                                        This rule is aimed at preventing unexpected behavior that could arise from using a for in loop without filtering the results in the loop. As such, it will warn when for in loops do not filter their results with an if statement.

                                        Examples of incorrect code for this rule:

                                        /*eslint guard-for-in: "error"*/
                                        
                                        for (key in foo) {
                                            doSomething(key);
                                        }

                                        Examples of correct code for this rule:

                                        /*eslint guard-for-in: "error"*/
                                        
                                        for (key in foo) {
                                            if (Object.prototype.hasOwnProperty.call(foo, key)) {
                                                doSomething(key);
                                            }
                                            if ({}.hasOwnProperty.call(foo, key)) {
                                                doSomething(key);
                                            }
                                        }

                                        Related Rules

                                        • [no-prototype-builtins](no-prototype-builtins.md)

                                        Further Reading

                                        Missing radix parameter.
                                        Open

                                                            params[param] = parseInt(getFilters[param]) / 1000; // Milliseconds to seconds
                                        Severity: Minor
                                        Found in models/survey.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

                                        TODO found
                                        Open

                                                // TODO resize the snapshots from the optimal size (512x288 / 512x512) to the smaller possible sizes (256x144 / 400x400)
                                        Severity: Minor
                                        Found in models/survey.js by fixme

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

                                                        markerPromise = survey.deleteCustomSingleMarker().then(function() {
                                                            return FileHelper.saveFileFromPath(req.files.custom_single_marker_img.path,
                                                                'images/survey/' + survey.id + '/marker/custom_single_marker' + path.extname(req.files.custom_single_marker_img.name),
                                                                req.files.custom_single_marker_img.name);
                                                        }).then(function(markerFileId) {
                                        Severity: Major
                                        Found in models/survey.js and 1 other location - About 2 hrs to fix
                                        models/survey.js on lines 560..564

                                        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

                                                        markerPromise = survey.deleteCustomSingleMarker().then(function() {
                                                            return FileHelper.saveFileFromPath(req.files.custom_single_marker_img.path,
                                                                'images/survey/' + survey.id + '/marker/custom_single_marker' + path.extname(req.files.custom_single_marker_img.name),
                                                                req.files.custom_single_marker_img.name);
                                                        });
                                        Severity: Major
                                        Found in models/survey.js and 1 other location - About 2 hrs to fix
                                        models/survey.js on lines 481..485

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

                                            Survey.prototype.getResponses = function(getFilters) {
                                                return getSurveyResponsesSql(this, answersRequestType.normal, getFilters).then(function(data) {
                                                    return sequelize.query(data.sql, {
                                                        replacements: data.params,
                                                        type: sequelize.QueryTypes.SELECT
                                        Severity: Major
                                        Found in models/survey.js and 1 other location - About 2 hrs to fix
                                        models/survey.js on lines 983..990

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

                                        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

                                            Survey.prototype.getAnonymizedResponses = function(getFilters) {
                                                return getSurveyResponsesSql(this, answersRequestType.anonymized, getFilters).then(function(data) {
                                                    return sequelize.query(data.sql, {
                                                        replacements: data.params,
                                                        type: sequelize.QueryTypes.SELECT
                                        Severity: Major
                                        Found in models/survey.js and 1 other location - About 2 hrs to fix
                                        models/survey.js on lines 974..981

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

                                        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 Promise.join(ownerPromise, this.getQuestions({
                                                    scope: 'includeAnswers'
                                                }), function(owner, questions) {
                                                    description.owner = owner.getDescription();
                                                    return Promise.map(questions, function(question) {
                                        Severity: Major
                                        Found in models/survey.js and 1 other location - About 1 hr to fix
                                        models/question.js on lines 722..732

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

                                                                return ', a.name' + (provinceName[0].exists ? '_' + params.lang : '') + ' AS name, ' +
                                                                    'c.name' + (countryName[0].exists ? '_' + params.lang : '') + ' AS supersuperheader';
                                        Severity: Major
                                        Found in models/survey.js and 1 other location - About 1 hr to fix
                                        models/survey.js on lines 1051..1052

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

                                        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 ', a.name' + (municipalityName[0].exists ? '_' + params.lang : '') + ' AS name, ' +
                                                                    'c.name' + (provinceName[0].exists ? '_' + params.lang : '') + ' AS superheader, ' +
                                        Severity: Major
                                        Found in models/survey.js and 1 other location - About 1 hr to fix
                                        models/survey.js on lines 1037..1038

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

                                        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

                                                if (pageSize !== null) {
                                                    params.limit = pageSize;
                                                    if (pageNr !== null && !isNaN(pageNr)) {
                                                        params.offset = (pageNr - 1) * pageSize;
                                                    }
                                        Severity: Major
                                        Found in models/survey.js and 1 other location - About 1 hr to fix
                                        models/user.js on lines 143..148

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

                                        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

                                                var description = this.getDescription(),
                                                    ownerPromise = typeof this.owner !== 'undefined' ?
                                                        Promise.resolve(this.owner) : this.getOwner();
                                        Severity: Minor
                                        Found in models/survey.js and 1 other location - About 55 mins to fix
                                        models/question.js on lines 719..721

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

                                        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

                                                            for (var i = 0, iLen = order.length; i<iLen; i++) {
                                                                params.order.push(order[i]);
                                                            }
                                        Severity: Minor
                                        Found in models/survey.js and 1 other location - About 55 mins to fix
                                        models/user.js on lines 129..131

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

                                        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

                                                provinceNamePromise = checkColumnExists('name_' + lang, 'provinces', 'base_layers').then(function(result) {
                                                    return result[0].exists ? 'name_' + lang : 'name';
                                                });
                                        Severity: Major
                                        Found in models/survey.js and 2 other locations - About 50 mins to fix
                                        models/survey.js on lines 123..125
                                        models/survey.js on lines 129..131

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

                                        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

                                                municipalityNamePromise = checkColumnExists('name_' + lang, 'municipalities', 'base_layers').then(function(result) {
                                                    return result[0].exists ? 'name_' + lang : 'name';
                                                });
                                        Severity: Major
                                        Found in models/survey.js and 2 other locations - About 50 mins to fix
                                        models/survey.js on lines 123..125
                                        models/survey.js on lines 126..128

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

                                        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

                                                countryNamePromise = checkColumnExists('name_' + lang, 'countries', 'base_layers').then(function(result) {
                                                    return result[0].exists ? 'name_' + lang : 'name';
                                                });
                                        Severity: Major
                                        Found in models/survey.js and 2 other locations - About 50 mins to fix
                                        models/survey.js on lines 126..128
                                        models/survey.js on lines 129..131

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

                                        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 j = 0, jLen = votes.length; j<jLen; j++) {
                                                        dates.push(votes[j].vote_date);
                                                    }
                                        Severity: Major
                                        Found in models/survey.js and 2 other locations - About 50 mins to fix
                                        models/question.js on lines 404..406
                                        routes/api-engine_routes.js on lines 103..105

                                        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

                                            } else {
                                                countryNamePromise = Promise.resolve('name');
                                                provinceNamePromise = Promise.resolve('name');
                                                municipalityNamePromise = Promise.resolve('name');
                                            }
                                        Severity: Minor
                                        Found in models/survey.js and 1 other location - About 40 mins to fix
                                        server.js on lines 62..66

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

                                        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

                                                    Utils.takeSnapshot(url, thumbnailsFolder + path.sep + 'small' + path.sep + encrId + '.png', 512, 288, 3000, 20000, 5, 256, 144),
                                        Severity: Minor
                                        Found in models/survey.js and 1 other location - About 30 mins to fix
                                        models/survey.js on lines 735..735

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

                                        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

                                                    Utils.takeSnapshot(url, thumbnailsFolder + path.sep + 'share' + path.sep + encrId + '.png', 512, 512, 3000, 30000, 5, 400, 400)
                                        Severity: Minor
                                        Found in models/survey.js and 1 other location - About 30 mins to fix
                                        models/survey.js on lines 734..734

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

                                        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