RouteInjector/route-injector

View on GitHub

Showing 414 of 414 total issues

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

            if (restrictions && restrictions.whitelist && restrictions.whitelist.roles && restrictions.whitelist.roles.indexOf(req.user.role) == -1)
                return kick();
Severity: Major
Found in lib/engine/routeinjector/routes/auth/utils.js and 1 other location - About 1 hr to fix
lib/engine/routeinjector/routes/auth/utils.js on lines 33..34

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

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 (defaultValue && opt.setDefaults) {
                                    pathO.options.default = defaultValue;
                                    if (type.type == 'date') {
                                        pathO.options.default = pathO.options.default.toISOString();
                                    }
lib/mongoose-plugins/mongoose-jsonform/lib/mongoose-jsonform.js on lines 169..174

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

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 walkSchema has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function walkSchema(app, Model, schema, parentName, fromArray, rawPath) {
    var modelConfig = utils.getModels()[Model.modelName];
    for (var key in schema) {
        var field = schema[key];
Severity: Minor
Found in lib/engine/routeinjector/typeBased.js - About 1 hr to fix

    Function getFileNameFromFile has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function getFileNameFromFile(outDirectory, sourceFileName, cb) {
        var fileName = null;
        sourceFileName = sourceFileName.toLowerCase();
    
        if (!fs.existsSync(outDirectory)) {
    Severity: Minor
    Found in lib/engine/routeinjector/images/new-image-injector.js - About 1 hr to fix

      Function getFileNameFromFile has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function getFileNameFromFile(outDirectory, sourceFileName, cb) {
          var fileName = null;
          sourceFileName = sourceFileName.toLowerCase();
      
          if (!fs.existsSync(outDirectory)) {
      Severity: Minor
      Found in lib/engine/routeinjector/files/file-injector.js - About 1 hr to fix

        Function DBConnection has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        var DBConnection = /** @class */ (function () {
            function DBConnection(config) {
                DBConnection.logger.trace("Creating DBConnection instance");
                this.config = config;
                this.debug(this.config.env.database.debug || false);
        Severity: Minor
        Found in lib/app/internals/DBConnection.js - About 1 hr to fix

          Function getFileNameFromFile has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function getFileNameFromFile(outDirectory, sourceFileName,cb){
              var fileName=null;
              sourceFileName=sourceFileName.toLowerCase();
          
              if (!fs.existsSync(outDirectory)){
          Severity: Minor
          Found in lib/engine/routeinjector/images/image-injector.js - About 1 hr to fix

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

            function checkRole(role) {
            
                return function (req, res, next) {
                    var injector = require('../../../../');
                    var config = injector.config;
            Severity: Minor
            Found in lib/engine/routeinjector/routes/auth/utils.js - About 1 hr to fix

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

                      function uploadFile(item, cb) {
                          fs.exists(item.path, function (exists) {
                              if (exists) {
                                  //TODO pass as setting paramter
                                  if(1==0) {//Get file name as randoom
              Severity: Minor
              Found in lib/engine/routeinjector/images/image-injector.js - About 1 hr to fix

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

                        function uploadFile(item, cb) {
                            fs.exists(item.path, function (exists) {
                                if (exists) {
                                    //TODO pass as setting paramter
                                    if (1 == 0) {//Get file name as randoom
                Severity: Minor
                Found in lib/engine/routeinjector/images/new-image-injector.js - About 1 hr to fix

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

                                          function endOK() {
                                              var refConf = confs[refModel.modelName];
                  
                                              if (refConf.search.disable === true) {
                                                  res.statusCode = statusCode.UNAUTHORIZED;
                  Severity: Minor
                  Found in lib/engine/routeinjector/typeBased/typeBased.js - About 1 hr to fix

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

                                    function save(doc) {
                                        var defer = Q.defer();
                                        //Create the Model object from the json received
                                        if (Model.injector()._references) {
                                            if (Model.injector()._references.toDB) {
                    Severity: Minor
                    Found in lib/engine/routeinjector/rest/put.js - About 1 hr to fix

                      Function expressSetup has 33 lines of code (exceeds 25 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 1 hr to fix

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

                        var Logger = /** @class */ (function () {
                            function Logger() {
                            }
                            /**
                             * Get a logger to log your application
                        Severity: Minor
                        Found in lib/app/internals/Logger.js - About 1 hr to fix

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

                          var MiddlewareRegistry = /** @class */ (function () {
                              function MiddlewareRegistry(config) {
                                  this._middlewares = {};
                                  this.config = config;
                                  MiddlewareRegistry.logger.trace("Creating MiddlewareRegistry instance");
                          Severity: Minor
                          Found in lib/app/internals/MiddlewareRegistry.js - About 1 hr to fix

                            Function expressSetup has 33 lines of code (exceeds 25 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 1 hr to fix

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

                                  FSUtils.clearCache = function (cfg, relativePath) {
                                      var e_1, _a;
                                      return __awaiter(this, void 0, void 0, function () {
                                          var dirName, baseNameNoExt, globPath, stream, stream_1, stream_1_1, entry, e_1_1;
                                          return __generator(this, function (_b) {
                              Severity: Minor
                              Found in lib/utils/FSUtils.js - About 1 hr to fix

                                Function doLogin has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    function doLogin(model, cbk) {
                                        if (loginInfo.found == undefined) {
                                            model.findOne(loginCondition, null).lean().exec(function (err, result) {
                                                //var logModels = config.login.model;
                                                if (err) {
                                Severity: Minor
                                Found in lib/engine/routeinjector/routes/auth.js - About 1 hr to fix

                                  Function checkToken has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  exports.checkToken = function (req, res, cb) {
                                      var token = req.params.token;
                                      jwt.verify(token, aconf["token.secret"], function (unauthorized, decoded) {
                                          if (unauthorized) {
                                              if(cb) return cb(false);
                                  Severity: Minor
                                  Found in lib/engine/routeinjector/routes/auth.js - About 1 hr to fix

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

                                    function getImage(param) {
                                        return function (req, res) {
                                    
                                            var conf = param.model.injector();
                                    
                                    Severity: Minor
                                    Found in lib/engine/routeinjector/images/image-injector.js - About 1 hr to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language