Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Task/harden validation of countries in asset profile endpoints (#7316)
Thomas Kaul5284f5ec77a6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 83146cce0f..270ea6f090 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Changed+- Hardened the validation of the countries in the asset profile endpoints- Set the change detection strategy to `OnPush` in the _X-ray_ page## 3.25.0 - 2026-07-12diff --git a/libs/common/src/lib/dtos/country.dto.ts b/libs/common/src/lib/dtos/country.dto.tsnew file mode 100644index 0000000000..663aa1ac61--- /dev/null+++ b/libs/common/src/lib/dtos/country.dto.ts@@ -0,0 +1,11 @@+import { IsISO31661Alpha2, IsNumber, Max, Min } from 'class-validator';++export class CountryDto {+ @IsISO31661Alpha2()+ code: string;++ @IsNumber()+ @Min(0)+ @Max(1)+ weight: number;+}diff --git a/libs/common/src/lib/dtos/create-asset-profile.dto.ts b/libs/common/src/lib/dtos/create-asset-profile.dto.tsindex 73f0d3f5a5..3e7e2224e7 100644--- a/libs/common/src/lib/dtos/create-asset-profile.dto.ts+++ b/libs/common/src/lib/dtos/create-asset-profile.dto.ts@@ -1,15 +1,19 @@import { IsCurrencyCode } from '@ghostfolio/common/validators/is-currency-code';import { AssetClass, AssetSubClass, DataSource, Prisma } from '@prisma/client';+import { Type } from 'class-transformer';import {IsArray,IsBoolean,IsEnum,IsOptional,IsString,- IsUrl+ IsUrl,+ ValidateNested} from 'class-validator';+import { CountryDto } from './country.dto';+export class CreateAssetProfileDto {@IsEnum(AssetClass)@IsOptional()@@ -25,6 +29,8 @@ export class CreateAssetProfileDto {@IsArray()@IsOptional()+ @Type(() => CountryDto)+ @ValidateNested({ each: true })countries?: Prisma.InputJsonArray;@IsCurrencyCode()diff --git a/libs/common/src/lib/dtos/index.ts b/libs/common/src/lib/dtos/index.tsindex cf0ce6f577..dea0923989 100644--- a/libs/common/src/lib/dtos/index.ts+++ b/libs/common/src/lib/dtos/index.ts@@ -1,4 +1,5 @@import { AuthDeviceDto } from './auth-device.dto';+import { CountryDto } from './country.dto';import { CreateAccessDto } from './create-access.dto';import { CreateAccountBalanceDto } from './create-account-balance.dto';import { CreateAccountWithBalancesDto } from './create-account-with-balances.dto';@@ -26,6 +27,7 @@ import { UpdateUserSettingDto } from './update-user-setting.dto';export {AuthDeviceDto,+ CountryDto,CreateAccessDto,CreateAccountBalanceDto,CreateAccountDto,diff --git a/libs/common/src/lib/dtos/update-asset-profile.dto.ts b/libs/common/src/lib/dtos/update-asset-profile.dto.tsindex 7096023b31..dc660a4818 100644--- a/libs/common/src/lib/dtos/update-asset-profile.dto.ts+++ b/libs/common/src/lib/dtos/update-asset-profile.dto.ts@@ -7,6 +7,7 @@ import {DataSource,Prisma} from '@prisma/client';+import { Type } from 'class-transformer';import {IsArray,IsBoolean,@@ -14,9 +15,12 @@ import {IsObject,IsOptional,IsString,- IsUrl+ IsUrl,+ ValidateNested} from 'class-validator';+import { CountryDto } from './country.dto';+export class UpdateAssetProfileDto {@IsEnum(AssetClass)@IsOptional()@@ -32,6 +36,8 @@ export class UpdateAssetProfileDto {@IsArray()@IsOptional()+ @Type(() => CountryDto)+ @ValidateNested({ each: true })countries?: Prisma.InputJsonArray;@IsCurrencyCode()