Showing 55 of 97 total issues
Function exports
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
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
Function merge
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
schema.methods.merge = function merge(other, callback) {
var self = this;
var conflicts = [];
var pathsToMerge = Object.keys(other.toObject());
_.each(pathsToMerge, function(path) {
Function paginate
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function paginate(options) {
options = options || {};
var page = parseInt(options.page, 10) || 1;
var perPage = parseInt(options.per_page, 10) || 30;
Function exports
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
module.exports = function(app) {
app.get('/:collection/:id(*)/full', function (req, res, next) {
var id = req.params.id;
Function importer
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function importer(connection, popoloObject, callback) {
var collections = [
['persons', 'Person'],
['people', 'Person'],
['organizations', 'Organization'],
Function checkMembership
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
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 ) {
- Read upRead up
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
Open
function paginate(options) {
options = options || {};
var page = parseInt(options.page, 10) || 1;
var perPage = parseInt(options.per_page, 10) || 30;
- Read upRead up
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
Open
module.exports = function(app) {
app.get('/:collection/:id/full', function (req, res, next) {
var id = req.params.id;
Function reIndex
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
schema.statics.reIndex = function(done) {
var self = this;
self.find(function(err, docs) {
if (err) {
return done(err);
Function hiddenFields
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function hiddenFields(req, res, next) {
var fields = {
all: {}
};
Function afterCreateMemberships
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
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]});
Function callCreateMembership
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function callCreateMembership(membership, cb) {
if ( ! membership.id ) {
createMembership(req, membership, function(err, membership) {
if ( err ) {
return cb(err);
Function esFilterDatesOnly
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
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]) {
Function exports
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
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) {
Function exports
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
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) {
Function bulkReIndex
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
schema.statics.bulkReIndex = function(docs, done) {
var self = this;
var indexed = 0;
var body;
async.concatSeries(docs, function(doc, callback) {
Function exports
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
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) {
Function popitApiApp
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function popitApiApp(options) {
var app = express();
require('../app-setup')(app, options);
Function removeOldMemberships
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function removeOldMemberships(req, memberships, key, id, done) {
var membership_ids =
_.chain(memberships)
.map( function(membership) { return membership.id; })
.compact()
Function importPopolo
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function importPopolo(req, res, next) {
var queue = kue.createQueue({
prefix: req.options.queuePrefix || 'popit-api-',
});
var job = queue.create('importPopolo', {