teableio/teable

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

Summary

Maintainability
D
1 day
Test Coverage

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

import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common';
import type {
  IFieldVo,
  IGetFieldsQuery,
  ISnapshotBase,
Severity: Major
Found in apps/nestjs-backend/src/features/field/field.service.ts - About 7 hrs to fix

    FieldService has 27 functions (exceeds 20 allowed). Consider refactoring.
    Open

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

      Function handleFieldProperty has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        private async handleFieldProperty(fieldId: string, opContext: IOpContext) {
          const { key, newValue } = opContext as ISetFieldPropertyOpContext;
      
          if (key === 'options') {
            if (!newValue) {
      Severity: Minor
      Found in apps/nestjs-backend/src/features/field/field.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 alterTableModifyFieldValidation has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        private async alterTableModifyFieldValidation(
          fieldId: string,
          key: 'unique' | 'notNull',
          newValue?: boolean
        ) {
      Severity: Minor
      Found in apps/nestjs-backend/src/features/field/field.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 alterTableAddField has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        private async alterTableAddField(dbTableName: string, fieldInstances: IFieldInstance[]) {
          for (let i = 0; i < fieldInstances.length; i++) {
            const { dbFieldType, dbFieldName, type, isLookup, unique, notNull } = fieldInstances[i];
      
            const alterTableQuery = this.knex.schema
      Severity: Minor
      Found in apps/nestjs-backend/src/features/field/field.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

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

        async getFieldsByQuery(tableId: string, query?: IGetFieldsQuery): Promise<IFieldVo[]> {
          const fieldsPlain = await this.prismaService.txClient().field.findMany({
            where: { tableId, deletedTime: null },
            orderBy: [
              {
      Severity: Minor
      Found in apps/nestjs-backend/src/features/field/field.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

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

        async batchUpdateFields(tableId: string, opData: { fieldId: string; ops: IOtOperation[] }[]) {
          if (!opData.length) return;
      
          const fieldRaw = await this.prismaService.txClient().field.findMany({
            where: { tableId, id: { in: opData.map((data) => data.fieldId) }, deletedTime: null },
      Severity: Minor
      Found in apps/nestjs-backend/src/features/field/field.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

      There are no issues that match your filters.

      Category
      Status