diff --git a/apps/client/eslint.config.cjs b/apps/client/eslint.config.cjs index 9aff0a032d..bcbe2c1c13 100644 --- a/apps/client/eslint.config.cjs +++ b/apps/client/eslint.config.cjs @@ -48,14 +48,7 @@ module.exports = [ files: ['**/*.ts', '**/*.tsx'], // Override or add rules here rules: { - '@typescript-eslint/prefer-nullish-coalescing': [ - 'error', - { - ignorePrimitives: { - string: true - } - } - ] + '@typescript-eslint/prefer-nullish-coalescing': 'error' } }, { diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts index cc6765f8e7..330688da18 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts @@ -11,6 +11,8 @@ import { DATE_FORMAT, getCountryName, getCurrencyFromSymbol, + getStringOrNull, + getStringOrUndefined, isCurrency } from '@ghostfolio/common/helper'; import { @@ -568,9 +570,10 @@ export class GfAssetProfileDialogComponent implements OnInit { this.assetProfileForm.controls.scraperConfiguration.controls.headers .value ?? '{}' ) as Record, - locale: + locale: getStringOrUndefined( this.assetProfileForm.controls.scraperConfiguration.controls.locale - ?.value || undefined, + ?.value + ), mode: this.assetProfileForm.controls.scraperConfiguration.controls.mode ?.value ?? undefined, @@ -619,7 +622,7 @@ export class GfAssetProfileDialogComponent implements OnInit { assetClass: this.assetProfileForm.controls.assetClass.value ?? undefined, assetSubClass: this.assetProfileForm.controls.assetSubClass.value ?? undefined, - comment: this.assetProfileForm.controls.comment.value || undefined, + comment: getStringOrNull(this.assetProfileForm.controls.comment.value), currency: this.assetProfileForm.controls.currency.value ?? undefined, dataGatheringFrequency: this.assetProfileForm.controls.dataGatheringFrequency.value ?? @@ -627,8 +630,8 @@ export class GfAssetProfileDialogComponent implements OnInit { isActive: isBoolean(this.assetProfileForm.controls.isActive.value) ? this.assetProfileForm.controls.isActive.value : undefined, - name: this.assetProfileForm.controls.name.value || undefined, - url: this.assetProfileForm.controls.url.value || undefined + name: this.assetProfileForm.controls.name.value ?? undefined, + url: getStringOrNull(this.assetProfileForm.controls.url.value) }; try { @@ -737,9 +740,10 @@ export class GfAssetProfileDialogComponent implements OnInit { this.assetProfileForm.controls.scraperConfiguration.controls.headers .value ?? '{}' ) as Record, - locale: + locale: getStringOrUndefined( this.assetProfileForm.controls.scraperConfiguration.controls.locale - ?.value || undefined, + ?.value + ), mode: this.assetProfileForm.controls.scraperConfiguration.controls .mode?.value, selector: diff --git a/libs/common/src/lib/dtos/update-asset-profile.dto.ts b/libs/common/src/lib/dtos/update-asset-profile.dto.ts index a6e2230e8e..a8eaad608a 100644 --- a/libs/common/src/lib/dtos/update-asset-profile.dto.ts +++ b/libs/common/src/lib/dtos/update-asset-profile.dto.ts @@ -35,7 +35,7 @@ export class UpdateAssetProfileDto { @IsOptional() @IsString() - comment?: string; + comment?: string | null; @IsArray() @IsOptional() @@ -96,5 +96,5 @@ export class UpdateAssetProfileDto { protocols: ['http', 'https'], require_protocol: true }) - url?: string; + url?: string | null; } diff --git a/libs/common/src/lib/helper.ts b/libs/common/src/lib/helper.ts index db1d3c2a20..4c02f86dc3 100644 --- a/libs/common/src/lib/helper.ts +++ b/libs/common/src/lib/helper.ts @@ -397,6 +397,22 @@ export function getStartOfUtcDate(aDate: Date) { return date; } +export function getStringOrNull(aString: string | null | undefined) { + if (aString) { + return aString; + } + + return null; +} + +export function getStringOrUndefined(aString: string | null | undefined) { + if (aString) { + return aString; + } + + return undefined; +} + export function getSum(aArray: Big[]) { if (aArray?.length > 0) { return aArray.reduce((a, b) => a.plus(b), new Big(0));