RouteInjector/route-injector

View on GitHub

Showing 414 of 414 total issues

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

            if (gConfig.shard && gConfig.shard.shardKey && gConfig.shard.shardKey != "") {
                var shard = req.query[gConfig.shard.shardKey] || req.body[gConfig.shard.shardKey];
                if (shard) {
                    query[gConfig.shard.shardKey] = shard;
                }
Severity: Major
Found in lib/engine/routeinjector/rest/export.js and 1 other location - About 3 hrs to fix
lib/engine/routeinjector/rest/search.js on lines 74..79

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

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

            if (gConfig.shard && gConfig.shard.shardKey && gConfig.shard.shardKey != "") {
                var shard = req.query[gConfig.shard.shardKey] || req.body[gConfig.shard.shardKey];
                if (shard) {
                    query[gConfig.shard.shardKey] = shard;
                }
Severity: Major
Found in lib/engine/routeinjector/rest/search.js and 1 other location - About 3 hrs to fix
lib/engine/routeinjector/rest/export.js on lines 290..295

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

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

Function process has 91 lines of code (exceeds 25 allowed). Consider refactoring.
Open

                        function process() {

                            var outFile = path.join(outDirectory, fileName);//path.basename(req.files.image.path));

                            var fileToDb = {
Severity: Major
Found in lib/engine/routeinjector/images/new-image-injector.js - About 3 hrs to fix

    Function post has 89 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports.post = function (Model) {
        return function (req, res) {
            var gConfig = Model.injector();
            var returnField = Model.injector().id;
            var config = utils.getConfigByProfile(gConfig.post, req);
    Severity: Major
    Found in lib/engine/routeinjector/rest/post.js - About 3 hrs to fix

      Function login has 89 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      exports.login = function (req, res) {
          var loginValue = req.body.login;
          var hash = req.body.password;
          var token = req.body.token;
      
      Severity: Major
      Found in lib/engine/routeinjector/routes/auth.js - About 3 hrs to fix

        Function PluginRegistry has 89 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        var PluginRegistry = /** @class */ (function () {
            function PluginRegistry(config) {
                this._plugins = {};
                PluginRegistry.logger.trace("Creating ModelsLoader instance");
                this.config = config;
        Severity: Major
        Found in lib/app/internals/PluginRegistry.js - About 3 hrs to fix

          Function transform has 86 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function transform(Model, key, fullKey, modelConfig, field) {
              /*var sc = getElementSchema(Model.schema.paths, fullKey);
               if(sc){
               sc.options["x-schema-form"] = sc.options["x-schema-form"] || {};
               sc.options["x-schema-form"]["disableSuccessState"] = true;
          Severity: Major
          Found in lib/engine/routeinjector/typeBased.js - About 3 hrs to fix

            Function process has 86 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                                function process() {
            
                                    var outFile = path.join(outDirectory, fileName);//path.basename(req.files.image.path));
                                    log.debug('File: ', outFile);
            
            Severity: Major
            Found in lib/engine/routeinjector/images/image-injector.js - About 3 hrs to fix

              Function process has 86 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                                  function process() {
              
                                      var outFile = path.join(outDirectory, fileName);//path.basename(req.files.file.path));
                                      log.debug('File: ', outFile);
              
              Severity: Major
              Found in lib/engine/routeinjector/files/file-injector.js - About 3 hrs to fix

                Function mainDeleteFn has 86 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        function mainDeleteFn() {
                            //ID CHECKING
                            if (gConfig.id == "_id" && !mongoose.Types.ObjectId.isValid(req.params[gConfig.id]) && !isTypeRaw) {
                                res.statusCode = statusCode.NOT_FOUND;
                                res.json("Document not found. Invalid mongoose id");
                Severity: Major
                Found in lib/engine/routeinjector/rest/delete.js - About 3 hrs to fix

                  Function expressSetup has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function expressSetup(app, config) {
                      app.set('views', FSUtils.join(config.appPath, 'views'));
                      app.set('view engine', config.application.view_engine || 'ejs');
                      logger.token('body', function getUrlToken(req) {
                          return req.__body || "";
                  Severity: Minor
                  Found in lib/app/internals/express/ExpressMiddlewares.js - About 3 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 expressSetup has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                  Open

                  export function expressSetup(app:Express, config:any) {
                  
                      app.set('views', FSUtils.join(config.appPath, 'views'));
                      app.set('view engine', config.application.view_engine || 'ejs');
                  
                  
                  Severity: Minor
                  Found in lib/app/internals/express/ExpressMiddlewares.ts - About 3 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 getByField has 84 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  module.exports.getByField = function (Model) {
                  
                      return function (req, res) {
                          var gConfig = Model.injector();
                          var isTypeBack = (req.query.type && req.query.type == "back"); //Special for filter normalizations
                  Severity: Major
                  Found in lib/engine/routeinjector/rest/get.js - About 3 hrs to fix

                    Function TypeBased has 83 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    var TypeBased = /** @class */ (function () {
                        function TypeBased() {
                        }
                        //TODO: Add hooks and middlewares
                        TypeBased.directReference = function (model, field, refModel, refField) {
                    Severity: Major
                    Found in lib/engine/routeinjector/newTypeBased/TypeBased.js - About 3 hrs to fix

                      Function AuthManager has 83 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      var AuthManager = /** @class */ (function () {
                          function AuthManager(config, models) {
                              var _this = this;
                              this.checkRole = function (role) { return ({
                                  name: 'checkRole(' + role + ')',
                      Severity: Major
                      Found in lib/app/internals/AuthManager.js - About 3 hrs to fix

                        Function handleGetImage has 82 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            GalleryInjector.prototype.handleGetImage = function () {
                                var _this = this;
                                var IMGR = require('imgr').IMGR;
                                var config = this.routeInjector.config.env.images.imgrConfig || {};
                                if (config.optimisation == undefined) {
                        Severity: Major
                        Found in lib/engine/routeinjector/images/GalleryInjector.js - About 3 hrs to fix

                          Function PageLoader has 82 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          var PageLoader = /** @class */ (function () {
                              function PageLoader(config, pluginRegistry) {
                                  this.directories = [];
                                  this._pages = {};
                                  PageLoader.logger.trace("Creating PageLoader instance");
                          Severity: Major
                          Found in lib/app/internals/PageLoader.js - About 3 hrs to fix

                            Function denormalize has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
                            Open

                            module.exports.denormalize = function (field, rkey, Model, isArray, fullPath) {
                                var needsFromDBhook = true;
                                var denormalizedFields = field.denormalize;
                                log.debug("Adding denormalized params :\"" + denormalizedFields + "\" to field " + fullPath + " in model " + Model.modelName);
                            
                            Severity: Minor
                            Found in lib/engine/routeinjector/newdenormalizer.js - About 3 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 mainPostFn has 81 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                    function mainPostFn() {
                                        var documentDB;
                                        var newModel = {};
                                        //Check incoming body has value
                                        if (req.body != undefined && req.body) {
                            Severity: Major
                            Found in lib/engine/routeinjector/rest/post.js - About 3 hrs to fix

                              Function punchgraph has 81 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              module.exports.punchgraph = function (Model, punchcard) {
                              
                                  var dateField = punchcard.dateField;
                                  var groupBy = punchcard.groupBy || "";
                                  var defaultQuery = punchcard.query || {};
                              Severity: Major
                              Found in lib/engine/routeinjector/graphs/punchgraph.js - About 3 hrs to fix
                                Severity
                                Category
                                Status
                                Source
                                Language