api/src/db/models/Engages.ts

Summary

Maintainability
F
1 wk
Test Coverage

Function loadClass has a Cognitive Complexity of 108 (exceeds 5 allowed). Consider refactoring.
Open

export const loadClass = () => {
  class Message {
    /**
     * Get engage message
     */
Severity: Minor
Found in api/src/db/models/Engages.ts - About 2 days 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 loadClass has 373 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const loadClass = () => {
  class Message {
    /**
     * Get engage message
     */
Severity: Major
Found in api/src/db/models/Engages.ts - About 1 day to fix

    File Engages.ts has 461 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { Model, model } from 'mongoose';
    import { ConversationMessages, Conversations } from '.';
    import { MESSAGE_KINDS } from '../../data/constants';
    import {
      checkCustomerExists,
    Severity: Minor
    Found in api/src/db/models/Engages.ts - About 7 hrs to fix

      Function createVisitorOrCustomerMessages has 120 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static async createVisitorOrCustomerMessages(params: {
            brandId: string;
            integrationId: string;
            customer?: ICustomerDocument;
            visitorId?: string;
      Severity: Major
      Found in api/src/db/models/Engages.ts - About 4 hrs to fix

        Function createOrUpdateConversationAndMessages has 72 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static async createOrUpdateConversationAndMessages(args: {
              customerId?: string;
              visitorId?: string;
              integrationId: string;
              user: IUserDocument;
        Severity: Major
        Found in api/src/db/models/Engages.ts - About 2 hrs to fix

          Function checkRule has 66 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static checkRule(params: ICheckRuleParams) {
                const { rule, browserInfo, numberOfVisits } = params;
                const { language, url, city, countryCode } = browserInfo;
                const { value, kind, condition } = rule;
                const ruleValue: any = value;
          Severity: Major
          Found in api/src/db/models/Engages.ts - About 2 hrs to fix

            Avoid too many return statements within this function.
            Open

                    return false;
            Severity: Major
            Found in api/src/db/models/Engages.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return false;
              Severity: Major
              Found in api/src/db/models/Engages.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return false;
                Severity: Major
                Found in api/src/db/models/Engages.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return false;
                  Severity: Major
                  Found in api/src/db/models/Engages.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return false;
                    Severity: Major
                    Found in api/src/db/models/Engages.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            return true;
                      Severity: Major
                      Found in api/src/db/models/Engages.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return false;
                        Severity: Major
                        Found in api/src/db/models/Engages.ts - About 30 mins to fix

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

                              public static async engageMessageSetPause(_id: string) {
                                await EngageMessages.updateOne({ _id }, { $set: { isLive: false } });
                          
                                return EngageMessages.findOne({ _id });
                              }
                          Severity: Major
                          Found in api/src/db/models/Engages.ts and 1 other location - About 1 hr to fix
                          api/src/db/models/Customers.ts on lines 372..379

                          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

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

                            createOrUpdateConversationAndMessages(args: {
                              customerId?: string;
                              visitorId?: string;
                              integrationId: string;
                              user: IUserDocument;
                          Severity: Minor
                          Found in api/src/db/models/Engages.ts and 1 other location - About 50 mins to fix
                          api/src/db/models/Engages.ts on lines 392..399

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

                          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

                              public static async createOrUpdateConversationAndMessages(args: {
                                customerId?: string;
                                visitorId?: string;
                                integrationId: string;
                                user: IUserDocument;
                          Severity: Minor
                          Found in api/src/db/models/Engages.ts and 1 other location - About 50 mins to fix
                          api/src/db/models/Engages.ts on lines 74..81

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

                          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