dsi-icl/optimise

View on GitHub
packages/optimise-core/src/controllers/dataController.js

Summary

Maintainability
F
3 days
Test Coverage

Function _RouterAddOrUpdate has 94 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    static _RouterAddOrUpdate(req, res) {
        if (optionsContainer.hasOwnProperty(`${req.params.dataType}`)) {
            const options = optionsContainer[req.params.dataType];
            if (!(req.body.hasOwnProperty(`${options.entryIdString}`) &&
                (req.body.hasOwnProperty('add') || req.body.hasOwnProperty('update')))) {
Severity: Major
Found in packages/optimise-core/src/controllers/dataController.js - About 3 hrs to fix

    Consider simplifying this complex logical expression.
    Open

                                                if (inputValue !== '' && !(inputValue === true || inputValue === false || inputValue === 1 || inputValue === 0 || inputValue === '1' || inputValue === '0' || inputValue.toUpperCase() === 'YES' || inputValue.toUpperCase() === 'NO')) {
                                                    res.status(400).json(ErrorHelper(`${message.dataMessage.BOOLEANFIELD}${fieldDefinition}`));
                                                    return false;
                                                }
    Severity: Critical
    Found in packages/optimise-core/src/controllers/dataController.js - About 1 hr to fix

      Function _RouterAddOrUpdate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          static _RouterAddOrUpdate(req, res) {
              if (optionsContainer.hasOwnProperty(`${req.params.dataType}`)) {
                  const options = optionsContainer[req.params.dataType];
                  if (!(req.body.hasOwnProperty(`${options.entryIdString}`) &&
                      (req.body.hasOwnProperty('add') || req.body.hasOwnProperty('update')))) {
      Severity: Minor
      Found in packages/optimise-core/src/controllers/dataController.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 _formatEntries has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static _formatEntries({ dataTableForeignKey, entryIdString }, { body, user }) {
              const returned = {};
              const numOfUpdates = (body.hasOwnProperty('update')) ? Object.keys(body.update).length : 0;
              const numOfAdds = (body.hasOwnProperty('add')) ? Object.keys(body.add).length : 0;
              const updates = [];
      Severity: Minor
      Found in packages/optimise-core/src/controllers/dataController.js - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                                            switch (fieldType) {
                                                case 5: //'B':
                                                    if (inputValue !== '' && !(inputValue === true || inputValue === false || inputValue === 1 || inputValue === 0 || inputValue === '1' || inputValue === '0' || inputValue.toUpperCase() === 'YES' || inputValue.toUpperCase() === 'NO')) {
                                                        res.status(400).json(ErrorHelper(`${message.dataMessage.BOOLEANFIELD}${fieldDefinition}`));
                                                        return false;
        Severity: Major
        Found in packages/optimise-core/src/controllers/dataController.js - About 45 mins to fix

          Avoid too many return statements within this function.
          Open

                                      return DataController._createAndUpdate(req, options, entries).then(() => {
                                          res.status(200).json(formatToJSON(`${message.dataMessage.SUCCESS}`));
                                          return true;
                                      }).catch((error) => {
                                          res.status(400).json(ErrorHelper(message.dataMessage.ERROR, error));
          Severity: Major
          Found in packages/optimise-core/src/controllers/dataController.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                                                            return false;
            Severity: Major
            Found in packages/optimise-core/src/controllers/dataController.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                                                              return false;
              Severity: Major
              Found in packages/optimise-core/src/controllers/dataController.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                                                return false;
                Severity: Major
                Found in packages/optimise-core/src/controllers/dataController.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                                                  return false;
                  Severity: Major
                  Found in packages/optimise-core/src/controllers/dataController.js - About 30 mins to fix

                    Function _formatEntries has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        static _formatEntries({ dataTableForeignKey, entryIdString }, { body, user }) {
                            const returned = {};
                            const numOfUpdates = (body.hasOwnProperty('update')) ? Object.keys(body.update).length : 0;
                            const numOfAdds = (body.hasOwnProperty('add')) ? Object.keys(body.add).length : 0;
                            const updates = [];
                    Severity: Minor
                    Found in packages/optimise-core/src/controllers/dataController.js - About 25 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

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

                            for (let i = 0; i < numOfUpdates; i++) {
                                const entry = {
                                    field: Object.keys(body.update)[i],
                                    value: body.update[Object.keys(body.update)[i]],
                                    createdByUser: user.id,
                    Severity: Major
                    Found in packages/optimise-core/src/controllers/dataController.js and 1 other location - About 4 hrs to fix
                    packages/optimise-core/src/controllers/dataController.js on lines 96..105

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

                    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

                            for (let i = 0; i < numOfAdds; i++) {
                                const entry = {
                                    field: Object.keys(body.add)[i],
                                    value: body.add[Object.keys(body.add)[i]],
                                    createdByUser: user.id,
                    Severity: Major
                    Found in packages/optimise-core/src/controllers/dataController.js and 1 other location - About 4 hrs to fix
                    packages/optimise-core/src/controllers/dataController.js on lines 86..95

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

                    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

                            for (let i = 0; entries.hasOwnProperty('updates') && i < entries.updates.length; i++) {
                                promiseArr.push(DataController._getField(fieldTable, entries.updates[i].field));
                            }
                    Severity: Major
                    Found in packages/optimise-core/src/controllers/dataController.js and 1 other location - About 2 hrs to fix
                    packages/optimise-core/src/controllers/dataController.js on lines 74..76

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

                    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

                            for (let i = 0; entries.hasOwnProperty('adds') && i < entries.adds.length; i++) {
                                promiseArr.push(DataController._getField(fieldTable, entries.adds[i].field));
                            }
                    Severity: Major
                    Found in packages/optimise-core/src/controllers/dataController.js and 1 other location - About 2 hrs to fix
                    packages/optimise-core/src/controllers/dataController.js on lines 71..73

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

                    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 (inputValue !== '' && !(inputValue === true || inputValue === false || inputValue === 1 || inputValue === 0 || inputValue === '1' || inputValue === '0' || inputValue.toUpperCase() === 'YES' || inputValue.toUpperCase() === 'NO')) {
                                                                    res.status(400).json(ErrorHelper(`${message.dataMessage.BOOLEANFIELD}${fieldDefinition}`));
                                                                    return false;
                                                                }
                    Severity: Major
                    Found in packages/optimise-core/src/controllers/dataController.js and 2 other locations - About 50 mins to fix
                    packages/optimise-core/src/controllers/dataController.js on lines 183..186
                    packages/optimise-core/src/controllers/dataController.js on lines 189..192

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

                    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 (inputValue !== '' && !(parseInt(inputValue) === parseFloat(inputValue))) {
                                                                    res.status(400).json(ErrorHelper(`${message.dataMessage.INTEGERFIELD}${fieldDefinition}`));
                                                                    return false;
                                                                }
                    Severity: Major
                    Found in packages/optimise-core/src/controllers/dataController.js and 2 other locations - About 50 mins to fix
                    packages/optimise-core/src/controllers/dataController.js on lines 171..174
                    packages/optimise-core/src/controllers/dataController.js on lines 189..192

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

                    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 (inputValue !== '' && !(parseFloat(inputValue).toString() === inputValue.toString())) {
                                                                    res.status(400).json(ErrorHelper(`${message.dataMessage.NUMBERFIELD}${fieldDefinition}`));
                                                                    return false;
                                                                }
                    Severity: Major
                    Found in packages/optimise-core/src/controllers/dataController.js and 2 other locations - About 50 mins to fix
                    packages/optimise-core/src/controllers/dataController.js on lines 171..174
                    packages/optimise-core/src/controllers/dataController.js on lines 183..186

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

                    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 (result.length <= 0) {
                                                    res.status(400).json(ErrorHelper(message.dataMessage.FIELDNOTFOUND));
                                                    return false;
                                                }
                    Severity: Minor
                    Found in packages/optimise-core/src/controllers/dataController.js and 1 other location - About 40 mins to fix
                    packages/optimise-core/src/controllers/patientController.js on lines 115..118

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

                    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