Browse Source

Resolve validation error caused by empty strings

pull/7509/head
Thomas Kaul 4 weeks 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'], files: ['**/*.ts', '**/*.tsx'],
// Override or add rules here // Override or add rules here
rules: { rules: {
'@typescript-eslint/prefer-nullish-coalescing': [ '@typescript-eslint/prefer-nullish-coalescing': 'error'
'error',
{
ignorePrimitives: {
string: true
}
}
]
} }
}, },
{ {

18
apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts

@ -11,6 +11,8 @@ import {
DATE_FORMAT, DATE_FORMAT,
getCountryName, getCountryName,
getCurrencyFromSymbol, getCurrencyFromSymbol,
getStringOrNull,
getStringOrUndefined,
isCurrency isCurrency
} from '@ghostfolio/common/helper'; } from '@ghostfolio/common/helper';
import { import {
@ -568,9 +570,10 @@ export class GfAssetProfileDialogComponent implements OnInit {
this.assetProfileForm.controls.scraperConfiguration.controls.headers this.assetProfileForm.controls.scraperConfiguration.controls.headers
.value ?? '{}' .value ?? '{}'
) as Record<string, string>, ) as Record<string, string>,
locale: locale: getStringOrUndefined(
this.assetProfileForm.controls.scraperConfiguration.controls.locale this.assetProfileForm.controls.scraperConfiguration.controls.locale
?.value || undefined, ?.value
),
mode: mode:
this.assetProfileForm.controls.scraperConfiguration.controls.mode this.assetProfileForm.controls.scraperConfiguration.controls.mode
?.value ?? undefined, ?.value ?? undefined,
@ -619,7 +622,7 @@ export class GfAssetProfileDialogComponent implements OnInit {
assetClass: this.assetProfileForm.controls.assetClass.value ?? undefined, assetClass: this.assetProfileForm.controls.assetClass.value ?? undefined,
assetSubClass: assetSubClass:
this.assetProfileForm.controls.assetSubClass.value ?? undefined, 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, currency: this.assetProfileForm.controls.currency.value ?? undefined,
dataGatheringFrequency: dataGatheringFrequency:
this.assetProfileForm.controls.dataGatheringFrequency.value ?? this.assetProfileForm.controls.dataGatheringFrequency.value ??
@ -627,8 +630,8 @@ export class GfAssetProfileDialogComponent implements OnInit {
isActive: isBoolean(this.assetProfileForm.controls.isActive.value) isActive: isBoolean(this.assetProfileForm.controls.isActive.value)
? this.assetProfileForm.controls.isActive.value ? this.assetProfileForm.controls.isActive.value
: undefined, : undefined,
name: this.assetProfileForm.controls.name.value || undefined, name: this.assetProfileForm.controls.name.value ?? undefined,
url: this.assetProfileForm.controls.url.value || undefined url: getStringOrNull(this.assetProfileForm.controls.url.value)
}; };
try { try {
@ -737,9 +740,10 @@ export class GfAssetProfileDialogComponent implements OnInit {
this.assetProfileForm.controls.scraperConfiguration.controls.headers this.assetProfileForm.controls.scraperConfiguration.controls.headers
.value ?? '{}' .value ?? '{}'
) as Record<string, string>, ) as Record<string, string>,
locale: locale: getStringOrUndefined(
this.assetProfileForm.controls.scraperConfiguration.controls.locale this.assetProfileForm.controls.scraperConfiguration.controls.locale
?.value || undefined, ?.value
),
mode: this.assetProfileForm.controls.scraperConfiguration.controls mode: this.assetProfileForm.controls.scraperConfiguration.controls
.mode?.value, .mode?.value,
selector: selector:

4
libs/common/src/lib/dtos/update-asset-profile.dto.ts

@ -35,7 +35,7 @@ export class UpdateAssetProfileDto {
@IsOptional() @IsOptional()
@IsString() @IsString()
comment?: string; comment?: string | null;
@IsArray() @IsArray()
@IsOptional() @IsOptional()
@ -96,5 +96,5 @@ export class UpdateAssetProfileDto {
protocols: ['http', 'https'], protocols: ['http', 'https'],
require_protocol: true 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; 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[]) { export function getSum(aArray: Big[]) {
if (aArray?.length > 0) { if (aArray?.length > 0) {
return aArray.reduce((a, b) => a.plus(b), new Big(0)); return aArray.reduce((a, b) => a.plus(b), new Big(0));

Loading…
Cancel
Save