api/src/data/resolvers/queries/boardUtils.ts

Summary

Maintainability
F
1 wk
Test Coverage

File boardUtils.ts has 664 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as moment from 'moment';
import {
  Companies,
  Conformities,
  Customers,
Severity: Major
Found in api/src/data/resolvers/queries/boardUtils.ts - About 1 day to fix

    Function getItemList has 195 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export const getItemList = async (
      filter: any,
      args: IListParams,
      user: IUserDocument,
      type: string,
    Severity: Major
    Found in api/src/data/resolvers/queries/boardUtils.ts - About 7 hrs to fix

      Function generateCommonFilters has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
      Open

      export const generateCommonFilters = async (
        currentUserId: string,
        args: any
      ) => {
        const {
      Severity: Minor
      Found in api/src/data/resolvers/queries/boardUtils.ts - About 6 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 generateCommonFilters has 141 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const generateCommonFilters = async (
        currentUserId: string,
        args: any
      ) => {
        const {
      Severity: Major
      Found in api/src/data/resolvers/queries/boardUtils.ts - About 5 hrs to fix

        Function getItemList has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

        export const getItemList = async (
          filter: any,
          args: IListParams,
          user: IUserDocument,
          type: string,
        Severity: Minor
        Found in api/src/data/resolvers/queries/boardUtils.ts - About 3 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 generateArhivedItemsFilter has 53 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const generateArhivedItemsFilter = (
          params: IArchiveArgs,
          stages: IStageDocument[]
        ) => {
          const {
        Severity: Major
        Found in api/src/data/resolvers/queries/boardUtils.ts - About 2 hrs to fix

          Function generateArhivedItemsFilter has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

          const generateArhivedItemsFilter = (
            params: IArchiveArgs,
            stages: IStageDocument[]
          ) => {
            const {
          Severity: Minor
          Found in api/src/data/resolvers/queries/boardUtils.ts - 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 getCloseDateByType has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export const getCloseDateByType = (closeDateType: string) => {
            if (closeDateType === CLOSE_DATE_TYPES.NEXT_DAY) {
              const tommorrow = moment().add(1, 'days');
          
              return {
          Severity: Minor
          Found in api/src/data/resolvers/queries/boardUtils.ts - About 1 hr to fix

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

            export const generateExtraFilters = async (filter, extraParams) => {
              const { source, userIds, priority, startDate, endDate } = extraParams;
            
              const isListEmpty = value => {
                return value.length === 1 && value[0].length === 0;
            Severity: Minor
            Found in api/src/data/resolvers/queries/boardUtils.ts - 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 generateExtraFilters has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export const generateExtraFilters = async (filter, extraParams) => {
              const { source, userIds, priority, startDate, endDate } = extraParams;
            
              const isListEmpty = value => {
                return value.length === 1 && value[0].length === 0;
            Severity: Minor
            Found in api/src/data/resolvers/queries/boardUtils.ts - About 1 hr to fix

              Consider simplifying this complex logical expression.
              Open

                if (
                  pipeline.isCheckUser &&
                  !(pipeline.excludeCheckUserIds || []).includes(currentUserId) &&
                  !(
                    (item.assignedUserIds || []).includes(currentUserId) ||
              Severity: Major
              Found in api/src/data/resolvers/queries/boardUtils.ts - About 40 mins to fix

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

                export const checkItemPermByUser = async (
                  currentUserId: string,
                  item: IItemCommonFields
                ) => {
                  const stage = await Stages.getStage(item.stageId);
                Severity: Minor
                Found in api/src/data/resolvers/queries/boardUtils.ts - 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

                Avoid too many return statements within this function.
                Open

                    return { $lt: today };
                Severity: Major
                Found in api/src/data/resolvers/queries/boardUtils.ts - About 30 mins to fix

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

                  export const generateTaskCommonFilters = async (
                    currentUserId: string,
                    args: any,
                    extraParams?: any
                  ) => {
                  Severity: Major
                  Found in api/src/data/resolvers/queries/boardUtils.ts and 1 other location - About 2 hrs to fix
                  api/src/data/resolvers/queries/boardUtils.ts on lines 349..366

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

                  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

                  export const generateTicketCommonFilters = async (
                    currentUserId: string,
                    args: any,
                    extraParams?: any
                  ) => {
                  Severity: Major
                  Found in api/src/data/resolvers/queries/boardUtils.ts and 1 other location - About 2 hrs to fix
                  api/src/data/resolvers/queries/boardUtils.ts on lines 368..385

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

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

                    if (endDate) {
                      if (filter.closeDate) {
                        filter.closeDate.$lte = new Date(endDate);
                      } else {
                        filter.closeDate = {
                  Severity: Major
                  Found in api/src/data/resolvers/queries/boardUtils.ts and 2 other locations - About 1 hr to fix
                  api/src/data/resolvers/queries/boardUtils.ts on lines 119..127
                  api/src/data/resolvers/queries/boardUtils.ts on lines 567..575

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

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

                    if (endDate) {
                      if (filter.closeDate) {
                        filter.closeDate.$lte = new Date(endDate);
                      } else {
                        filter.closeDate = {
                  Severity: Major
                  Found in api/src/data/resolvers/queries/boardUtils.ts and 2 other locations - About 1 hr to fix
                  api/src/data/resolvers/queries/boardUtils.ts on lines 237..245
                  api/src/data/resolvers/queries/boardUtils.ts on lines 567..575

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

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

                    if (endDate) {
                      if (filter.closeDate) {
                        filter.closeDate.$lte = new Date(endDate);
                      } else {
                        filter.closeDate = {
                  Severity: Major
                  Found in api/src/data/resolvers/queries/boardUtils.ts and 2 other locations - About 1 hr to fix
                  api/src/data/resolvers/queries/boardUtils.ts on lines 119..127
                  api/src/data/resolvers/queries/boardUtils.ts on lines 237..245

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

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

                    const {
                      search,
                      userIds,
                      priorities,
                      assignedUserIds,
                  Severity: Major
                  Found in api/src/data/resolvers/queries/boardUtils.ts and 6 other locations - About 1 hr to fix
                  api/src/data/resolvers/mutations/widgets.ts on lines 354..366
                  api/src/data/resolvers/queries/users.ts on lines 31..42
                  integrations/src/gmail/utils.ts on lines 153..164
                  ui/src/modules/boards/components/editForm/Left.tsx on lines 158..169
                  ui/src/modules/engage/containers/MessageListRow.tsx on lines 38..49
                  widgets/client/form/containers/App.tsx on lines 128..139

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

                  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 (userIds) {
                      const isEmpty = isListEmpty(userIds);
                  
                      filter.userId = isEmpty ? { $in: [null, []] } : { $in: userIds };
                    }
                  Severity: Major
                  Found in api/src/data/resolvers/queries/boardUtils.ts and 2 other locations - About 50 mins to fix
                  api/src/data/resolvers/queries/boardUtils.ts on lines 262..266
                  api/src/data/resolvers/queries/boardUtils.ts on lines 287..291

                  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 (userIds) {
                      const isEmpty = isListEmpty(userIds);
                  
                      filter.userId = isEmpty ? { $in: [null, []] } : { $in: userIds };
                    }
                  Severity: Major
                  Found in api/src/data/resolvers/queries/boardUtils.ts and 2 other locations - About 50 mins to fix
                  api/src/data/resolvers/queries/boardUtils.ts on lines 103..107
                  api/src/data/resolvers/queries/boardUtils.ts on lines 262..266

                  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 (labelIds) {
                      const isEmpty = isListEmpty(labelIds);
                  
                      filter.labelIds = isEmpty ? { $in: [null, []] } : { $in: labelIds };
                    }
                  Severity: Major
                  Found in api/src/data/resolvers/queries/boardUtils.ts and 2 other locations - About 50 mins to fix
                  api/src/data/resolvers/queries/boardUtils.ts on lines 103..107
                  api/src/data/resolvers/queries/boardUtils.ts on lines 287..291

                  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

                  There are no issues that match your filters.

                  Category
                  Status