api/src/data/modules/segments/queryBuilder.ts

Summary

Maintainability
F
1 wk
Test Coverage

File queryBuilder.ts has 701 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as _ from 'underscore';
import {
  Boards,
  Conformities,
  Pipelines,
Severity: Major
Found in api/src/data/modules/segments/queryBuilder.ts - About 1 day to fix

    Function generateQueryBySegment has a Cognitive Complexity of 80 (exceeds 5 allowed). Consider refactoring.
    Open

    export const generateQueryBySegment = async (args: {
      segment: ISegment;
      selector: any;
      options?: IOptions;
      isInitialCall?: boolean;
    Severity: Minor
    Found in api/src/data/modules/segments/queryBuilder.ts - About 1 day 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 generateQueryBySegment has 218 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export const generateQueryBySegment = async (args: {
      segment: ISegment;
      selector: any;
      options?: IOptions;
      isInitialCall?: boolean;
    Severity: Major
    Found in api/src/data/modules/segments/queryBuilder.ts - About 1 day to fix

      Function elkConvertConditionToQuery has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
      Open

      export function elkConvertConditionToQuery(args: {
        field: string;
        type?: any;
        operator: string;
        value: string;
      Severity: Minor
      Found in api/src/data/modules/segments/queryBuilder.ts - 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

      Function elkConvertConditionToQuery has 136 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function elkConvertConditionToQuery(args: {
        field: string;
        type?: any;
        operator: string;
        value: string;
      Severity: Major
      Found in api/src/data/modules/segments/queryBuilder.ts - About 5 hrs to fix

        Function fetchSegment has 116 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export const fetchSegment = async (
          segment,
          options: IOptions = {}
        ): Promise<any> => {
          const { contentType } = segment;
        Severity: Major
        Found in api/src/data/modules/segments/queryBuilder.ts - About 4 hrs to fix

          Function fetchSegment has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
          Open

          export const fetchSegment = async (
            segment,
            options: IOptions = {}
          ): Promise<any> => {
            const { contentType } = segment;
          Severity: Minor
          Found in api/src/data/modules/segments/queryBuilder.ts - About 4 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 generateNestedQuery has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export const generateNestedQuery = (
            kind: string,
            field: string,
            operator: string,
            query: any
          Severity: Minor
          Found in api/src/data/modules/segments/queryBuilder.ts - About 1 hr to fix

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

            const associationPropertyFilter = async ({
              mainType,
              propertyType,
              positiveQuery,
              negativeQuery
            Severity: Minor
            Found in api/src/data/modules/segments/queryBuilder.ts - 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

            Avoid too many return statements within this function.
            Open

              return response.hits.hits.map(hit => hit._id);
            Severity: Major
            Found in api/src/data/modules/segments/queryBuilder.ts - About 30 mins to fix

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

              export const getIndexByContentType = (contentType: string) => {
                let index = 'customers';
              
                if (contentType === 'company') {
                  index = 'companies';
              Severity: Minor
              Found in api/src/data/modules/segments/queryBuilder.ts - 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

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

              const generateConditionStageIds = async ({
                boardId,
                pipelineId,
                options
              }: {
              Severity: Minor
              Found in api/src/data/modules/segments/queryBuilder.ts - 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

                if (['dne', 'numberdne'].includes(operator)) {
                  if (['keyword', 'email'].includes(type) || operator === 'numberdne') {
                    negativeQuery = {
                      term: { [field]: value }
                    };
              Severity: Major
              Found in api/src/data/modules/segments/queryBuilder.ts and 1 other location - About 2 hrs to fix
              api/src/data/modules/segments/queryBuilder.ts on lines 535..545

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

              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 (['e', 'numbere'].includes(operator)) {
                  if (['keyword', 'email'].includes(type) || operator === 'numbere') {
                    positiveQuery = {
                      term: { [field]: value }
                    };
              Severity: Major
              Found in api/src/data/modules/segments/queryBuilder.ts and 1 other location - About 2 hrs to fix
              api/src/data/modules/segments/queryBuilder.ts on lines 548..558

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

              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 (['ilt', 'numberilt', 'dateilt'].includes(operator)) {
                  positiveQuery = {
                    range: {
                      [field]: {
                        lte: fixedValue
              Severity: Minor
              Found in api/src/data/modules/segments/queryBuilder.ts and 1 other location - About 40 mins to fix
              api/src/data/modules/segments/queryBuilder.ts on lines 579..587

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

              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 (['igt', 'numberigt', 'dateigt'].includes(operator)) {
                  positiveQuery = {
                    range: {
                      [field]: {
                        gte: fixedValue
              Severity: Minor
              Found in api/src/data/modules/segments/queryBuilder.ts and 1 other location - About 40 mins to fix
              api/src/data/modules/segments/queryBuilder.ts on lines 590..598

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

              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 (operator === 'wobm') {
                    gte = `now+${fixedValue}m/m`;
                    lte = `now+${fixedValue}m/m`;
                  }
              Severity: Minor
              Found in api/src/data/modules/segments/queryBuilder.ts and 2 other locations - About 35 mins to fix
              api/src/data/modules/segments/queryBuilder.ts on lines 641..644
              api/src/data/modules/segments/queryBuilder.ts on lines 653..656

              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

                  if (operator === 'woam') {
                    gte = `now-${fixedValue}m/m`;
                    lte = `now-${fixedValue}m/m`;
                  }
              Severity: Minor
              Found in api/src/data/modules/segments/queryBuilder.ts and 2 other locations - About 35 mins to fix
              api/src/data/modules/segments/queryBuilder.ts on lines 647..650
              api/src/data/modules/segments/queryBuilder.ts on lines 653..656

              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

                  if (operator === 'woad') {
                    gte = `now-${fixedValue}d/d`;
                    lte = `now-${fixedValue}d/d`;
                  }
              Severity: Minor
              Found in api/src/data/modules/segments/queryBuilder.ts and 2 other locations - About 35 mins to fix
              api/src/data/modules/segments/queryBuilder.ts on lines 641..644
              api/src/data/modules/segments/queryBuilder.ts on lines 647..650

              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

              const generateConditionStageIds = async ({
                boardId,
                pipelineId,
                options
              }: {
              Severity: Minor
              Found in api/src/data/modules/segments/queryBuilder.ts and 2 other locations - About 35 mins to fix
              integrations/src/nylas/handleController.ts on lines 352..376
              ui/src/modules/settings/integrations/components/chatfuel/Form.tsx on lines 42..62

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

              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