mirror of https://github.com/ghostfolio/ghostfolio
Browse Source
* Harden validation of accounts, assetClasses, dataSource and tags in endpoints with filters * Update changelogpull/6845/merge
committed by
GitHub
6 changed files with 43 additions and 22 deletions
@ -1,23 +1,35 @@ |
|||||
import { IsOptional, IsString } from 'class-validator'; |
import { AssetClass, DataSource } from '@prisma/client'; |
||||
|
import { Transform, TransformFnParams } from 'class-transformer'; |
||||
|
import { IsEnum, IsOptional, IsString, IsUUID } from 'class-validator'; |
||||
|
import { isString } from 'lodash'; |
||||
|
|
||||
export class FilterDto { |
export class FilterDto { |
||||
@IsOptional() |
@IsOptional() |
||||
@IsString() |
@IsUUID(undefined, { each: true }) |
||||
accounts?: string; |
@Transform(({ value }: TransformFnParams) => { |
||||
|
return isString(value) ? value.split(',') : value; |
||||
|
}) |
||||
|
accounts?: string[]; |
||||
|
|
||||
|
@IsEnum(AssetClass, { each: true }) |
||||
@IsOptional() |
@IsOptional() |
||||
@IsString() |
@Transform(({ value }: TransformFnParams) => { |
||||
assetClasses?: string; |
return isString(value) ? value.split(',') : value; |
||||
|
}) |
||||
|
assetClasses?: AssetClass[]; |
||||
|
|
||||
|
@IsEnum(DataSource) |
||||
@IsOptional() |
@IsOptional() |
||||
@IsString() |
dataSource?: DataSource; |
||||
dataSource?: string; |
|
||||
|
|
||||
@IsOptional() |
@IsOptional() |
||||
@IsString() |
@IsString() |
||||
symbol?: string; |
symbol?: string; |
||||
|
|
||||
@IsOptional() |
@IsOptional() |
||||
@IsString() |
@IsUUID(undefined, { each: true }) |
||||
tags?: string; |
@Transform(({ value }: TransformFnParams) => { |
||||
|
return isString(value) ? value.split(',') : value; |
||||
|
}) |
||||
|
tags?: string[]; |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue