nci-ats/fs-middlelayer-api

View on GitHub
src/controllers/index.js

Summary

Maintainability
D
2 days
Test Coverage

Function routeRequest has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

const routeRequest = function(req, res){

    const reqPath = `/${req.params[0]}`;
    const reqMethod = req.method.toLowerCase();

Severity: Minor
Found in src/controllers/index.js - About 5 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 index.js has 286 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*

  ___ ___       ___               _ _       _   ___ ___ 
 | __/ __|  ___| _ \___ _ _ _ __ (_) |_    /_\ | _ \_ _|
 | _|\__ \ / -_)  _/ -_) '_| '  \| |  _|  / _ \|  _/| | 
Severity: Minor
Found in src/controllers/index.js - About 2 hrs to fix

    Function getControlNumber has 68 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const getControlNumber = function(req, res, reqData){
        const pathData = reqData.schema;
        const fileTypes = {
            'gud': 'guideDocumentation',
            'arf': 'acknowledgementOfRiskForm',
    Severity: Major
    Found in src/controllers/index.js - About 2 hrs to fix

      Function postApplication has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const postApplication = function(req, res, reqData){
      
          const pathData = reqData.schema;
      
          const body = util.getBody(req);
      Severity: Major
      Found in src/controllers/index.js - About 2 hrs to fix

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

        const routeRequest = function(req, res){
        
            const reqPath = `/${req.params[0]}`;
            const reqMethod = req.method.toLowerCase();
        
        
        Severity: Minor
        Found in src/controllers/index.js - About 1 hr to fix

          Function saveAndUploadFiles has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function saveAndUploadFiles(req, res, possbileFiles, files, controlNumber, application, callback){
          
              const asyncTasks = [];
          
              possbileFiles.forEach((fileConstraints)=>{
          Severity: Minor
          Found in src/controllers/index.js - About 1 hr to fix

            Function apiSchemaData has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

            function apiSchemaData(apiSchema, reqPath){
            
                if (apiSchema) {
                    for (const k in apiSchema.paths) {
            
            
            Severity: Minor
            Found in src/controllers/index.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 getControlNumberFileName has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const getControlNumberFileName = function(req, res, reqData) {
            
                const controlNumber = reqData.matches.controlNumber;
                const fileName = reqData.matches.fileName;
            
            
            Severity: Minor
            Found in src/controllers/index.js - About 1 hr to fix

              Function saveAndUploadFiles has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              function saveAndUploadFiles(req, res, possbileFiles, files, controlNumber, application, callback){
              Severity: Major
              Found in src/controllers/index.js - About 50 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                    if (!apiSchema.paths[apiPath][reqMethod].responses['200']) {
                                        return error.sendError(req, res, 500, 'No endpoint success found.');
                                    }
                                    else {
                                        
                Severity: Major
                Found in src/controllers/index.js - About 45 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return error.sendError(req, res, 404, 'Invalid endpoint.');
                  Severity: Major
                  Found in src/controllers/index.js - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status