nci-ats/fs-middlelayer-api

View on GitHub
src/controllers/validation.js

Summary

Maintainability
D
1 day
Test Coverage

File validation.js has 417 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*

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

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

    function generateErrorMesage(output){
    
        let errorMessage = '';
        const messages = [];
        output.errorArray.forEach((error)=>{
    Severity: Minor
    Found in src/controllers/validation.js - About 1 hr to fix

      Function checkFieldLengths has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function checkFieldLengths(schema, input, processedFieldErrors, path){
          const keys = Object.keys(schema);
          keys.forEach((key)=>{
              switch (key){
              case 'allOf':
      Severity: Minor
      Found in src/controllers/validation.js - About 1 hr to fix

        Function findField has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function findField(schema, field, func){
            const fieldCopy = JSON.parse(JSON.stringify(field));
            const schemaKeys = Object.keys(schema);
            schemaKeys.forEach((key)=>{
                if (key === fieldCopy[0]){
        Severity: Minor
        Found in src/controllers/validation.js - About 1 hr to fix

          Function checkForIndividualIsCitizen has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          function checkForIndividualIsCitizen(input, processedFieldErrors){
              if (input.tempOutfitterFields && input.applicantInfo){
                  if (!input.applicantInfo.orgType || input.applicantInfo.orgType.toUpperCase() === 'PERSON'){
                      if ((typeof input.tempOutfitterFields.individualIsCitizen) !== 'boolean'){
                          processedFieldErrors.errorArray.push(makeErrorObj('tempOutfitterFields.individualIsCitizen', 'missing'));
          Severity: Minor
          Found in src/controllers/validation.js - About 45 mins 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

          Avoid deeply nested control flow statements.
          Open

                              if (maxLength < fieldLength){
                                  
                                  processedFieldErrors.errorArray.push(makeErrorObj(field, 'length', maxLength));
                              }
          Severity: Major
          Found in src/controllers/validation.js - About 45 mins to fix

            Function makeErrorObj has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            function makeErrorObj(field, errorType, expectedFieldType, enumMessage, dependency, anyOfFields){
            Severity: Minor
            Found in src/controllers/validation.js - About 45 mins to fix

              Function checkForOrgName has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              function checkForOrgName(input, processedFieldErrors){
                  if (input.applicantInfo){
                      if (input.applicantInfo.orgType && input.applicantInfo.orgType.toUpperCase() !== 'PERSON'){
                          if (!input.applicantInfo.organizationName || input.applicantInfo.organizationName.length <= 0){
                              processedFieldErrors.errorArray.push(makeErrorObj('applicantInfo.organizationName', 'missing'));
              Severity: Minor
              Found in src/controllers/validation.js - About 35 mins 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 checkForSmallBusiness has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              function checkForSmallBusiness(input, processedFieldErrors){
                  if (input.tempOutfitterFields && input.applicantInfo){
                      if (input.applicantInfo.orgType && input.applicantInfo.orgType.toUpperCase() !== 'PERSON'){
                          if ((typeof input.tempOutfitterFields.smallBusiness) !== 'boolean'){
                              processedFieldErrors.errorArray.push(makeErrorObj('tempOutfitterFields.smallBusiness', 'missing'));
              Severity: Minor
              Found in src/controllers/validation.js - About 35 mins 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

              There are no issues that match your filters.

              Category
              Status