move CONTRIBUTIONLINK_NAME validation into arg

This commit is contained in:
Einhornimmond 2023-08-09 13:59:29 +02:00
parent 51d1c6b64b
commit 191103a812
2 changed files with 9 additions and 8 deletions

View File

@ -2,7 +2,12 @@ import { MaxLength, MinLength } from 'class-validator'
import { Decimal } from 'decimal.js-light'
import { ArgsType, Field, Int } from 'type-graphql'
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from '@/graphql/resolver/const/const'
import {
MEMO_MAX_CHARS,
MEMO_MIN_CHARS,
CONTRIBUTIONLINK_NAME_MIN_CHARS,
CONTRIBUTIONLINK_NAME_MAX_CHARS,
} from '@/graphql/resolver/const/const'
@ArgsType()
export class ContributionLinkArgs {
@ -10,6 +15,8 @@ export class ContributionLinkArgs {
amount: Decimal
@Field(() => String)
@MaxLength(CONTRIBUTIONLINK_NAME_MAX_CHARS)
@MinLength(CONTRIBUTIONLINK_NAME_MIN_CHARS)
name: string
@Field(() => String)

View File

@ -18,7 +18,6 @@ import {
import { Context, getUser } from '@/server/context'
import { LogError } from '@/server/LogError'
import { CONTRIBUTIONLINK_NAME_MAX_CHARS, CONTRIBUTIONLINK_NAME_MIN_CHARS } from './const/const'
import { transactionLinkCode as contributionLinkCode } from './TransactionLinkResolver'
import { isStartEndDateValid } from './util/creations'
@ -41,12 +40,7 @@ export class ContributionLinkResolver {
@Ctx() context: Context,
): Promise<ContributionLink> {
isStartEndDateValid(validFrom, validTo)
if (name.length < CONTRIBUTIONLINK_NAME_MIN_CHARS) {
throw new LogError('The value of name is too short', name.length)
}
if (name.length > CONTRIBUTIONLINK_NAME_MAX_CHARS) {
throw new LogError('The value of name is too long', name.length)
}
if (!new Decimal(amount).isPositive()) {
throw new LogError('The amount must be a positiv value', amount)
}