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';
LinkService
has 31 functions (exceeds 20 allowed). Consider refactoring. Open
@Injectable()
export class LinkService {
constructor(
private readonly prismaService: PrismaService,
private readonly batchService: BatchService,
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
- Read upRead up
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[] {
- Read upRead up
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;
- Read upRead up
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;
- Read upRead up
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;
- Read upRead up
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;
- Read upRead up
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;
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[],
- Read upRead up
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;
Avoid too many return
statements within this function. Open
return acc;