From cadc3cd26a5dd0fd8707fee3e5760dfdc71c5666 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Tue, 2 Sep 2025 20:13:10 +0300 Subject: [PATCH] feat(subscriptions): add trial period validation for subscriptions - Implemented a check to verify if a user has already utilized their trial period before allowing access to subscription services. - Enhanced error handling to provide a clear message when a trial period has been previously used, improving user experience and subscription management. --- packages/graphql/api/subscriptions.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/graphql/api/subscriptions.ts b/packages/graphql/api/subscriptions.ts index ded79d6..084b892 100644 --- a/packages/graphql/api/subscriptions.ts +++ b/packages/graphql/api/subscriptions.ts @@ -44,6 +44,22 @@ export class SubscriptionsService extends BaseService { // Получаем пользователя и проверяем бан const { customer } = await this.checkIsBanned(); + // Проверяем, не использовал ли пользователь уже пробный период + const { subscription: existingSubscription } = await this.getSubscription({ + telegramId: customer.telegramId, + }); + if (existingSubscription) { + // Проверяем, есть ли в истории успешная пробная подписка + const hasUsedTrial = existingSubscription.subscriptionHistories?.some( + (item) => + item?.period === GQL.Enum_Subscriptionhistory_Period.Trial && + item?.state === GQL.Enum_Subscriptionhistory_State.Success, + ); + if (hasUsedTrial) { + throw new Error('Пробный период уже был использован'); + } + } + // Получаем цены подписки для определения длительности пробного периода const { subscriptionPrices } = await this.getSubscriptionPrices({ isActive: true }); if (!subscriptionPrices) throw new Error('Subscription prices not found');