bcgov/common-object-management-service

View on GitHub
app/src/services/metadata.js

Summary

Maintainability
F
5 days
Test Coverage
F
48%

Function associateMetadata has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

  associateMetadata: async (versionId, metadata, currentUserId = SYSTEM_USER, etrx = undefined) => {
    let trx;
    try {
      trx = etrx ? etrx : await Metadata.startTransaction();
      let response = [];
Severity: Minor
Found in app/src/services/metadata.js - About 2 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 associateMetadata has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  associateMetadata: async (versionId, metadata, currentUserId = SYSTEM_USER, etrx = undefined) => {
    let trx;
    try {
      trx = etrx ? etrx : await Metadata.startTransaction();
      let response = [];
Severity: Minor
Found in app/src/services/metadata.js - About 1 hr to fix

    Function fetchMetadataForVersion has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      fetchMetadataForVersion: async (params, etrx = undefined) => {
        let trx;
        try {
          trx = etrx ? etrx : await Metadata.startTransaction();
    
    
    Severity: Minor
    Found in app/src/services/metadata.js - About 1 hr to fix

      Function createMetadata has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        createMetadata: async (metadata, etrx = undefined) => {
          let trx;
          let response = [];
          try {
            trx = etrx ? etrx : await Metadata.startTransaction();
      Severity: Minor
      Found in app/src/services/metadata.js - About 1 hr to fix

        Function fetchMetadataForObject has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          fetchMetadataForObject: (params) => {
            return ObjectModel.query()
              .select('object.id AS objectId', 'object.bucketId as bucketId')
              .allowGraph('[bucketPermission, objectPermission, version.metadata]')
              .withGraphJoined('version.metadata')
        Severity: Minor
        Found in app/src/services/metadata.js - About 1 hr to fix

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

            createMetadata: async (metadata, etrx = undefined) => {
              let trx;
              let response = [];
              try {
                trx = etrx ? etrx : await Metadata.startTransaction();
          Severity: Minor
          Found in app/src/services/metadata.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

          TODO found
          Open

                  // TODO: call a dissociateMetadata() function for this version
          Severity: Minor
          Found in app/src/services/metadata.js by fixme

          TODO found
          Open

                // TODO: consider doing one bulk delete query instead of using forEach
          Severity: Minor
          Found in app/src/services/metadata.js by fixme

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

            fetchMetadataForObject: (params) => {
              return ObjectModel.query()
                .select('object.id AS objectId', 'object.bucketId as bucketId')
                .allowGraph('[bucketPermission, objectPermission, version.metadata]')
                .withGraphJoined('version.metadata')
          Severity: Major
          Found in app/src/services/metadata.js and 1 other location - About 1 day to fix
          app/src/services/tag.js on lines 233..268

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

          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

            pruneOrphanedMetadata: async (etrx = undefined) => {
              let trx;
              try {
                trx = etrx ? etrx : await Metadata.startTransaction();
          
          
          Severity: Major
          Found in app/src/services/metadata.js and 1 other location - About 1 day to fix
          app/src/services/tag.js on lines 150..171

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

          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

                metadata.forEach(async meta => {
                  // match on key
                  const params = { 'metadata.key': meta.key };
                  // if metadata has a value match key and value
                  if (meta.value && meta.value !== '') params['metadata.value'] = meta.value;
          Severity: Major
          Found in app/src/services/metadata.js and 1 other location - About 5 hrs to fix
          app/src/services/tag.js on lines 114..130

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

          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

            searchMetadata: (params) => {
              return Metadata.query()
                .modify((query) => {
                  if (params.privacyMask) {
                    query
          Severity: Major
          Found in app/src/services/metadata.js and 1 other location - About 3 hrs to fix
          app/src/services/tag.js on lines 330..344

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

          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

                const response = await Version.query(trx)
                  .select('version.id as versionId', 'version.s3VersionId')
                  .allowGraph('metadata')
                  .withGraphJoined('metadata')
                  .modifyGraph('metadata', builder => {
          Severity: Major
          Found in app/src/services/metadata.js and 1 other location - About 2 hrs to fix
          app/src/services/tag.js on lines 285..307

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

          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 (newMetadata.length) {
                  const newMetadataRecords = await Metadata.query(trx)
                    .insert(newMetadata)
                    .returning('*');
                  // merge new with existing metadata
          Severity: Major
          Found in app/src/services/metadata.js and 1 other location - About 2 hrs to fix
          app/src/services/tag.js on lines 204..213

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

          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

                    const dissociateMetadata = associatedMetadata.filter(({ metadataId }) => {
                      return !dbMetadata.some(({ id }) => id === metadataId);
                    });
          Severity: Minor
          Found in app/src/services/metadata.js and 1 other location - About 55 mins to fix
          app/src/services/tag.js on lines 76..78

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

          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

                    response = await VersionMetadata.query(trx)
                      .insert(newJoins.map(({ id }) => ({
                        versionId: versionId,
                        metadataId: id,
                        createdBy: currentUserId
          Severity: Minor
          Found in app/src/services/metadata.js and 1 other location - About 55 mins to fix
          app/src/services/tag.js on lines 81..86

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

          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