Browse Source

Resolve validation error caused by empty strings

pull/7509/head
Thomas Kaul 1 month ago
parent
commit
31bf289bd3
  1. 9
      apps/client/eslint.config.cjs
  2. 18
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts
  3. 4
      libs/common/src/lib/dtos/update-asset-profile.dto.ts
  4. 16
      libs/common/src/lib/helper.ts

9
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'
}
},
{

18
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<string, string>,
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<string, string>,
locale:
locale: getStringOrUndefined(
this.assetProfileForm.controls.scraperConfiguration.controls.locale
?.value || undefined,
?.value
),
mode: this.assetProfileForm.controls.scraperConfiguration.controls
.mode?.value,
selector:

4
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;
}

16
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));

Loading…
Cancel
Save