resource-watch/graph-client

View on GitHub
app/src/services/query.service.js

Summary

Maintainability
F
3 days
Test Coverage
F
58%

File query.service.js has 469 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-disable no-underscore-dangle */
const logger = require('logger');
const Neo4JService = require('services/neo4j.service');

const CREATE_DATASET = `MERGE (dataset:DATASET {id: {id}, views: 0}) RETURN dataset`;
Severity: Minor
Found in app/src/services/query.service.js - About 7 hrs to fix

    QueryService has 29 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class QueryService {
    
        static async run(query, params) {
            logger.info('Doing query ONLY READ ', query);
            const data = await Neo4JService.query(query, params);
    Severity: Minor
    Found in app/src/services/query.service.js - About 3 hrs to fix

      Function sortDatasets has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static async sortDatasets(sort = '', datasets = null) {
              let query;
              let dir = 'ASC';
              if (sort.startsWith('-')) {
                  // eslint-disable-next-line no-param-reassign
      Severity: Minor
      Found in app/src/services/query.service.js - About 1 hr to fix

        Function getListConcepts has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            static async getListConcepts(application, includes = null, search = null) {
                logger.debug('Getting list concepts');
                let query = QUERY_GET_LIST_CONCEPTS[0];
                if ((includes && includes.length > 0) || (search && search.length > 0)) {
                    query += ' WHERE ';
        Severity: Minor
        Found in app/src/services/query.service.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 querySearchDatasets has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static async querySearchDatasets(concepts, application, depth) {
                logger.debug('Searching datasets with concepts ', concepts);
        
                let query = '';
                const params = {
        Severity: Minor
        Found in app/src/services/query.service.js - About 1 hr to fix

          Function sortDatasets has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              static async sortDatasets(sort = '', datasets = null) {
                  let query;
                  let dir = 'ASC';
                  if (sort.startsWith('-')) {
                      // eslint-disable-next-line no-param-reassign
          Severity: Minor
          Found in app/src/services/query.service.js - About 55 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 querySearchDatasets has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              static async querySearchDatasets(concepts, application, depth) {
                  logger.debug('Searching datasets with concepts ', concepts);
          
                  let query = '';
                  const params = {
          Severity: Minor
          Found in app/src/services/query.service.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

          Identical blocks of code found in 3 locations. Consider refactoring.
          Open

                  if (results.records) {
                      results.records.map((el) => {
                          if (el._fields[0].length > 0) {
                              datasetIds = datasetIds.concat(el._fields[0]);
                          }
          Severity: Major
          Found in app/src/services/query.service.js and 2 other locations - About 2 hrs to fix
          app/src/routes/api/v1/graph.router.js on lines 263..270
          app/src/routes/api/v1/graph.router.js on lines 301..308

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

          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 (application) {
                      logger.debug(DELETE_RELATION.replace('{resourceType}', resourceType));
                      await QueryService.run(DELETE_RELATION.replace('{resourceType}', resourceType), {
                          resourceId,
                          application
          Severity: Major
          Found in app/src/services/query.service.js and 1 other location - About 1 hr to fix
          app/src/services/query.service.js on lines 288..294

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

          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

                  } else {
                      logger.debug(DELETE_RELATION_ALL_APPS.replace('{resourceType}', resourceType));
                      await QueryService.run(DELETE_RELATION_ALL_APPS.replace('{resourceType}', resourceType), {
                          resourceId,
                          application
          Severity: Major
          Found in app/src/services/query.service.js and 1 other location - About 1 hr to fix
          app/src/services/query.service.js on lines 282..288

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

          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 4 locations. Consider refactoring.
          Open

              static async createWidgetNodeAndRelation(idDataset, idWidget) {
                  logger.debug('Creating widget and relation with id ', idWidget, '; id dataset', idDataset);
                  return QueryService.run(CREATE_WIDGET_AND_RELATION, {
                      idWidget,
                      idDataset
          Severity: Major
          Found in app/src/services/query.service.js and 3 other locations - About 35 mins to fix
          app/src/services/query.service.js on lines 377..383
          app/src/services/query.service.js on lines 392..398
          app/src/services/query.service.js on lines 453..459

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

          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 4 locations. Consider refactoring.
          Open

              static async createLayerNodeAndRelation(idDataset, idLayer) {
                  logger.debug('Creating layer and relation with id ', idLayer, '; id dataset', idDataset);
                  return QueryService.run(CREATE_LAYER_AND_RELATION, {
                      idLayer,
                      idDataset
          Severity: Major
          Found in app/src/services/query.service.js and 3 other locations - About 35 mins to fix
          app/src/services/query.service.js on lines 369..375
          app/src/services/query.service.js on lines 377..383
          app/src/services/query.service.js on lines 453..459

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

          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 4 locations. Consider refactoring.
          Open

              static async createUserNodeAndRelation(idDataset, idWidget) {
                  logger.debug('Creating user and relation with id ', idWidget, '; id dataset', idDataset);
                  return QueryService.run(CREATE_WIDGET_AND_RELATION, {
                      idWidget,
                      idDataset
          Severity: Major
          Found in app/src/services/query.service.js and 3 other locations - About 35 mins to fix
          app/src/services/query.service.js on lines 369..375
          app/src/services/query.service.js on lines 392..398
          app/src/services/query.service.js on lines 453..459

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

          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 4 locations. Consider refactoring.
          Open

              static async querySearchByLabelSynonymons(search, application) {
                  logger.debug('Obtaining dataset by search ', search, 'and application ', application);
                  return QueryService.run(QUERY_SEARCH_BY_LABEL_SYNONYMONS, {
                      search,
                      application
          Severity: Major
          Found in app/src/services/query.service.js and 3 other locations - About 35 mins to fix
          app/src/services/query.service.js on lines 369..375
          app/src/services/query.service.js on lines 377..383
          app/src/services/query.service.js on lines 392..398

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

          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

              static async querySimilarDatasetsIncludingDescendent(datasets, application) {
                  logger.debug('Obtaining similar datasets including descendent of ', datasets);
                  return QueryService.run(QUERY_SIMILAR_DATASET_WITH_DESCENDENT, {
                      datasets,
                      application
          Severity: Minor
          Found in app/src/services/query.service.js and 2 other locations - About 30 mins to fix
          app/src/services/query.service.js on lines 422..428
          app/src/services/query.service.js on lines 445..451

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

          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

              static async querySimilarDatasets(datasets, application) {
                  logger.debug('Obtaining similar datasets of ', datasets);
                  return QueryService.run(QUERY_SIMILAR_DATASET, {
                      datasets,
                      application
          Severity: Minor
          Found in app/src/services/query.service.js and 2 other locations - About 30 mins to fix
          app/src/services/query.service.js on lines 430..436
          app/src/services/query.service.js on lines 445..451

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

          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

              static async queryMostViewedByUser(userId, application) {
                  logger.debug('Obtaining dataset most viewed by user ', userId);
                  return QueryService.run(QUERY_MOST_VIEWED_BY_USER, {
                      userId,
                      application
          Severity: Minor
          Found in app/src/services/query.service.js and 2 other locations - About 30 mins to fix
          app/src/services/query.service.js on lines 422..428
          app/src/services/query.service.js on lines 430..436

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

          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