File field-supplement.service.ts
has 1154 lines of code (exceeds 300 allowed). Consider refactoring. Open
/* eslint-disable sonarjs/no-duplicate-string */
import { BadRequestException, Injectable } from '@nestjs/common';
import type {
IFieldRo,
IFieldVo,
FieldSupplementService
has 51 functions (exceeds 20 allowed). Consider refactoring. Open
@Injectable()
export class FieldSupplementService {
constructor(
private readonly fieldService: FieldService,
private readonly prismaService: PrismaService,
Function cleanForeignKey
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
async cleanForeignKey(options: ILinkFieldOptions) {
const { fkHostTableName, relationship, selfKeyName, foreignKeyName, isOneWay } = options;
const dropTable = async (tableName: string) => {
const alterTableSchema = this.knex.schema.dropTable(tableName);
- 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 prepareFormattingShowAs
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
prepareFormattingShowAs(
options: IFieldRo['options'] = {},
sourceOptions: IFieldVo['options'],
cellValueType: CellValueType,
isMultipleCellValue?: boolean
- 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 generateLinkOptionsVo
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
private async generateLinkOptionsVo(params: {
tableId: string;
optionsRo: ILinkFieldOptionsRo;
fieldId: string;
symmetricFieldId: string | undefined;
- 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 createForeignKey
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
async createForeignKey(options: ILinkFieldOptions) {
const { relationship, fkHostTableName, selfKeyName, foreignKeyName, isOneWay } = options;
let alterTableSchema: Knex.SchemaBuilder | undefined;
- 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 prepareLookupOptions
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private async prepareLookupOptions(field: IFieldRo, batchFieldVos?: IFieldVo[]) {
const { lookupOptions } = field;
if (!lookupOptions) {
throw new BadRequestException('lookupOptions is required');
}
- 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 prepareUserField
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private prepareUserField(field: IFieldRo) {
const { name } = field;
const options: IUserFieldOptions = field.options || UserFieldCore.defaultOptions();
const { isMultiple } = options;
const defaultValue = options.defaultValue ? [options.defaultValue].flat() : undefined;
- 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 prepareCreateField
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
async prepareCreateField(tableId: string, fieldRo: IFieldRo, batchFieldVos?: IFieldVo[]) {
const field = (await this.prepareCreateFieldInner(tableId, fieldRo, batchFieldVos)) as IFieldVo;
const fieldId = field.id || generateFieldId();
const fieldName = await this.uniqFieldName(tableId, field.name);
- 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 prepareUpdateLinkField
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private async prepareUpdateLinkField(tableId: string, fieldRo: IFieldRo, oldFieldVo: IFieldVo) {
if (!majorFieldKeysChanged(oldFieldVo, fieldRo)) {
return mergeWith({}, oldFieldVo, fieldRo, (_oldValue: unknown, newValue: unknown) => {
if (Array.isArray(newValue)) {
return newValue;
- 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"