api/src/data/resolvers/mutations/widgets.ts

Summary

Maintainability
F
1 wk
Test Coverage

File widgets.ts has 862 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import * as strip from 'strip';
import {
  Companies,
  Conformities,
  ConversationMessages,
Severity: Major
Found in api/src/data/resolvers/mutations/widgets.ts - About 2 days to fix

    Function widgetsInsertMessage has 192 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async widgetsInsertMessage(
        _root,
        args: {
          integrationId: string;
          customerId?: string;
    Severity: Major
    Found in api/src/data/resolvers/mutations/widgets.ts - About 7 hrs to fix

      Function widgetsInsertMessage has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
      Open

        async widgetsInsertMessage(
          _root,
          args: {
            integrationId: string;
            customerId?: string;
      Severity: Minor
      Found in api/src/data/resolvers/mutations/widgets.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 widgetsMessengerConnect has 99 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async widgetsMessengerConnect(
          _root,
          args: {
            brandCode: string;
            email?: string;
      Severity: Major
      Found in api/src/data/resolvers/mutations/widgets.ts - About 3 hrs to fix

        Function widgetBotRequest has 74 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          async widgetBotRequest(
            _root,
            {
              integrationId,
              conversationId,
        Severity: Major
        Found in api/src/data/resolvers/mutations/widgets.ts - About 2 hrs to fix

          Function createFormConversation has 67 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const createFormConversation = async (
            args: {
              integrationId: string;
              formId: string;
              submissions: ISubmission[];
          Severity: Major
          Found in api/src/data/resolvers/mutations/widgets.ts - About 2 hrs to fix

            Function widgetsMessengerConnect has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
            Open

              async widgetsMessengerConnect(
                _root,
                args: {
                  brandCode: string;
                  email?: string;
            Severity: Minor
            Found in api/src/data/resolvers/mutations/widgets.ts - 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 getMessengerData has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

            export const getMessengerData = async (integration: IIntegrationDocument) => {
              let messagesByLanguage: IMessengerDataMessagesItem | null = null;
              let messengerData = integration.messengerData;
            
              if (messengerData) {
            Severity: Minor
            Found in api/src/data/resolvers/mutations/widgets.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 getMessengerData has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export const getMessengerData = async (integration: IIntegrationDocument) => {
              let messagesByLanguage: IMessengerDataMessagesItem | null = null;
              let messengerData = integration.messengerData;
            
              if (messengerData) {
            Severity: Minor
            Found in api/src/data/resolvers/mutations/widgets.ts - About 1 hr to fix

              Function widgetsSendEmail has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                async widgetsSendEmail(_root, args: IWidgetEmailParams) {
                  const { toEmails, fromEmail, title, content, customerId, formId } = args;
              
                  const attachments = args.attachments || [];
              
              
              Severity: Minor
              Found in api/src/data/resolvers/mutations/widgets.ts - About 1 hr to fix

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

                  async widgetsLeadConnect(
                    _root,
                    args: { brandCode: string; formCode: string; cachedCustomerId?: string }
                  ) {
                    const brand = await getDocument('brands', { code: args.brandCode });
                Severity: Minor
                Found in api/src/data/resolvers/mutations/widgets.ts - About 1 hr to fix

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

                  const createFormConversation = async (
                    args: {
                      integrationId: string;
                      formId: string;
                      submissions: ISubmission[];
                  Severity: Minor
                  Found in api/src/data/resolvers/mutations/widgets.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

                  Function widgetsLeadConnect has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                    async widgetsLeadConnect(
                      _root,
                      args: { brandCode: string; formCode: string; cachedCustomerId?: string }
                    ) {
                      const brand = await getDocument('brands', { code: args.brandCode });
                  Severity: Minor
                  Found in api/src/data/resolvers/mutations/widgets.ts - 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

                  Function widgetBotRequest has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                    async widgetBotRequest(
                      _root,
                      {
                        integrationId,
                        conversationId,
                  Severity: Minor
                  Found in api/src/data/resolvers/mutations/widgets.ts - 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

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

                      {
                        integrationId,
                        conversationId,
                        customerId,
                        visitorId,
                  Severity: Major
                  Found in api/src/data/resolvers/mutations/widgets.ts and 1 other location - About 2 hrs to fix
                  integrations/src/nylas/auth.ts on lines 341..357

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

                  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

                      if (attachments.length > 0) {
                        mailAttachment = attachments.map(file => {
                          return {
                            filename: file.name || '',
                            path: file.url || ''
                  Severity: Major
                  Found in api/src/data/resolvers/mutations/widgets.ts and 1 other location - About 1 hr to fix
                  engages-email-sender/src/sender.ts on lines 53..60

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

                  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 {
                        brandCode,
                        email,
                        phone,
                        code,
                  Severity: Major
                  Found in api/src/data/resolvers/mutations/widgets.ts and 6 other locations - About 1 hr to fix
                  api/src/data/resolvers/queries/boardUtils.ts on lines 520..531
                  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 2 locations. Consider refactoring.
                  Open

                    async widgetsSaveLead(
                      _root,
                      args: {
                        integrationId: string;
                        formId: string;
                  Severity: Minor
                  Found in api/src/data/resolvers/mutations/widgets.ts and 1 other location - About 55 mins to fix
                  api/src/data/resolvers/mutations/widgets.ts on lines 1040..1076

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

                  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

                    async widgetsSaveBooking(
                      _root,
                      args: {
                        integrationId: string;
                        formId: string;
                  Severity: Minor
                  Found in api/src/data/resolvers/mutations/widgets.ts and 1 other location - About 55 mins to fix
                  api/src/data/resolvers/mutations/widgets.ts on lines 280..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 54.

                  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

                    widgetsKnowledgebaseIncReactionCount(
                      _root,
                      { articleId, reactionChoice }: { articleId: string; reactionChoice: string }
                    ) {
                      return KnowledgeBaseArticles.modifyReactionCount(
                  Severity: Minor
                  Found in api/src/data/resolvers/mutations/widgets.ts and 1 other location - About 55 mins to fix
                  api/src/data/resolvers/mutations/widgets.ts on lines 324..333

                  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

                    widgetsKnowledgebaseDecReactionCount(
                      _root,
                      { articleId, reactionChoice }: { articleId: string; reactionChoice: string }
                    ) {
                      return KnowledgeBaseArticles.modifyReactionCount(
                  Severity: Minor
                  Found in api/src/data/resolvers/mutations/widgets.ts and 1 other location - About 55 mins to fix
                  api/src/data/resolvers/mutations/widgets.ts on lines 313..322

                  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

                    async widgetsSaveBrowserInfo(
                      _root,
                      {
                        visitorId,
                        customerId,
                  Severity: Minor
                  Found in api/src/data/resolvers/mutations/widgets.ts and 1 other location - About 35 mins to fix
                  api/src/data/resolvers/queries/engages.ts on lines 97..129

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

                        const conversation = await Conversations.createConversation({
                          customerId,
                          integrationId,
                          operatorStatus: CONVERSATION_OPERATOR_STATUS.BOT,
                          status: CONVERSATION_STATUSES.CLOSED
                  Severity: Minor
                  Found in api/src/data/resolvers/mutations/widgets.ts and 1 other location - About 35 mins to fix
                  api/src/__tests__/pipelineLabelDb.test.ts on lines 68..73

                  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

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

                    args: {
                      integrationId: string;
                      formId: string;
                      submissions: ISubmission[];
                      browserInfo: any;
                  Severity: Minor
                  Found in api/src/data/resolvers/mutations/widgets.ts and 1 other location - About 30 mins to fix
                  api/src/data/widgetUtils.ts on lines 343..349

                  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