mysociety/popit-api

View on GitHub

Showing 55 of 97 total issues

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

module.exports = function(app) {

  app.post('/:collection', validateBody, function (req, res, next) {
    var body = req.body;
    // if there's an image and no body.images then add one as the popit front end uses
Severity: Minor
Found in src/routes/1.0/collection.post.js - About 1 hr to fix

    Function merge has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      schema.methods.merge = function merge(other, callback) {
        var self = this;
        var conflicts = [];
        var pathsToMerge = Object.keys(other.toObject());
        _.each(pathsToMerge, function(path) {
    Severity: Minor
    Found in src/mongoose/merge.js - About 1 hr to fix

      Function paginate has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function paginate(options) {
        options = options || {};
        var page = parseInt(options.page, 10) || 1;
        var perPage = parseInt(options.per_page, 10) || 30;
      
      
      Severity: Minor
      Found in src/paginate.js - About 1 hr to fix

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

        module.exports = function(app) {
        
          app.get('/:collection/:id(*)/full', function (req, res, next) {
            var id = req.params.id;
        
        
        Severity: Minor
        Found in src/routes/1.0/document.get.js - About 1 hr to fix

          Function importer has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function importer(connection, popoloObject, callback) {
            var collections = [
              ['persons', 'Person'],
              ['people', 'Person'],
              ['organizations', 'Organization'],
          Severity: Minor
          Found in src/importer.js - About 1 hr to fix

            Function checkMembership has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

            function checkMembership(req, membership, doc, done) {
              if ( req.model.modelName == 'Person' ) {
                if ( !membership.person_id ) {
                  membership.person_id = doc.id;
                } else if ( membership.person_id != doc.id ) {
            Severity: Minor
            Found in src/inline-memberships.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 paginate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

            function paginate(options) {
              options = options || {};
              var page = parseInt(options.page, 10) || 1;
              var perPage = parseInt(options.per_page, 10) || 30;
            
            
            Severity: Minor
            Found in src/paginate.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 exports has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            module.exports = function(app) {
            
              app.get('/:collection/:id/full', function (req, res, next) {
                var id = req.params.id;
            
            
            Severity: Minor
            Found in src/routes/document.get.js - About 1 hr to fix

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

                schema.statics.reIndex = function(done) {
                  var self = this;
                  self.find(function(err, docs) {
                    if (err) {
                      return done(err);
              Severity: Minor
              Found in src/mongoose/elasticsearch.js - About 1 hr to fix

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

                function hiddenFields(req, res, next) {
                  var fields = {
                    all: {}
                  };
                
                
                Severity: Minor
                Found in src/middleware/hidden-fields.js - About 1 hr to fix

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

                            }, function afterCreateMemberships(err) {
                            if (err) {
                              tidyUpInlineMembershipError(req, null, req.created_memberships, req.updated_memberships, function(innerErr) {
                                if ( innerErr ) {
                                  return res.send(400, {errors: [innerErr]});
                  Severity: Minor
                  Found in src/routes/1.0/document.put.js - About 1 hr to fix

                    Function callCreateMembership has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        function callCreateMembership(membership, cb) {
                          if ( ! membership.id ) {
                            createMembership(req, membership, function(err, membership) {
                              if ( err ) {
                                return cb(err);
                    Severity: Minor
                    Found in src/inline-memberships.js - About 1 hr to fix

                      Function esFilterDatesOnly has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        function esFilterDatesOnly(doc, ret) {
                          var missing = '';
                          for (var field in ret) {
                            if ( ['start_date', 'birth_date', 'founding_date', 'created_at', 'updated_at', 'valid_from'].indexOf(field) != -1 ) {
                              if (!ret[field]) {
                      Severity: Minor
                      Found in src/esfilter.js - About 1 hr to fix

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

                        module.exports = function(app) {
                        
                          app.get('/search/:collection', function(req, res, next) {
                            var pagination = paginate(req.query);
                            req.collection.search(req.query, function(err, result) {
                        Severity: Minor
                        Found in src/routes/search.js - About 1 hr to fix

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

                          module.exports = function(app) {
                          
                            app.get('/search/:collection', function(req, res, next) {
                              var pagination = paginate(req.query);
                              req.collection.search(req.query, function(err, result) {
                          Severity: Minor
                          Found in src/routes/1.0/search.js - About 1 hr to fix

                            Function bulkReIndex has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                              schema.statics.bulkReIndex = function(docs, done) {
                                var self = this;
                                var indexed = 0;
                                var body;
                                async.concatSeries(docs, function(doc, callback) {
                            Severity: Minor
                            Found in src/mongoose/elasticsearch.js - About 1 hr to fix

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

                              module.exports = function(app) {
                              
                                app.get('/:collection', function (req, res, next) {
                                  var pagination = paginate(req.query);
                                  req.collection.find({}, null, pagination, function (err, docs) {
                              Severity: Minor
                              Found in src/routes/collection.get.js - About 1 hr to fix

                                Function popitApiApp has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                function popitApiApp(options) {
                                  var app = express();
                                
                                  require('../app-setup')(app, options);
                                
                                
                                Severity: Minor
                                Found in src/versions/0.1.js - About 1 hr to fix

                                  Function removeOldMemberships has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  function removeOldMemberships(req, memberships, key, id, done) {
                                    var membership_ids =
                                      _.chain(memberships)
                                       .map( function(membership) { return membership.id; })
                                       .compact()
                                  Severity: Minor
                                  Found in src/inline-memberships.js - About 1 hr to fix

                                    Function importPopolo has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                      function importPopolo(req, res, next) {
                                        var queue = kue.createQueue({
                                          prefix: req.options.queuePrefix || 'popit-api-',
                                        });
                                        var job = queue.create('importPopolo', {
                                    Severity: Minor
                                    Found in src/routes/import.js - About 1 hr to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language