Emapic/emapic

View on GitHub

Showing 122 of 2,019 total issues

Function facebookAuth has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    function facebookAuth (req, profile, token) {
        var usr;
        return models.User.findOne({ where: { 'facebook_id' : profile.id } }).then(function(user) {
            if (user === null) {
                if (!('emails' in profile) || profile.emails.length === 0) {
Severity: Major
Found in routes/auth/index.js - About 2 hrs to fix

    Function parseAnswersFromPost has 55 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function parseAnswersFromPost(req, questions, oldAnswers) {
        var answers = [];
        oldAnswers = oldAnswers || null;
        for (var i = 1, iLen = questions.length; i<=iLen; i++) {
            var question = questions[i-1];
    Severity: Major
    Found in models/question.js - About 2 hrs to fix

      Function saveFileFromPath has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              saveFileFromPath: function(srcPath, dstPath, fileName, defaultMime) {
                  var cleanDstPath = dstPath;
                  while(cleanDstPath.charAt(0) === path.sep) {
                      cleanDstPath = cleanDstPath.substr(1);
                  }
      Severity: Minor
      Found in utils/file_helper.js - About 2 hrs to fix

        Function googleAuth has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function googleAuth (req, profile, token) {
                var usr;
                return models.User.findOne({ where: { 'google_id' : profile.id } }).then(function(user) {
                    if (user === null) {
                        // If we don't find it by google id, we try by email
        Severity: Minor
        Found in routes/auth/index.js - About 2 hrs to fix

          Function saveFileFromBuffer has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  saveFileFromBuffer: function(buffer, dstPath, fileName, defaultMime) {
                      var cleanDstPath = dstPath;
                      while(cleanDstPath.charAt(0) === path.sep) {
                          cleanDstPath = cleanDstPath.substr(1);
                      }
          Severity: Minor
          Found in utils/file_helper.js - About 1 hr to fix

            Function getAnsweredSurveysWithAllDates has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                User.prototype.getAnsweredSurveysWithAllDates = function() {
                    var userId = this.id;
                    return Promise.reduce(this.getVotes({
                            include: [
                                {
            Severity: Minor
            Found in models/user.js - About 1 hr 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 transform has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                                transform: function(result) {
                                    // First line is always the header, which doesn't need transforming
                                    if (results.indexOf(result) === 0) {
                                        return result;
                                    }
                Severity: Minor
                Found in routes/utils_api.js - About 1 hr to fix

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

                  module.exports = function(app) {
                      FileHelper = {
                  
                          saveFileFromBuffer: function(buffer, dstPath, fileName, defaultMime) {
                              var cleanDstPath = dstPath;
                  Severity: Minor
                  Found in utils/file_helper.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 checkValidAnswersFromPost has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function checkValidAnswersFromPost(req, questions) {
                      var answers = [];
                      for (var i = 1, iLen = questions.length; i<=iLen; i++) {
                          var question = questions[i-1];
                          switch(question.type) {
                  Severity: Minor
                  Found in models/question.js - About 1 hr to fix

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

                    module.exports = function(sequelize, DataTypes) {
                        var Answer = sequelize.define('Answer', {
                            id: { type: DataTypes.BIGINT, autoIncrement: true, primaryKey: true },
                            answer: { type: DataTypes.STRING, allowNull: false },
                            img: { type: DataTypes.BLOB },
                    Severity: Minor
                    Found in models/answer.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 ((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 ((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

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