api/src/db/models/Fields.ts

Summary

Maintainability
F
1 wk
Test Coverage

Function loadFieldClass has a Cognitive Complexity of 105 (exceeds 5 allowed). Consider refactoring.
Open

export const loadFieldClass = () => {
  class Field {
    static async checkCodeDuplication(code: string) {
      const group = await Fields.findOne({
        code
Severity: Minor
Found in api/src/db/models/Fields.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 loadFieldClass has 345 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const loadFieldClass = () => {
  class Field {
    static async checkCodeDuplication(code: string) {
      const group = await Fields.findOne({
        code
Severity: Major
Found in api/src/db/models/Fields.ts - About 1 day to fix

    File Fields.ts has 564 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /*
     * Extra fields for form, customer, company
     */
    import { Model, model } from 'mongoose';
    import * as validator from 'validator';
    Severity: Major
    Found in api/src/db/models/Fields.ts - About 1 day to fix

      Function loadGroupClass has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
      Open

      export const loadGroupClass = () => {
        class FieldGroup {
          static async checkCodeDuplication(code: string) {
            const group = await FieldsGroups.findOne({
              code
      Severity: Minor
      Found in api/src/db/models/Fields.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 loadGroupClass has 109 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const loadGroupClass = () => {
        class FieldGroup {
          static async checkCodeDuplication(code: string) {
            const group = await FieldsGroups.findOne({
              code
      Severity: Major
      Found in api/src/db/models/Fields.ts - About 4 hrs to fix

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

            public static async createSystemFields(
              groupId: string,
              contentType: string
            ) {
              switch (contentType) {
        Severity: Major
        Found in api/src/db/models/Fields.ts - About 2 hrs to fix

          Function createField has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static async createField({
                contentType,
                contentTypeId,
                groupId,
                groupName,
          Severity: Minor
          Found in api/src/db/models/Fields.ts - About 1 hr to fix

            Function generateTypedItem has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static generateTypedItem(
                  field: string,
                  value: string | number | string[] | number[] | ICoordinates,
                  type: string,
                  validation?: string
            Severity: Minor
            Found in api/src/db/models/Fields.ts - About 1 hr to fix

              Function clean has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static async clean(_id: string, _value: string | Date | number) {
                    const field = await Fields.findOne({ _id });
              
                    let value = _value;
              
              
              Severity: Minor
              Found in api/src/db/models/Fields.ts - About 1 hr to fix

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

                    public static async createSystemGroupsFields() {
                      for (const group of PROPERTY_GROUPS) {
                        if (['ticket', 'task', 'lead', 'visitor'].includes(group.value)) {
                          continue;
                        }
                Severity: Minor
                Found in api/src/db/models/Fields.ts - About 1 hr to fix

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

                          case FIELDS_GROUPS_CONTENT_TYPES.CUSTOMER:
                            const customerFields = CUSTOMER_BASIC_INFO.ALL.map(e => ({
                              text: e.label,
                              type: e.field,
                              canHide: e.canHide,
                  Severity: Major
                  Found in api/src/db/models/Fields.ts and 1 other location - About 3 hrs to fix
                  api/src/db/models/Fields.ts on lines 460..471

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

                  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

                          case FIELDS_GROUPS_CONTENT_TYPES.COMPANY:
                            const companyFields = COMPANY_INFO.ALL.map(e => ({
                              text: e.label,
                              type: e.field,
                              canHide: e.canHide,
                  Severity: Major
                  Found in api/src/db/models/Fields.ts and 1 other location - About 3 hrs to fix
                  api/src/db/models/Fields.ts on lines 448..459

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

                  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

                          case FIELDS_GROUPS_CONTENT_TYPES.CONVERSATION:
                            const conversationFields = CONVERSATION_INFO.ALL.map(e => ({
                              text: e.label,
                              type: e.field,
                              groupId,
                  Severity: Major
                  Found in api/src/db/models/Fields.ts and 2 other locations - About 2 hrs to fix
                  api/src/db/models/Fields.ts on lines 493..502
                  api/src/db/models/Fields.ts on lines 503..512

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

                  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

                          case FIELDS_GROUPS_CONTENT_TYPES.DEVICE:
                            const deviceFields = DEVICE_PROPERTIES_INFO.ALL.map(e => ({
                              text: e.label,
                              type: e.field,
                              groupId,
                  Severity: Major
                  Found in api/src/db/models/Fields.ts and 2 other locations - About 2 hrs to fix
                  api/src/db/models/Fields.ts on lines 483..492
                  api/src/db/models/Fields.ts on lines 503..512

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

                  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

                          case FIELDS_GROUPS_CONTENT_TYPES.USER:
                            const userFields = USER_PROPERTIES_INFO.ALL.map(e => ({
                              text: e.label,
                              type: e.field,
                              groupId,
                  Severity: Major
                  Found in api/src/db/models/Fields.ts and 2 other locations - About 2 hrs to fix
                  api/src/db/models/Fields.ts on lines 483..492
                  api/src/db/models/Fields.ts on lines 493..502

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

                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                  Refactorings

                  Further Reading

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

                  export interface ITypedListItem {
                    field: string;
                    value: any;
                    stringValue?: string;
                    numberValue?: number;
                  Severity: Major
                  Found in api/src/db/models/Fields.ts and 1 other location - About 1 hr to fix
                  api/src/db/models/definitions/common.ts on lines 43..50

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

                  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 checkIsDefinedByErxes(_id: string) {
                        const groupObj = await FieldsGroups.findOne({ _id });
                  
                        // Checking if the group is defined by the erxes
                        if (groupObj && groupObj.isDefinedByErxes) {
                  Severity: Minor
                  Found in api/src/db/models/Fields.ts and 1 other location - About 55 mins to fix
                  api/src/db/models/Fields.ts on lines 108..115

                  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

                      public static async checkIsDefinedByErxes(_id: string) {
                        const fieldObj = await Fields.findOne({ _id });
                  
                        // Checking if the field is defined by the erxes
                        if (fieldObj && fieldObj.isDefinedByErxes) {
                  Severity: Minor
                  Found in api/src/db/models/Fields.ts and 1 other location - About 55 mins to fix
                  api/src/db/models/Fields.ts on lines 589..596

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

                      static async checkCodeDuplication(code: string) {
                        const group = await Fields.findOne({
                          code
                        });
                  
                  
                  Severity: Major
                  Found in api/src/db/models/Fields.ts and 2 other locations - About 50 mins to fix
                  api/src/db/models/Fields.ts on lines 577..585
                  api/src/db/models/Products.ts on lines 270..278

                  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

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

                      static async checkCodeDuplication(code: string) {
                        const group = await FieldsGroups.findOne({
                          code
                        });
                  
                  
                  Severity: Major
                  Found in api/src/db/models/Fields.ts and 2 other locations - About 50 mins to fix
                  api/src/db/models/Fields.ts on lines 96..104
                  api/src/db/models/Products.ts on lines 270..278

                  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