From 191103a812a4e9b8dbc0e764dbd3153d65860dec Mon Sep 17 00:00:00 2001 From: Einhornimmond Date: Wed, 9 Aug 2023 13:59:29 +0200 Subject: [PATCH] move CONTRIBUTIONLINK_NAME validation into arg --- backend/src/graphql/arg/ContributionLinkArgs.ts | 9 ++++++++- backend/src/graphql/resolver/ContributionLinkResolver.ts | 8 +------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/backend/src/graphql/arg/ContributionLinkArgs.ts b/backend/src/graphql/arg/ContributionLinkArgs.ts index 9d12a6128..59688a969 100644 --- a/backend/src/graphql/arg/ContributionLinkArgs.ts +++ b/backend/src/graphql/arg/ContributionLinkArgs.ts @@ -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) diff --git a/backend/src/graphql/resolver/ContributionLinkResolver.ts b/backend/src/graphql/resolver/ContributionLinkResolver.ts index 42593dec1..e8a694a55 100644 --- a/backend/src/graphql/resolver/ContributionLinkResolver.ts +++ b/backend/src/graphql/resolver/ContributionLinkResolver.ts @@ -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 { 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) }