e-ucm/rage-analytics-backend

View on GitHub
lib/groups.js

Summary

Maintainability
F
1 wk
Test Coverage

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

module.exports = (function () {
    var Collection = require('easy-collections');
    var db = require('./db');
    var utils = require('./utils');
    var groups = new Collection(db, 'groups');
Severity: Major
Found in lib/groups.js - About 1 day to fix

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

    module.exports = (function () {
        var Collection = require('easy-collections');
        var db = require('./db');
        var utils = require('./utils');
        var groups = new Collection(db, 'groups');
    Severity: Minor
    Found in lib/groups.js - About 7 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

    File groups.js has 274 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    'use strict';
    
    module.exports = (function () {
        var Collection = require('easy-collections');
        var db = require('./db');
    Severity: Minor
    Found in lib/groups.js - About 2 hrs to fix

      Function removeGroups has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          groups.removeGroups = function (id, username) {
              return groups.findById(id)
                  .then(function (groupRes) {
                      if (!groupRes) {
                          throw {
      Severity: Minor
      Found in lib/groups.js - About 1 hr to fix

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

            groups.modifyGroup = function (id, username, body, add) {
                var validationObj = v.validate(body, groupSchema);
                validationObj = validationObj.errors.length > 0 ? v.validate(body, participantsGroupSchema) : validationObj;
                if (validationObj.errors && validationObj.errors.length > 0) {
                    throw {
        Severity: Minor
        Found in lib/groups.js - About 1 hr to fix

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

              groups.getUserTypeForArray = function (groupIds, username, ignoreStudents, ignoreAssistants, ignoreTeachers) {
                  if (groupIds.length > 0) {
                      groupIds = groupIds.slice(0);
                      var groupId = groupIds.shift();
                      return groups.getUserType(groupId, username, ignoreStudents, ignoreAssistants, ignoreTeachers)
          Severity: Minor
          Found in lib/groups.js - About 1 hr to fix

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

                groups.createGroup = function (username, classId, group) {
            
                    if (group.participants) {
                        if (!group.participants.teachers) {
                            group.participants.teachers = [];
            Severity: Minor
            Found in lib/groups.js - About 1 hr to fix

              Function getUserTypeForArray has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  groups.getUserTypeForArray = function (groupIds, username, ignoreStudents, ignoreAssistants, ignoreTeachers) {
              Severity: Minor
              Found in lib/groups.js - About 35 mins to fix

                Function getUserType has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    groups.getUserType = function (groupId, username, ignoreStudents, ignoreAssistants, ignoreTeachers) {
                Severity: Minor
                Found in lib/groups.js - About 35 mins to fix

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

                      groups.getUserTypeForArray = function (groupIds, username, ignoreStudents, ignoreAssistants, ignoreTeachers) {
                          if (groupIds.length > 0) {
                              groupIds = groupIds.slice(0);
                              var groupId = groupIds.shift();
                              return groups.getUserType(groupId, username, ignoreStudents, ignoreAssistants, ignoreTeachers)
                  Severity: Major
                  Found in lib/groups.js and 1 other location - About 1 day to fix
                  lib/groupings.js on lines 252..283

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

                  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 groupings.find({classId: groupRes.classId})
                                                  .then(function (groupingsRes) {
                                                      if (groupingsRes.length > 0) {
                                                          groupingsRes.forEach(function (classObj) {
                                                              var updateGroups = {};
                  Severity: Major
                  Found in lib/groups.js and 1 other location - About 6 hrs to fix
                  lib/groupings.js on lines 181..199

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

                  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 classes.findById(classId).then(function (classObj) {
                              if (!classObj) {
                                  throw {
                                      message: 'Class does not exist',
                                      status: 404
                  Severity: Major
                  Found in lib/groups.js and 1 other location - About 5 hrs to fix
                  lib/groupings.js on lines 88..106

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

                  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 groups.findById(groupId).then(function (group) {
                              if (group) {
                                  if (!ignoreTeachers && group.participants.teachers.indexOf(username) !== -1) {
                                      return 'teacher';
                                  }
                  Severity: Major
                  Found in lib/groups.js and 1 other location - About 4 hrs to fix
                  lib/classes.js on lines 553..566

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

                  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

                              participants: {
                                  type: 'object',
                                  properties: {
                                      students: {
                                          type: 'array',
                  Severity: Major
                  Found in lib/groups.js and 1 other location - About 3 hrs to fix
                  lib/classes.js on lines 40..59

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

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

                      function getBestType(type1, type2) {
                          if (type1 === 'teacher' || type2 === 'teacher') {
                              return 'teacher';
                          }
                          if (type1 === 'assistant' || type2 === 'assistant') {
                  Severity: Major
                  Found in lib/groups.js and 2 other locations - About 2 hrs to fix
                  lib/activities.js on lines 195..206
                  lib/groupings.js on lines 239..250

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

                  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 (classObj.groups && classObj.groups.length > 0) {
                                          var updateGroups = {};
                                          utils.addToArrayHandler(updateGroups, {groups: [groupRes._id]}, 'groups', false);
                                          classes.findAndUpdate(classObj._id, updateGroups);
                                      }
                  Severity: Major
                  Found in lib/groups.js and 1 other location - About 2 hrs to fix
                  lib/groupings.js on lines 175..179

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

                  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 (!group.participants.teachers || group.participants.teachers.indexOf(username) === -1) {
                                          throw {
                                              message: 'You don\'t have permission to modify this group.',
                                              status: 401
                                          };
                  Severity: Major
                  Found in lib/groups.js and 1 other location - About 1 hr to fix
                  lib/groups.js on lines 198..203

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

                  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 (!groupRes.participants.teachers || groupRes.participants.teachers.indexOf(username) === -1) {
                                      throw {
                                          message: 'You don\'t have permission to delete this groups.',
                                          status: 401
                                      };
                  Severity: Major
                  Found in lib/groups.js and 1 other location - About 1 hr to fix
                  lib/groups.js on lines 152..157

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

                  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

                                      if (add && body.name) {
                                          update.$set = {};
                                          update.$set.name = body.name;
                                      }
                  Severity: Minor
                  Found in lib/groups.js and 2 other locations - About 35 mins to fix
                  lib/courses.js on lines 111..114
                  lib/groupings.js on lines 147..150

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

                  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

                      groups.getGroups = function (classId) {
                          return groups.find({classId: groups.toObjectID(classId)});
                      };
                  Severity: Minor
                  Found in lib/groups.js and 1 other location - About 35 mins to fix
                  lib/groupings.js on lines 61..63

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

                  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