teableio/teable

View on GitHub
apps/nestjs-backend/src/features/calculation/link.service.ts

Summary

Maintainability
F
4 days
Test Coverage

File link.service.ts has 993 lines of code (exceeds 300 allowed). Consider refactoring.
Open

import { BadRequestException, Injectable } from '@nestjs/common';
import type { ILinkCellValue, ILinkFieldOptions } from '@teable/core';
import { FieldType, Relationship } from '@teable/core';
import type { Field } from '@teable/db-main-prisma';
import { PrismaService } from '@teable/db-main-prisma';
Severity: Major
Found in apps/nestjs-backend/src/features/calculation/link.service.ts - About 2 days to fix

    LinkService has 31 functions (exceeds 20 allowed). Consider refactoring.
    Open

    @Injectable()
    export class LinkService {
      constructor(
        private readonly prismaService: PrismaService,
        private readonly batchService: BatchService,
    Severity: Minor
    Found in apps/nestjs-backend/src/features/calculation/link.service.ts - About 3 hrs to fix

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

        private async updateLinkRecord(
          tableId: string,
          fkRecordMap: IFkRecordMap,
          fieldMapByTableId: { [tableId: string]: IFieldMap },
          originRecordMapByTableId: IRecordMapByTableId
      Severity: Minor
      Found in apps/nestjs-backend/src/features/calculation/link.service.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 diffLinkCellChange has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        private diffLinkCellChange(
          fieldMapByTableId: { [tableId: string]: IFieldMap },
          originRecordMapByTableId: IRecordMapByTableId,
          updatedRecordMapByTableId: IRecordMapByTableId
        ): ICellChange[] {
      Severity: Minor
      Found in apps/nestjs-backend/src/features/calculation/link.service.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 updateForeignCellForManyOne has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        private updateForeignCellForManyOne(params: {
          fkItem: IFkRecordItem;
          recordId: string;
          symmetricFieldId: string;
          sourceLookedFieldId: string;
      Severity: Minor
      Found in apps/nestjs-backend/src/features/calculation/link.service.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 saveForeignKeyForOneOne has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        private async saveForeignKeyForOneOne(
          field: LinkFieldDto,
          fkMap: { [recordId: string]: IFkRecordItem }
        ) {
          const { selfKeyName, foreignKeyName, fkHostTableName } = field.options;
      Severity: Minor
      Found in apps/nestjs-backend/src/features/calculation/link.service.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 saveForeignKeyToDb has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        private async saveForeignKeyToDb(fieldMap: IFieldMap, fkRecordMap: IFkRecordMap) {
          for (const fieldId in fkRecordMap) {
            const fkMap = fkRecordMap[fieldId];
            const field = fieldMap[fieldId] as LinkFieldDto;
            const relationship = field.options.relationship;
      Severity: Minor
      Found in apps/nestjs-backend/src/features/calculation/link.service.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 getContextByDelete has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        private async getContextByDelete(linkFieldRaws: Field[], recordIds: string[]) {
          const cellContextsMap: { [tableId: string]: ICellContext[] } = {};
      
          const keyToValue = (key: string | string[] | null) =>
            key ? (Array.isArray(key) ? key.map((id) => ({ id })) : { id: key }) : null;
      Severity: Minor
      Found in apps/nestjs-backend/src/features/calculation/link.service.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

      Consider simplifying this complex logical expression.
      Open

            if (relationship === Relationship.ManyMany || relationship === Relationship.OneMany) {
              const newCellValue = cellContext.newValue as ILinkCellValue[] | undefined;
              const oldKey = foreignKeys?.map((key) => key.foreignId) ?? null;
              const newKey = newCellValue?.map((item) => item.id) ?? null;
      
      
      Severity: Major
      Found in apps/nestjs-backend/src/features/calculation/link.service.ts - About 40 mins to fix

        Function fetchRecordMap has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          private async fetchRecordMap(
            tableId2DbTableName: { [tableId: string]: string },
            fieldMapByTableId: { [tableId: string]: IFieldMap },
            recordMapByTableId: IRecordMapByTableId,
            cellContexts: ICellContext[],
        Severity: Minor
        Found in apps/nestjs-backend/src/features/calculation/link.service.ts - About 35 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

        Avoid too many return statements within this function.
        Open

                return acc;
        Severity: Major
        Found in apps/nestjs-backend/src/features/calculation/link.service.ts - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                return acc;
          Severity: Major
          Found in apps/nestjs-backend/src/features/calculation/link.service.ts - About 30 mins to fix

            There are no issues that match your filters.

            Category
            Status