mirror of https://github.com/ghostfolio/ghostfolio
12 changed files with 163 additions and 114 deletions
@ -1,26 +1,36 @@ |
|||
import { IsAfter1970Constraint } from '@ghostfolio/common/validator-constraints/is-after-1970'; |
|||
import { IsSplitFactorConstraint } from '@ghostfolio/common/validator-constraints/is-split-factor'; |
|||
import { IsSplitRatioConstraint } from '@ghostfolio/common/validator-constraints/is-split-ratio'; |
|||
|
|||
import { IsISO8601, IsNumber, Validate } from 'class-validator'; |
|||
import { IsInt, IsISO8601, Validate } from 'class-validator'; |
|||
|
|||
export class CreateAssetProfileSplitDto { |
|||
/** |
|||
* The date the split becomes effective. Activities before this date are |
|||
* adjusted by the factor. |
|||
* adjusted by the ratio. |
|||
*/ |
|||
@IsISO8601() |
|||
@Validate(IsAfter1970Constraint) |
|||
date: string; |
|||
|
|||
/** |
|||
* The number of shares held after the split per 1 share held before, for |
|||
* example 4 for a 4:1 split or 0.1 for a 1:10 reverse split. |
|||
* The number of shares held before the split, for example 1 for a 4:1 split |
|||
* or 10 for a 1:10 reverse split. |
|||
*/ |
|||
@IsInt() |
|||
denominator: number; |
|||
|
|||
/** |
|||
* The number of shares held after the split, for example 4 for a 4:1 split |
|||
* or 1 for a 1:10 reverse split. |
|||
* |
|||
* The resulting split factor is numerator / denominator. Both parts are kept |
|||
* so that the ratio stays exact, for example 1/3 for a 1:3 reverse split. |
|||
* |
|||
* Only the quantity of activities is adjusted by this factor. Market data is |
|||
* Only the quantity of activities is adjusted by this ratio. Market data is |
|||
* already split-adjusted by the data providers and must not be adjusted |
|||
* again. |
|||
*/ |
|||
@IsNumber() |
|||
@Validate(IsSplitFactorConstraint) |
|||
factor: number; |
|||
@IsInt() |
|||
@Validate(IsSplitRatioConstraint) |
|||
numerator: number; |
|||
} |
|||
|
|||
@ -1,17 +0,0 @@ |
|||
import { isSplitFactor } from '@ghostfolio/common/helper'; |
|||
|
|||
import { |
|||
ValidatorConstraint, |
|||
ValidatorConstraintInterface |
|||
} from 'class-validator'; |
|||
|
|||
@ValidatorConstraint({ name: 'isSplitFactor' }) |
|||
export class IsSplitFactorConstraint implements ValidatorConstraintInterface { |
|||
public defaultMessage() { |
|||
return 'factor must be a positive number other than 1'; |
|||
} |
|||
|
|||
public validate(aFactor: number) { |
|||
return isSplitFactor(aFactor); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
import { isSplitRatio } from '@ghostfolio/common/helper'; |
|||
|
|||
import { |
|||
ValidationArguments, |
|||
ValidatorConstraint, |
|||
ValidatorConstraintInterface |
|||
} from 'class-validator'; |
|||
|
|||
@ValidatorConstraint({ name: 'isSplitRatio' }) |
|||
export class IsSplitRatioConstraint implements ValidatorConstraintInterface { |
|||
public defaultMessage() { |
|||
return 'numerator and denominator must be different positive integers'; |
|||
} |
|||
|
|||
public validate(_: unknown, { object }: ValidationArguments) { |
|||
return isSplitRatio(object as { denominator: number; numerator: number }); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue