api/src/db/models/Customers.ts

Summary

Maintainability
F
1 wk
Test Coverage

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

export const loadClass = () => {
  class Customer {
    /**
     * Checking if customer has duplicated unique properties
     */
Severity: Minor
Found in api/src/db/models/Customers.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 537 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const loadClass = () => {
  class Customer {
    /**
     * Checking if customer has duplicated unique properties
     */
Severity: Major
Found in api/src/db/models/Customers.ts - About 2 days to fix

    File Customers.ts has 672 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import { Model, model } from 'mongoose';
    import { ACTIVITY_LOG_ACTIONS, putActivityLog } from '../../data/logUtils';
    import { sendToWebhook, validSearchText } from '../../data/utils';
    import { validateSingle } from '../../data/verifierUtils';
    import {
    Severity: Major
    Found in api/src/db/models/Customers.ts - About 1 day to fix

      Function mergeCustomers has 61 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static async mergeCustomers(
            customerIds: string[],
            customerFields: ICustomer,
            user?: IUserDocument
          ) {
      Severity: Major
      Found in api/src/db/models/Customers.ts - About 2 hrs to fix

        Function calcPSS has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static async calcPSS(customer: any) {
              const nullValues = ['', null];
        
              let possibleLead = false;
              let score = 0;
        Severity: Minor
        Found in api/src/db/models/Customers.ts - About 1 hr to fix

          Function createCustomer has 44 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static async createCustomer(
                doc: ICustomer,
                user?: IUserDocument
              ): Promise<ICustomerDocument> {
                // Checking duplicated fields of customer
          Severity: Minor
          Found in api/src/db/models/Customers.ts - About 1 hr to fix

            Function fixListFields has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static fixListFields(
                  doc: any,
                  customData = {},
                  customer?: ICustomerDocument
                ) {
            Severity: Minor
            Found in api/src/db/models/Customers.ts - About 1 hr to fix

              Function checkDuplication has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static async checkDuplication(
                    customerFields: ICustomerFieldsInput,
                    idsToExclude?: string[] | string
                  ) {
                    const query: { status: {}; [key: string]: any } = {
              Severity: Minor
              Found in api/src/db/models/Customers.ts - About 1 hr to fix

                Function updateCustomer has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static async updateCustomer(_id: string, doc: ICustomer) {
                      // Checking duplicated fields of customer
                      try {
                        await Customers.checkDuplication(doc, _id);
                      } catch (e) {
                Severity: Minor
                Found in api/src/db/models/Customers.ts - About 1 hr to fix

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

                      public static async saveVisitorContactInfo(
                        args: IVisitorContactInfoParams
                      ) {
                        const { customerId, type, value } = args;
                  
                  
                  Severity: Minor
                  Found in api/src/db/models/Customers.ts - About 1 hr to fix

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

                        public static async getWidgetCustomer({
                          integrationId,
                          email,
                          phone,
                          code,
                    Severity: Minor
                    Found in api/src/db/models/Customers.ts - About 1 hr to fix

                      Consider simplifying this complex logical expression.
                      Open

                              if (customerObj) {
                                // get last customer's integrationId
                                customerFields.integrationId = customerObj.integrationId;
                      
                                // merge custom fields data
                      Severity: Major
                      Found in api/src/db/models/Customers.ts - About 40 mins to fix

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

                            public static customerFieldNames() {
                              const names: string[] = [];
                        
                              customerSchema.eachPath(name => {
                                names.push(name);
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 1 other location - About 4 hrs to fix
                        api/src/db/models/Companies.ts on lines 117..133

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

                        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

                            public static async updateLocation(_id: string, browserInfo: IBrowserInfo) {
                              await Customers.findByIdAndUpdate(
                                { _id },
                                {
                                  $set: { location: browserInfo }
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 1 other location - About 1 hr to fix
                        api/src/db/models/Integrations.ts on lines 318..324

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

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

                              if (doc.email) {
                                if (!emails.includes(doc.email)) {
                                  emails.push(doc.email);
                                }
                        
                        
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 3 other locations - About 1 hr to fix
                        api/src/db/models/Companies.ts on lines 159..167
                        api/src/db/models/Companies.ts on lines 169..177
                        api/src/db/models/Customers.ts on lines 684..692

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

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

                              if (doc.phone) {
                                if (!phones.includes(doc.phone)) {
                                  phones.push(doc.phone);
                                }
                        
                        
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 3 other locations - About 1 hr to fix
                        api/src/db/models/Companies.ts on lines 159..167
                        api/src/db/models/Companies.ts on lines 169..177
                        api/src/db/models/Customers.ts on lines 674..682

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

                        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 (type === 'phone') {
                                await Customers.updateOne(
                                  { _id: customerId },
                                  {
                                    $set: { 'visitorContactInfo.phone': value },
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 1 other location - About 1 hr to fix
                        api/src/db/models/Customers.ts on lines 845..855

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

                        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 (type === 'email') {
                                await Customers.updateOne(
                                  { _id: customerId },
                                  {
                                    $set: { 'visitorContactInfo.email': value },
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 1 other location - About 1 hr to fix
                        api/src/db/models/Customers.ts on lines 857..867

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

                        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 (
                                customer.lastSeenAt &&
                                now.getTime() - customer.lastSeenAt.getTime() > 6 * 1000
                              ) {
                                // update session count
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 1 other location - About 1 hr to fix
                        logger/src/models/Visitors.ts on lines 140..146

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

                        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

                            public static async markCustomerAsActive(customerId: string) {
                              await Customers.updateOne(
                                { _id: customerId },
                                { $set: { isOnline: true } }
                              );
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 1 other location - About 1 hr to fix
                        api/src/db/models/Engages.ts on lines 145..149

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

                              if (customerFields.primaryPhone) {
                                // check duplication from primaryPhone
                                previousEntry = await Customers.find({
                                  ...query,
                                  primaryPhone: customerFields.primaryPhone
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 4 other locations - About 1 hr to fix
                        api/src/db/models/Companies.ts on lines 70..80
                        api/src/db/models/Companies.ts on lines 82..92
                        api/src/db/models/Customers.ts on lines 161..171
                        api/src/db/models/Customers.ts on lines 185..195

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

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

                              if (customerFields.code) {
                                // check duplication from code
                                previousEntry = await Customers.find({
                                  ...query,
                                  code: customerFields.code
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 4 other locations - About 1 hr to fix
                        api/src/db/models/Companies.ts on lines 70..80
                        api/src/db/models/Companies.ts on lines 82..92
                        api/src/db/models/Customers.ts on lines 161..171
                        api/src/db/models/Customers.ts on lines 173..183

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

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

                              if (customerFields.primaryEmail) {
                                // check duplication from primaryEmail
                                previousEntry = await Customers.find({
                                  ...query,
                                  primaryEmail: customerFields.primaryEmail
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 4 other locations - About 1 hr to fix
                        api/src/db/models/Companies.ts on lines 70..80
                        api/src/db/models/Companies.ts on lines 82..92
                        api/src/db/models/Customers.ts on lines 173..183
                        api/src/db/models/Customers.ts on lines 185..195

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

                        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 (!nullValues.includes(customer.firstName || '')) {
                                score += 10;
                                possibleLead = true;
                                searchText = searchText.concat(' ', customer.firstName || '');
                              }
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 2 other locations - About 1 hr to fix
                        api/src/db/models/Customers.ts on lines 417..421
                        api/src/db/models/Customers.ts on lines 423..427

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

                        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 (!nullValues.includes(customer.lastName || '')) {
                                score += 5;
                                possibleLead = true;
                                searchText = searchText.concat(' ', customer.lastName || '');
                              }
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 2 other locations - About 1 hr to fix
                        api/src/db/models/Customers.ts on lines 411..415
                        api/src/db/models/Customers.ts on lines 423..427

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

                        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 (!nullValues.includes(customer.code || '')) {
                                score += 10;
                                possibleLead = true;
                                searchText = searchText.concat(' ', customer.code || '');
                              }
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 2 other locations - About 1 hr to fix
                        api/src/db/models/Customers.ts on lines 411..415
                        api/src/db/models/Customers.ts on lines 417..421

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

                        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 (
                                (doc.primaryPhone && !doc.phoneValidationStatus) ||
                                (doc.primaryPhone && doc.phoneValidationStatus === 'unknown')
                              ) {
                                validateSingle({ phone: doc.primaryPhone });
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 1 other location - About 1 hr to fix
                        api/src/db/models/Customers.ts on lines 298..303

                        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

                              if (
                                (doc.primaryEmail && !doc.emailValidationStatus) ||
                                (doc.primaryEmail && doc.emailValidationStatus === 'unknown')
                              ) {
                                validateSingle({ email: doc.primaryEmail });
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 1 other location - About 1 hr to fix
                        api/src/db/models/Customers.ts on lines 305..310

                        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

                              if (doc.primaryEmail) {
                                if (doc.primaryEmail !== oldCustomer.primaryEmail) {
                                  doc.emailValidationStatus = 'unknown';
                        
                                  validateSingle({ email: doc.primaryEmail });
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 1 other location - About 1 hr to fix
                        api/src/db/models/Customers.ts on lines 348..354

                        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

                              if (doc.primaryPhone) {
                                if (doc.primaryPhone !== oldCustomer.primaryPhone) {
                                  doc.phoneValidationStatus = 'unknown';
                        
                                  validateSingle({ phone: doc.primaryPhone });
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 1 other location - About 1 hr to fix
                        api/src/db/models/Customers.ts on lines 340..346

                        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

                              if (doc.deviceToken) {
                                if (!deviceTokens.includes(doc.deviceToken)) {
                                  deviceTokens.push(doc.deviceToken);
                                }
                        
                        
                        Severity: Major
                        Found in api/src/db/models/Customers.ts and 1 other location - About 1 hr to fix
                        api/src/db/models/Companies.ts on lines 179..185

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

                        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 (email) {
                                customer = await Customers.findOne({
                                  $or: [{ emails: { $in: [email] } }, { primaryEmail: email }]
                                });
                              }
                        Severity: Minor
                        Found in api/src/db/models/Customers.ts and 1 other location - About 45 mins to fix
                        api/src/db/models/Customers.ts on lines 602..606

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

                        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 (!customer && phone) {
                                customer = await Customers.findOne({
                                  $or: [{ phones: { $in: [phone] } }, { primaryPhone: phone }]
                                });
                              }
                        Severity: Minor
                        Found in api/src/db/models/Customers.ts and 1 other location - About 45 mins to fix
                        api/src/db/models/Customers.ts on lines 596..600

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

                        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