integrations/src/nylas/handleController.ts

Summary

Maintainability
D
3 days
Test Coverage

File handleController.ts has 563 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { debugError, debugNylas } from '../debuggers';
import { revokeToken } from '../gmail/api';
import memoryStorage from '../inmemoryStorage';
import { Accounts, Integrations } from '../models';
import { IAccount } from '../models/Accounts';
Severity: Major
Found in integrations/src/nylas/handleController.ts - About 1 day to fix

    Function nylasSendEmail has 49 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export const nylasSendEmail = async (erxesApiId: string, params: any) => {
      const integration = await Integrations.findOne({ erxesApiId }).lean();
    
      if (!integration) {
        throw new Error('Integration not found');
    Severity: Minor
    Found in integrations/src/nylas/handleController.ts - About 1 hr to fix

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

      export const nylasGetEvents = async ({
        calendarIds,
        startTime,
        endTime
      }: {
      Severity: Minor
      Found in integrations/src/nylas/handleController.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 nylasGetSchedulePages has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const nylasGetSchedulePages = async (accountId: string) => {
        try {
          const account = await Accounts.findOne({ _id: accountId });
      
          if (!account) {
      Severity: Minor
      Found in integrations/src/nylas/handleController.ts - About 1 hr to fix

        Function createNylasIntegration has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export const createNylasIntegration = async (
          kind: string,
          integrationId: string,
          data: INylasIntegrationData
        ) => {
        Severity: Minor
        Found in integrations/src/nylas/handleController.ts - About 1 hr to fix

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

          export const nylasUpdateEvent = async ({
            accountId,
            eventId,
            doc
          }: {
          Severity: Major
          Found in integrations/src/nylas/handleController.ts and 1 other location - About 4 hrs to fix
          integrations/src/nylas/handleController.ts on lines 378..402

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

          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 nylasSendEventAttendance = async ({
            erxesApiId,
            eventId,
            doc
          }: {
          Severity: Major
          Found in integrations/src/nylas/handleController.ts and 1 other location - About 4 hrs to fix
          integrations/src/nylas/handleController.ts on lines 352..376

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

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

              const {
                shouldResolve,
                to,
                cc,
                bcc,
          Severity: Major
          Found in integrations/src/nylas/handleController.ts and 5 other locations - About 55 mins to fix
          api/src/workers/utils.ts on lines 309..319
          integrations/src/facebook/store.ts on lines 51..61
          ui/src/modules/engage/components/step/SegmentStep.tsx on lines 31..41
          ui/src/modules/settings/productService/components/product/ProductRow.tsx on lines 34..44
          ui/src/modules/settings/properties/containers/Properties.tsx on lines 42..52

          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