mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
move CONTRIBUTIONLINK_NAME validation into arg
This commit is contained in:
parent
51d1c6b64b
commit
191103a812
@ -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)
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user