mirror of https://github.com/ghostfolio/ghostfolio
committed by
GitHub
17 changed files with 292 additions and 91 deletions
@ -0,0 +1,43 @@ |
|||||
|
import { DATE_RANGES } from '@ghostfolio/common/config'; |
||||
|
import { DateRange } from '@ghostfolio/common/types'; |
||||
|
|
||||
|
import { Type as ActivityType } from '@prisma/client'; |
||||
|
import { Transform, TransformFnParams } from 'class-transformer'; |
||||
|
import { IsEnum, IsOptional, IsString, Matches } from 'class-validator'; |
||||
|
import { isString } from 'lodash'; |
||||
|
|
||||
|
// A named date range or a calendar year like '2024', '2023', '2022', etc.
|
||||
|
const DATE_RANGE_PATTERN = new RegExp(`^(${DATE_RANGES.join('|')}|\\d{4})$`); |
||||
|
|
||||
|
export class ActivitiesFilterDto { |
||||
|
@IsOptional() |
||||
|
@IsString() |
||||
|
accounts?: string; |
||||
|
|
||||
|
@IsEnum(ActivityType, { each: true }) |
||||
|
@IsOptional() |
||||
|
@Transform(({ value }: TransformFnParams) => { |
||||
|
return isString(value) ? value.split(',') : value; |
||||
|
}) |
||||
|
activityTypes?: ActivityType[]; |
||||
|
|
||||
|
@IsOptional() |
||||
|
@IsString() |
||||
|
assetClasses?: string; |
||||
|
|
||||
|
@IsOptional() |
||||
|
@IsString() |
||||
|
dataSource?: string; |
||||
|
|
||||
|
@IsOptional() |
||||
|
@Matches(DATE_RANGE_PATTERN) |
||||
|
range?: DateRange; |
||||
|
|
||||
|
@IsOptional() |
||||
|
@IsString() |
||||
|
symbol?: string; |
||||
|
|
||||
|
@IsOptional() |
||||
|
@IsString() |
||||
|
tags?: string; |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
import { Prisma } from '@prisma/client'; |
||||
|
import { Type } from 'class-transformer'; |
||||
|
import { IsIn, IsInt, IsOptional, Min } from 'class-validator'; |
||||
|
|
||||
|
import { ActivitiesFilterDto } from './activities-filter.dto'; |
||||
|
|
||||
|
export class GetActivitiesDto extends ActivitiesFilterDto { |
||||
|
@IsInt() |
||||
|
@IsOptional() |
||||
|
@Min(0) |
||||
|
@Type(() => Number) |
||||
|
skip?: number; |
||||
|
|
||||
|
@IsIn(Object.values(Prisma.OrderScalarFieldEnum)) |
||||
|
@IsOptional() |
||||
|
sortColumn?: keyof typeof Prisma.OrderScalarFieldEnum; |
||||
|
|
||||
|
@IsIn(['asc', 'desc'] as Prisma.SortOrder[]) |
||||
|
@IsOptional() |
||||
|
sortDirection?: Prisma.SortOrder; |
||||
|
|
||||
|
@IsInt() |
||||
|
@IsOptional() |
||||
|
@Min(0) |
||||
|
@Type(() => Number) |
||||
|
take?: number; |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
import { ActivitiesFilterDto } from '@ghostfolio/api/app/activities/activities-filter.dto'; |
||||
|
|
||||
|
import { Transform, TransformFnParams } from 'class-transformer'; |
||||
|
import { IsOptional, IsUUID } from 'class-validator'; |
||||
|
import { isString } from 'lodash'; |
||||
|
|
||||
|
export class GetExportDto extends ActivitiesFilterDto { |
||||
|
@IsOptional() |
||||
|
@IsUUID(undefined, { each: true }) |
||||
|
@Transform(({ value }: TransformFnParams) => { |
||||
|
return isString(value) ? value.split(',') : value; |
||||
|
}) |
||||
|
activityIds?: string[]; |
||||
|
} |
||||
@ -1,9 +1,3 @@ |
|||||
export type DateRange = |
import type { DATE_RANGES } from '../config'; |
||||
| '1d' |
|
||||
| '1y' |
export type DateRange = (typeof DATE_RANGES)[number] | string; // '2024', '2023', '2022', etc.
|
||||
| '5y' |
|
||||
| 'max' |
|
||||
| 'mtd' |
|
||||
| 'wtd' |
|
||||
| 'ytd' |
|
||||
| string; // '2024', '2023', '2022', etc.
|
|
||||
|
|||||
Loading…
Reference in new issue