Compare commits

...

105 Commits

Author SHA1 Message Date
vchikalkin
7ecf72656b chore: update type definitions and react dependencies to latest versions 2025-12-30 16:50:24 +03:00
vchikalkin
241effd3b8 fix build 2025-10-27 14:05:20 +03:00
vchikalkin
64c9134cc2 feat: add URL_FAQ environment variable and update bot localization
- Introduced a new environment variable URL_FAQ for FAQ links.
- Updated Russian localization to include a button for FAQ access.
- Modified the main menu to include a URL button for the FAQ section.
2025-10-27 13:43:22 +03:00
vchikalkin
19b53db5f3 refactor: rename OFFER_URL and PRIVACY_URL to URL_OFFER and URL_PRIVACY
- Updated environment variable names for consistency across the application.
- Modified references in the deployment workflow, bot conversations, and web components to use the new variable names.
2025-10-27 13:26:00 +03:00
vchikalkin
a26c0eab8a hotfix: getRemainingOrdersCount: add master to filter 2025-10-16 17:28:59 +03:00
vchikalkin
3ac86cfeb0 mdx: whitespace fix 2025-10-14 20:06:33 +03:00
vchikalkin
d895433a65 chore: update deploy.yml to enhance .env file creation process
- Renamed steps for clarity in the deployment workflow.
- Updated the creation of the .env files to use secrets for sensitive URLs instead of hardcoded values, improving security and flexibility.
2025-10-14 20:01:12 +03:00
vchikalkin
3064887ecf Revert "chore: update deploy.yml to create .env files with improved variable handling"
This reverts commit bdcd11d97e59affe3d16a65e81b142dc486b889e.
2025-10-14 19:59:11 +03:00
vchikalkin
02e9d5c529 refactor: update contact information in offer and privacy documents
- Simplified contact information sections in both the offer and privacy policy documents.
- Removed specific Telegram link references and replaced them with a general note directing users to the bot description for contact details.
2025-10-14 16:42:46 +03:00
vchikalkin
f45140ef04 remove comment 2025-10-14 16:30:13 +03:00
vchikalkin
bdcd11d97e chore: update deploy.yml to create .env files with improved variable handling
- Renamed steps for clarity in the deployment workflow.
- Updated the creation of the fake and real .env files to include necessary environment variables and secrets.
- Removed hardcoded URLs and replaced them with references to secrets for better security and flexibility.
2025-10-14 16:28:01 +03:00
vchikalkin
6a0d34d37b refactor: update MDX link handling and improve document formatting
- Removed the custom link component in MDX and replaced it with standard anchor tags for external links.
- Updated offer and privacy policy documents to use environment variables for dynamic URLs instead of custom components.
- Improved formatting for better readability in the offer and privacy policy sections.
2025-10-14 16:16:30 +03:00
Vlad Chikalkin
2df80c90f6
Feature/mdx (#128)
* convert /documents/privacy to .mdx

* fix: update h2 styling in MDX components

- Changed h2 font weight from bold to semibold for improved visual hierarchy in rendered content.

* fix build

* feat: implement public offer document and layout

- Added a new layout component for the public offer document.
- Created the public offer page in MDX format, detailing terms and conditions for service usage.
- Removed the old offer page in TSX format.
- Updated links for offer and support to a new shared component for better maintainability.
- Integrated Tailwind CSS typography plugin for improved text styling.

* fix: correct formatting in privacy policy terms section

- Adjusted the formatting of terms and definitions in the privacy policy to ensure consistent presentation and clarity.
- Removed unnecessary hyphenation in the definition of "Разработчик" and "Политика" for improved readability.
2025-10-14 15:43:51 +03:00
vchikalkin
03145534a1 feat: update queryTTL for customer-related queries
- Added 12-hour TTL for GetCustomer and GetSubscriptionSettings queries to improve caching strategy.
- Ensured other queries remain unchanged with their TTL set to false.
2025-10-12 17:12:08 +03:00
vchikalkin
6a21f5911e feat: add libphonenumber-js for phone number parsing and validation
- Integrated libphonenumber-js to handle phone number parsing and validation in the addContact and registration features.
- Removed deprecated phone validation and normalization functions from utils.
- Updated contact handling logic to ensure valid phone numbers are processed correctly.
2025-10-12 13:41:48 +03:00
vchikalkin
b88ac07ba3 refactor: simplify profile button logic and remove unused components
- Consolidated booking logic into a single handleBook function based on customer role.
- Removed unused Drawer and Button components to streamline the ProfileButtons component.
- Added loading state handling for improved user experience.
2025-10-12 09:03:30 +03:00
vchikalkin
b517519e7e feat: conditionally render services list based on customer role
- Added a check to prevent rendering the ReadonlyServicesList component for users with the 'Client' role, ensuring a tailored experience based on user permissions.
2025-10-11 14:21:37 +03:00
vchikalkin
a1af00af69 feat: allow order with inactive contacts 2025-10-11 14:09:18 +03:00
vchikalkin
311f6c183d fix: prevent subscription info bar from rendering for client role users
- Added a condition to return null for the SubscriptionInfoBar component if the customer role is 'Client', ensuring that clients do not see the subscription information.
2025-10-11 13:37:37 +03:00
vchikalkin
67cf9a8e26 feat: add subscription_price to subscription history
- Included subscription_price in the subscription history object to enhance tracking of trial subscriptions.
2025-10-11 13:36:54 +03:00
vchikalkin
6080aadc93 chore: add workflow_dispatch trigger to deploy.yml for manual deployment 2025-10-09 18:19:57 +03:00
vchikalkin
ee4e70f43d feat: integrate customer data into subscription invoice
- Added CustomersService to retrieve customer information based on telegramId.
- Enhanced invoice provider data to include customer phone and item details for improved payment processing.
- Updated the subscription function to utilize the new customer data in the invoice generation.
2025-10-09 18:04:38 +03:00
vchikalkin
4d40230864 fix: back button mounts after first app launch 2025-10-09 12:01:06 +03:00
vchikalkin
92119baa5e GQL: rename CheckCustomerExists -> _NOCACHE_GetCustomer 2025-10-09 11:26:28 +03:00
vchikalkin
1e9fd66e27 Refactor customer retrieval in addContact function to use RegistrationService
- Replaced the use of CustomersService.getCustomer with RegistrationService.checkCustomerExists for improved consistency in customer existence checks.
- Introduced a new instance of CustomersService for adding invited users, maintaining functionality while enhancing code clarity.
2025-10-09 09:44:43 +03:00
vchikalkin
aa11ecfcec fix "registrationService.getCustomer is not a function" 2025-10-09 00:33:25 +03:00
vchikalkin
8e61fbbb40 Fix: Refactor customer retrieval logic to use checkCustomerExists method
- Updated the addContact and registration features to replace getCustomer calls with checkCustomerExists, improving consistency in customer existence checks.
- Modified GraphQL operations to remove deprecated getCustomer queries and introduced a new checkCustomerExists query for better clarity and efficiency.
- Adjusted queryTTL configuration in cache-proxy to reflect the removal of unused endpoints.
2025-10-09 00:20:37 +03:00
vchikalkin
d32a7dc54e fix registration error 2025-10-08 22:43:24 +03:00
vchikalkin
0a43d63c2c bot: msg-contact-forward: use parse_mode HTML 2025-10-08 22:04:15 +03:00
vchikalkin
01d8bb20d5 Enhance GitHub Actions workflow for conditional builds and environment file management
- Introduced path filtering using `dorny/paths-filter` to conditionally build and push Docker images for web, bot, and cache-proxy projects based on changes.
- Added outputs to track which projects were built and modified the build and push steps to execute conditionally.
- Created separate environment files for each project tag and implemented logic to merge these files into a main `.env` file during deployment.
- Improved the deployment process by conditionally copying environment files to the VPS based on whether the corresponding project was built.
2025-10-08 18:13:09 +03:00
vchikalkin
20b2b44572 Update queryTTL configuration in cache-proxy to include new endpoints and set default values to false
- Added new entries for `GetCustomers`, `GetInvited`, `GetInvitedBy`, `GetOrders`, `GetServices`, `GetSlots`, and `GetSubscriptionHistory` with default values set to false.
- Removed the `Login` entry from the previous configuration, ensuring clarity in the query time-to-live settings.
2025-10-08 12:14:51 +03:00
vchikalkin
7fe1b89f5b Update PageHeader component to conditionally hide BackButton based on environment and TMA status
- Modified the logic in the PageHeader component to hide the BackButton when in production or when the TMA status is 'simple', improving user experience by reducing unnecessary navigation options.
2025-10-07 19:31:40 +03:00
vchikalkin
4a98ac5d3e Update middleware matcher to exclude 'offer' from routing
- Modified the middleware configuration to exclude the 'offer' path from the matcher, ensuring that requests to this route are handled appropriately.
2025-10-07 19:26:36 +03:00
vchikalkin
f8d0b7619f fix build 2025-10-07 19:17:31 +03:00
Vlad Chikalkin
0b64d8086c
Feature/documents pages (#118)
* apps/web: add generic privacy & offer pages

* Update environment variables and enhance offer and privacy pages

- Added `OFFER_URL` and `SUPPORT_TELEGRAM_URL` to environment variable configuration for better flexibility.
- Updated the offer page to dynamically link to the offer URL and improved contact information presentation with a direct link to the support Telegram.
- Revised the privacy policy page to reflect the service name and updated contact details, ensuring clarity and consistency in communication.

* move offer & privacy -> (documents) sub directory

* Update offer and privacy pages to include user consent for third-party data sharing

- Added a clause in the offer page requiring users to ensure consent from third parties when adding their contact information.
- Updated the privacy policy to clarify that users can share third-party data, emphasizing the need for consent for data processing within the service.

* Add privacy agreement and update environment variables

- Introduced `PRIVACY_URL` to the environment configuration for dynamic linking.
- Updated localization files to include a user consent agreement for sharing phone numbers, linking to the offer and privacy URLs.
- Enhanced welcome and contact addition messages to incorporate the new consent clause, improving user clarity on data handling.

* Refactor phone agreement localization and enhance user consent messaging

- Updated the Russian localization file to streamline the phone sharing agreement, improving clarity on user consent for data processing.
- Modified the contact addition and welcome messages to incorporate the new agreement format, ensuring users are informed about their consent to share personal data.

* Enhance Russian localization and update message formatting

- Added a new payment agreement clause in the Russian localization file, clarifying user consent for payments.
- Updated message formatting in the contact addition and subscription processes to support HTML parsing, improving message presentation and user experience.
- Incorporated the new payment agreement into the subscription flow, ensuring users are informed about their consent to the terms.

* Refactor Russian localization for contact agreements and enhance user consent messaging

- Updated the Russian localization file to separate and clarify the phone sharing and contact sharing agreements, improving user understanding of consent requirements.
- Modified the contact addition and welcome messages to utilize the new agreement format, ensuring users are informed about their consent to share personal data in a more structured manner.

* Enhance Russian localization and add document handling features

- Updated the Russian localization file to include new entries for privacy policy and public offer documents, improving user access to important information.
- Added 'documents' command to the bot's command list, allowing users to easily access document-related features.
- Integrated document handling in the main menu and handlers, enhancing user experience and navigation within the bot.
2025-10-07 19:13:41 +03:00
vchikalkin
458a06a620 Refactor async components to synchronous functions for improved performance
- Converted several async components to synchronous functions, including `Layout`, `AddOrdersPage`, `ProfilePage`, `SlotPage`, and `ServicePage`, enhancing rendering efficiency.
- Removed unnecessary prefetching logic and hydration boundaries, simplifying component structure and improving maintainability.
- Updated the `TelegramProvider` to return null during the initial mount instead of a loading message, streamlining the loading state handling.
- Enhanced loading state management in order-related components by adding loading spinners and data not found alerts, improving user experience during data fetching.
2025-10-07 13:28:40 +03:00
vchikalkin
c7648e8bf9 Enhance contact management by adding surname input and updating customer handling
- Introduced a new input for capturing the surname of the user during contact addition.
- Updated the contact parsing logic to include surname alongside name and phone number.
- Modified the customer creation and update processes to accommodate surname, ensuring full name is used in confirmation messages.
- Adjusted localization files to reflect the new surname input prompt and updated confirmation messages.
- Refactored components to utilize a unified method for retrieving full customer names, improving consistency across the application.
2025-10-07 12:36:03 +03:00
vchikalkin
9244eaec26 2025-10-07 11:25:59 +03:00
vchikalkin
d109d50120 Add QuickAppointment component to profile page and integrate Radix UI Drawer
- Introduced a new `QuickAppointment` component for scheduling appointments directly from the profile page.
- Integrated the `QuickAppointment` component into the profile layout, allowing users to book appointments with a selected master or client.
- Implemented a Radix UI Drawer for the appointment booking interface, enhancing user experience with a modal-like interaction.
- Updated `pnpm-lock.yaml` and `package.json` to include new dependencies for the Radix UI components and the `vaul` library.
2025-10-07 11:04:56 +03:00
vchikalkin
8aaae245a7 Refactor Apollo Client setup by removing createLink function
- Updated the `createApolloClient` function to directly handle authorization headers and GraphQL URI configuration, improving modularity and reducing complexity.
- Removed the `createLink` function, streamlining the client setup process and enhancing maintainability.
- Renamed type `Parameters` to `Parameters_` for clarity in the client function signature.
2025-10-07 10:14:09 +03:00
vchikalkin
c4b76a4755 docker-compose: comment healthcheck 2025-10-06 23:46:33 +03:00
vchikalkin
cb4763e32b env(cache-proxy): fix missing REDIS_HOST 2025-10-06 23:34:56 +03:00
Vlad Chikalkin
2836153887
Feature/caching (#117)
* Refactor GraphQL client usage in services to improve consistency

- Replaced direct calls to `getClientWithToken` with a new method `getGraphQLClient` across multiple services, ensuring a unified approach to obtaining the GraphQL client.
- Updated the `BaseService` to manage the GraphQL client instance, enhancing performance by reusing the client when available.

* Refactor UpdateProfile component to use useClientOnce for initial profile update

- Replaced useEffect with useClientOnce to handle the first login profile update more efficiently.
- Removed local state management for hasUpdated, simplifying the component logic.
- Updated localStorage handling to ensure the profile update occurs only on the first login.

* Refactor Apollo Client setup to improve modularity and maintainability

- Introduced a new `createLink` function to encapsulate the link creation logic for Apollo Client.
- Updated `createApolloClient` to utilize the new `createLink` function, enhancing code organization.
- Simplified the handling of authorization headers by moving it to the link configuration.

* Add cache-proxy application with initial setup and configuration

- Created a new cache-proxy application using NestJS, including essential files such as Dockerfile, .gitignore, and .eslintrc.js.
- Implemented core application structure with AppModule, ProxyModule, and ProxyController for handling GraphQL requests.
- Configured caching with Redis and established environment variable management using Zod for validation.
- Added utility functions for query handling and time management, enhancing the application's functionality.
- Included README.md for project documentation and setup instructions.

* Add cache-proxy service to Docker configurations and update deployment workflow</message>

<message>
- Introduced a new cache-proxy service in both `docker-compose.dev.yml` and `docker-compose.yml`, with dependencies on Redis and integration into the web and bot services.
- Updated GitHub Actions workflow to include build and push steps for the cache-proxy image, ensuring it is deployed alongside web and bot services.
- Modified environment variable management to accommodate the cache-proxy, enhancing the overall deployment process.
- Adjusted GraphQL cached URL to point to the cache-proxy service for improved request handling.

* Add health check endpoint and controller to cache-proxy service

- Implemented a new HealthController in the cache-proxy application to provide a health check endpoint at `/api/health`, returning a simple status response.
- Updated the AppModule to include the HealthController, ensuring it is registered within the application.
- Configured a health check in the Docker Compose file for the cache-proxy service, allowing for automated health monitoring.

* Update proxy controller and environment variable for cache-proxy service

- Changed the route prefix of the ProxyController from `/proxy` to `/api` to align with the new API structure.
- Updated the default value of the `URL_GRAPHQL_CACHED` environment variable to reflect the new route, ensuring proper integration with the GraphQL service.

* Update cache proxy configuration for query time-to-live settings

- Increased the time-to-live for `GetCustomer`, `GetOrder`, `GetService`, and `GetSlot` queries to 24 hours, enhancing cache efficiency and performance.
- Maintained the existing setting for `GetSubscriptions`, which remains at 12 hours.

* Enhance subscription management and configuration settings

- Added new query time-to-live settings for `GetSlotsOrders`, `GetSubscriptionPrices`, and `GetSubscriptions` to improve caching strategy.
- Implemented `hasTrialSubscription` method in `SubscriptionsService` to check for trial subscriptions based on user history, enhancing subscription management capabilities.
- Updated GraphQL operations to reflect the change from `getSubscriptionSettings` to `GetSubscriptionSettings`, ensuring consistency in naming conventions.

* fix build

* Refactor subscription settings naming

- Updated the naming of `getSubscriptionSettings` to `GetSubscriptionSettings` in the cache-proxy configuration for consistency with other settings.
2025-10-06 23:26:03 +03:00
vchikalkin
1c669f04dd optimize: skip has getSubscription request if user has no subscriptions 2025-09-27 16:52:14 +03:00
vchikalkin
047a9b1956 hide TryFreeButton if user had any subscription 2025-09-27 16:42:13 +03:00
vchikalkin
d9e67bf4ba Refactor registration feature to improve reply handling
- Updated the registration feature to use KEYBOARD_REMOVE before sending the support message, enhancing user interaction flow.
- Ensured consistent reply structure by replacing direct message returns with await calls for better asynchronous handling.
2025-09-20 12:44:27 +03:00
vchikalkin
80d29af1b4 Update registration and welcome features to use mainMenu for replies
- Modified the registration feature to replace KEYBOARD_REMOVE with mainMenu in reply messages.
- Updated the welcome feature to use mainMenu instead of combining messages for a cleaner response structure.
2025-09-20 12:11:08 +03:00
vchikalkin
d191be03e8 Refactor welcome feature to use RegistrationService for customer retrieval
- Replaced CustomersService with RegistrationService in the welcome feature to streamline customer data retrieval.
- Updated the command handler to ensure proper integration with the new service.
2025-09-20 11:58:04 +03:00
vchikalkin
900cfe2cc2 Enhance subscription handling in bot and GraphQL API
- Updated the `createOrUpdateSubscription` method in the SubscriptionsService to accept an optional `paymentId` parameter for better tracking of payment transactions.
- Modified the bot's subscription feature to pass the `provider_payment_charge_id` when creating or updating subscriptions, improving payment processing accuracy.
2025-09-20 11:51:19 +03:00
vchikalkin
1f168df095 Refactor ProPage and improve back button logic
- Removed the unused PageHeader component from ProPage for a cleaner layout.
- Updated the isRootLevelPage function to enhance path exclusion logic, ensuring it correctly identifies root level pages.
2025-09-19 16:21:12 +03:00
vchikalkin
3e0ac818f2 bot(priceButtons): продлить/доступ 2025-09-18 19:41:05 +03:00
vchikalkin
29ecc47822 Fix logic in isRootLevelPage function to correctly identify root level pages 2025-09-18 19:31:27 +03:00
vchikalkin
86f0d87c31 Refactor subscription logic to remove unused trial subscription variable
- Eliminated the `usedTrialSubscription` variable from the subscription function.
- Updated the subscription period condition to directly reference `GQL.Enum_Subscriptionprice_Period.Trial` for clarity.
2025-09-18 19:18:58 +03:00
vchikalkin
a9fd9808ec shorter msg-invalid-phone 2025-09-18 19:06:02 +03:00
vchikalkin
31adf7e7b3 Update Russian localization and enhance contact addition flow
- Changed terminology from "клиент" to "пользователь" for consistency in user interactions.
- Updated messages to clarify user instructions for adding contacts and handling phone numbers.
- Added validation to prevent users from adding their own phone number as a contact.
- Improved conversation prompts for better user experience during contact addition.
2025-09-18 19:00:35 +03:00
vchikalkin
ec3c2869c1 Update bot features and localization
- Added new buttons and messages in Russian localization for improved user interaction.
- Integrated '@grammyjs/menu' version 1.3.1 to enhance menu functionality.
- Refactored bot command handlers to streamline conversation flows and improve code organization.
- Updated the main menu structure to include new options for adding contacts and subscription information.
2025-09-18 18:09:35 +03:00
vchikalkin
24aabae434 Enhance ProPage: Add subscription pricing display and update layout
- Integrated subscription pricing information by fetching active subscription prices and displaying them on the ProPage.
- Adjusted layout margins for improved visual consistency in the header and benefits sections.
- Enhanced user experience by conditionally rendering the pricing section based on available subscription prices.
2025-09-18 15:47:45 +03:00
vchikalkin
81e0168e44 Enhance ProPage: Update bot URL handling for trial subscriptions
- Introduced a new URL construction for the bot link, incorporating a 'start' parameter set to 'pro' for improved trial subscription management.
- Updated the link in the ProPage to utilize the newly constructed bot URL, ensuring users are directed correctly for Pro access through the bot.
2025-09-18 15:30:06 +03:00
vchikalkin
eb0ad25c3c fix back-button on /pro 2025-09-18 15:12:58 +03:00
vchikalkin
7c7ddcf0d5 typo: Pro Доступ 2025-09-18 14:17:14 +03:00
vchikalkin
106fdc0da5 refactor(profile): simplify profile page structure and enhance loading states
- Removed unnecessary data fetching and hydration logic from the main profile page.
- Updated the rendering of components to improve clarity and performance.
- Enhanced loading states in various profile components for better user experience.
- Refactored service list handling to utilize telegramId instead of masterId for consistency.
2025-09-18 14:02:10 +03:00
vchikalkin
a669e1846e fix(web): profile page getSubscriptionSettings queryKey 2025-09-18 13:10:36 +03:00
vchikalkin
8092c7fecc hotfix(auth): missing session 2025-09-18 12:51:20 +03:00
Vlad Chikalkin
363fce4499
Feature/pro subscription (#103)
* feat(profile): add subscription information to profile page

- Integrated `SubscriptionInfoBar` component into the profile page for displaying subscription details.
- Updated GraphQL types to include subscription-related fields and filters.
- Enhanced the profile data management by adding subscription handling capabilities.
- Added a new utility function `getRemainingDays` to calculate remaining days until a specified date.

* refactor(tests): remove BOT_TOKEN from environment mocks in order and slots tests

- Eliminated the hardcoded BOT_TOKEN from the environment mock in both orders.test.js and slots.test.js to streamline test configurations and improve security practices.

* feat(env): add BOT_URL to environment variables and update related configurations

- Introduced BOT_URL to the environment schema for enhanced configuration management.
- Updated turbo.json to include BOT_URL in the environment variables list.
- Modified subscription-bar.tsx to improve user messaging for subscription availability.

* feat(pro-page): use next/link

* feat(pro-page): enhance subscription messaging and add benefits section

- Updated subscription status messaging for clarity and conciseness.
- Improved button styling based on trial availability.
- Added a new benefits section for non-active subscribers, highlighting key features of the Pro subscription.

* fix(pro-page): adjust hero section layout for improved visual consistency

- Reduced margin in the hero section to enhance alignment and overall aesthetics of the Pro page.

* feat(subscriptions): add trial subscription functionality

- Implemented `createTrialSubscription` action in the API for initiating trial subscriptions.
- Enhanced the Pro page to include a `TryFreeButton` for users to activate their trial.
- Updated GraphQL operations and types to support trial subscription features.
- Improved subscription messaging and user experience across relevant components.

* refactor(pro-page): streamline ProPage layout and improve bottom navigation visibility

- Consolidated the main container for the ProPage to enhance layout consistency.
- Updated the BottomNav component to conditionally hide on the Pro page, improving navigation clarity for users.

* 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.

* style(pro-page, subscription-bar): enhance dark mode support and improve styling consistency

- Updated gradient backgrounds in ProPage and SubscriptionInfoBar to support dark mode variations.
- Refactored class names for better conditional styling based on subscription activity.
- Improved text color handling for better readability in both active and inactive states.

* feat(orders, subscriptions): implement banned user checks and improve remaining orders calculation

- Added `checkIsBanned` method calls in the `createOrder`, `getOrder`, `getOrders`, and `updateOrder` methods of the `OrdersService` to prevent actions from banned users.
- Updated the calculation of `remainingOrdersCount` in the `SubscriptionsService` to ensure it does not go below zero, enhancing subscription management accuracy.

* feat(subscriptions): enhance error handling with centralized error messages

- Introduced a centralized `ERRORS` object in the `subscriptions.ts` file to standardize error messages related to trial subscriptions.
- Updated error handling in the `createSubscription` method to utilize the new error messages, improving maintainability and clarity for subscription-related errors.

* feat(orders): implement order limit checks for clients and masters

- Added order limit validation in the `OrdersService` to check if a master has reached their monthly order limit.
- Introduced new error messages for exceeding order limits, enhancing user feedback for both clients and masters.
- Integrated `SubscriptionsService` to manage subscription status and remaining order counts effectively.

* order-card: fix order_number badge overlays navigation bar

* fix(docker-compose): update healthcheck endpoint to include API path

* feat(profile): add MasterServicesList component to display services for profile masters

- Introduced the MasterServicesList component to show services associated with a master profile.
- Updated ProfilePage to conditionally render MasterServicesList based on user role.
- Refactored services fetching logic into a new useMasterServices hook for better reusability.

* feat(profile): conditionally render SubscriptionInfoBar based on user role

- Updated ProfilePage to check if the user is a master and conditionally render the SubscriptionInfoBar component.
- Refactored customer fetching logic to include a utility function for determining user role.

* fix tests

* fix(typo): rename updateSlot to updateOrder for clarity

* refactor(contact): remove customer master role checks and simplify contact addition

- Updated the `addContact` function to allow all users to add contacts, removing the previous restriction that only masters could do so.
- Deleted the `become-master` feature and related utility functions, streamlining the codebase.
- Adjusted command settings to reflect the removal of the master role functionality.
- Refactored components and hooks to eliminate dependencies on the master role, enhancing user experience and simplifying logic.

* refactor(contacts): rename masters to invited and update related functionality

- Changed the terminology from "masters" to "invited" and "invitedBy" across the codebase for clarity and consistency.
- Updated the `addContact` function to reflect the new naming convention.
- Refactored API actions and server methods to support the new invited structure.
- Adjusted components and hooks to utilize the updated invited data, enhancing user experience and simplifying logic.

* feat(profile): enhance user role checks in subscription and links components

- Added conditional rendering in SubscriptionInfoBar and LinksCard to hide components for users with the Client role.
- Updated ProfileDataCard to use Enum_Customer_Role for role management.
- Improved error handling in OrdersService to differentiate between master and client order limit errors.

* refactor(contacts): update grid components and improve customer role handling

- Renamed InvitedByGrid to MastersGrid and InvitedGrid to ClientsGrid for clarity.
- Enhanced customer role checks by using documentId for identifying the current user.
- Updated the contacts passed to grid components to reflect the new naming and role structure.
- Adjusted titles in grid components for better user experience.

* feat(order): enhance order initialization logic with additional client selection step

- Added a new step for client selection in the order initialization process when only a masterId is present.
- Disabled cognitive complexity checks for improved code maintainability.

* feat(contacts): add showServices prop to ContactRow for conditional rendering

- Updated ContactsList to pass showServices prop to ContactRow.
- Modified ContactRow to conditionally render services based on the showServices prop, enhancing the display of contact information.

* feat(contacts): add DataNotFound component for empty states in contacts and services grids

- Integrated DataNotFound component to display a message when no contacts or services are found in the respective grids.
- Enhanced loading state handling in ServicesSelect and ScheduleCalendar components to improve user experience during data fetching.

* feat(contacts): enhance contact display and improve user experience

- Updated ContactsList to include a description prop in ContactRow for better service representation.
- Renamed header in OrderContacts from "Контакты" to "Участники" for clarity.
- Replaced Avatar components with UserAvatar in various components for consistent user representation.
- Filtered active contacts in MastersGrid and ClientsGrid to improve data handling.
- Adjusted customer query logic to ensure proper handling of telegramId.

* feat(customers): add getCustomers API and enhance customer queries

- Introduced getCustomers action and corresponding server method to fetch customer data with pagination and sorting.
- Updated hooks to support infinite querying of customers, improving data handling in components.
- Refactored ContactsList and related components to utilize the new customer fetching logic, enhancing user experience.
- Adjusted filter labels in dropdowns for better clarity and user understanding.

* refactor(contacts): consolidate customer queries and enhance contact handling

- Replaced use of useCustomersInfiniteQuery with a new useContactsInfiniteQuery hook for improved data fetching.
- Simplified ContactsList and MastersGrid components by removing unnecessary customer documentId filters.
- Deleted outdated contact-related hooks and queries to streamline the codebase.
- Enhanced loading state management across components for better user experience.

* fix(avatar): update UserAvatar sizes for consistency across components

- Changed UserAvatar size from 'xl' to 'lg' in PersonCard for better alignment with design.
- Adjusted UserAvatar size from 'sm' to 'xs' in OrderCard to ensure uniformity in avatar presentation.
- Updated sizeClasses in UserAvatar component to reflect the new 'xs' size, enhancing responsiveness.

* fix(auth): ensure telegramId is a string for consistent handling

- Updated the signIn calls in both Auth and useAuth functions to convert telegramId to a string.
- Modified the JWT callback to store telegramId as a string in the token.
- Enhanced session handling to correctly assign telegramId from the token to the session user.
- Added type definitions for telegramId in next-auth to ensure proper type handling.

* fix(auth): handle unregistered users in authentication flow

- Updated the authentication logic in both Auth and useAuth functions to redirect unregistered users to the '/unregistered' page.
- Enhanced error handling in the authOptions to check for user registration status using the Telegram ID.
- Improved the matcher configuration in middleware to exclude the '/unregistered' route from authentication checks.

* feat(subscriptions): add SubscriptionRewardFields and update related types

- Introduced SubscriptionRewardFields fragment to encapsulate reward-related data for subscriptions.
- Updated CustomerFiltersInput and SubscriptionHistoryFiltersInput to include subscription_rewards for enhanced filtering capabilities.
- Added SubscriptionRewardFiltersInput and SubscriptionRewardInput types to support reward management in subscriptions.
- Modified existing fragments and queries to reflect the new structure and ensure consistency across the codebase.

* test payment

* feat(subscriptions): refactor subscription handling and update related queries

- Renamed `hasUserTrialSubscription` to `usedTrialSubscription` for clarity in the SubscriptionsService.
- Updated subscription-related queries and fragments to use `active` instead of `isActive` for consistency.
- Enhanced the ProPage component to utilize the new subscription checks and improve trial usage logic.
- Removed unused subscription history query to streamline the codebase.
- Adjusted the SubscriptionInfoBar to reflect the new subscription state handling.

* feat(subscriptions): update subscription messages and enhance bot functionality

- Renamed `msg-subscribe-active-until` to `msg-subscription-active-until` for consistency in localization.
- Added `msg-subscription-active-days` to inform users about remaining subscription days.
- Refactored subscription handling in the bot to utilize updated subscription checks and improve user messaging.
- Enhanced conversation flow by integrating chat action for typing indication during subscription interactions.

* feat(subscriptions): enhance subscription handling and localization updates

- Added new message `msg-subscribe-disabled` to inform users when their subscription is disabled.
- Updated `msg-subscription-active-days` to ensure proper localization formatting.
- Refactored subscription command in the bot to check for subscription status and respond accordingly.
- Enhanced ProfilePage to conditionally render the SubscriptionInfoBar based on subscription status.
- Updated GraphQL types and queries to include `proEnabled` for better subscription management.

* feat(bot): enhance conversation handling by removing redundant typing indication

- Added a chat action for 'typing' indication at the start of the bot's conversation flow.
- Removed the redundant 'typing' action from individual conversation handlers to streamline the code.

* feat(localization): update Russian localization with support contact and message adjustments

- Added a new support contact message for user inquiries.
- Refactored existing messages to utilize the new support contact variable for consistency.
- Cleaned up redundant messages and ensured proper localization formatting across various sections.

* feat(localization): add Pro subscription information and update command list

- Introduced new localization entry for Pro subscription information.
- Updated command list to include 'pro' command for better user guidance.
- Enhanced existing subscription messages for clarity and consistency.

* feat(localization): update Pro access terminology and enhance subscription messages

- Replaced instances of "подписка" with "доступ" to clarify Pro access terminology.
- Updated subscription-related messages for improved user understanding and consistency.
- Enhanced command list and bot responses to reflect changes in Pro access messaging.

* feat(subscriptions): enhance subscription flow and localization updates

- Updated default locale to Russian for improved user experience.
- Refactored subscription messages to include expiration dates and active subscription status.
- Enhanced keyboard display for subscription options with clear expiration information.
- Improved handling of subscription-related queries and responses for better clarity.

* update support contact

* update bot description

* .github\workflows\deploy.yml: add BOT_PROVIDER_TOKEN
2025-09-17 14:46:17 +03:00
Vlad Chikalkin
3d0f74ef62
Hotfix/bot registraion add contact (#99)
* refactor(registration): remove checkBanStatus method and related logic

* fix(BaseService): streamline customer permission checks by consolidating conditions

* bot: remove logger from context

* refactor(bot): update conversation handling and middleware integration

- Replaced the previous conversations middleware with the Grammy framework's implementation.
- Introduced a loop to register custom conversations, enhancing the bot's conversation management capabilities.
- Removed the addContact feature implementation from the add-contact file, streamlining the codebase.

* feat(bot): add cancel command to conversation middleware

- Implemented a '/cancel' command in the bot's conversation middleware to allow users to exit all conversations gracefully.
- Removed the manual cancellation check from the addContact conversation, streamlining the code and improving user experience.

* fix(bot): conversations register - disable minification in build configuration
2025-09-07 16:36:31 +03:00
Vlad Chikalkin
0934417aaf
Fix/rc 1 (#89)
* Revert "packages(apps/web): upgrade next@15.5.0"

This reverts commit 22e4f72ee6e36834672e44a25acf8a5797dcca8c.

* docker-compose: add volumes

* Update Dockerfiles to install specific version of turbo (2.3.2) for consistent dependency management

* .github\workflows\deploy.yml: remove REDIS_PASSWORD env variable

* Update deploy.yml to add REDIS_PASSWORD environment variable for improved configuration management

* Reapply "packages(apps/web): upgrade next@15.5.0"

This reverts commit bcb9be88dfd1b57d6ce6f47bedca4aa3e8db0eae.

* refactor(bot): remove Redis integration from bot configuration

- Eliminated Redis instance and related storage client from the bot's configuration, streamlining the setup and reducing dependencies.
- Updated bot middleware to enhance performance and maintainability.

* Revert "refactor(bot): remove Redis integration from bot configuration"

This reverts commit 4fbbccb0a2967af0c92ff19fe337467347d9a91a.

* docker compose: format

* bot: fix production run (logger problem)

* docker-compose: add app network to redis
2025-08-27 11:37:15 +03:00
Vlad Chikalkin
81fa32c3d2
Release/rc 1 (#87)
* feat(profile): implement local hooks for profile and service data editing

- Added `useProfileEdit` and `useServiceEdit` hooks to manage pending changes and save functionality for profile and service data cards.
- Updated `ProfileDataCard` and `ServiceDataCard` components to utilize these hooks, enhancing user experience with save and cancel options.
- Introduced buttons for saving and canceling changes, improving the overall interactivity of the forms.
- Refactored input handling to use `updateField` for better state management.

* feat(bot): integrate Redis and update bot configuration

- Added Redis service to both docker-compose files for local development and production environments.
- Updated bot configuration to utilize the Grammy framework, replacing Telegraf.
- Implemented graceful shutdown for the bot, ensuring proper resource management.
- Refactored bot commands and removed deprecated message handling logic.
- Enhanced environment variable management for Redis connection settings.
- Updated dependencies in package.json to include new Grammy-related packages.

* fix(registration): improve error handling for customer creation

- Updated error handling in the registration feature to return a generic error message when documentId is not present, enhancing user experience by providing clearer feedback.

* feat(bot): add unhandled command message and integrate unhandled feature

- Introduced a new message for unhandled commands in Russian localization to improve user feedback.
- Integrated the unhandled feature into the bot's middleware for better command handling.

* feat(locales): update Russian localization with additional contact information

- Enhanced the short description in the Russian localization file to include a contact note for user inquiries, improving user support accessibility.

* feat(help): enhance help command with support information

- Updated the help command to include a support message in the Russian localization, providing users with a contact point for inquiries.
- Improved the command response by combining the list of available commands with the new support information, enhancing user experience.

* fix(orders): update default sorting order for orders

- Changed the default sorting order for orders from 'datetime_start:asc' to 'datetime_start:desc' to ensure the most recent orders are displayed first, improving the user experience in order management.

* refactor(orders): remove ClientsOrdersList and streamline OrdersList component

- Eliminated the ClientsOrdersList component to simplify the orders page structure.
- Updated OrdersList to handle both client and master views, enhancing code reusability.
- Improved order fetching logic and UI rendering for better performance and user experience.

* fix(order-form): hide next button on success & error pages

* refactor(bot): streamline bot middleware and improve key generator function

- Removed unused session middleware and sequentialize function from the bot's error boundary.
- Simplified the key generator function for rate limiting by condensing its implementation.
- Enhanced overall code clarity and maintainability in the bot's configuration.

* feat(customer): implement banned customer check and enhance customer data handling

- Added `isCustomerBanned` function to determine if a customer is banned based on the `bannedUntil` field.
- Updated the `BaseService` to throw an error if a banned customer attempts to access certain functionalities.
- Enhanced the GraphQL operations to include the `bannedUntil` field in customer queries and mutations, improving data integrity and user experience.
- Integrated the `CheckBanned` component in the layout to manage banned customer states effectively.

* feat(ban-system): implement multi-level user ban checks across services

- Added a comprehensive ban checking system to prevent access for banned users at multiple levels, including database, API, and client-side.
- Introduced `bannedUntil` field in the customer model to manage temporary and permanent bans effectively.
- Enhanced `BaseService` and various service classes to include ban checks, ensuring that banned users cannot perform actions or access data.
- Updated error handling to provide consistent feedback for banned users across the application.
- Improved user experience with a dedicated ban check component and a user-friendly ban notification page.

* packages(apps/web): upgrade next@15.5.0
2025-08-26 13:23:52 +03:00
vchikalkin
2e849857f2 feat(number-field): add min prop to NumberField and implement minimum value validation in ServiceDataCard
- Introduced a `min` prop to the NumberField component to enforce minimum value constraints.
- Updated ServiceDataCard to set the minimum price to 0, enhancing input validation for service pricing.
2025-08-20 17:57:12 +03:00
vchikalkin
c52e991e3f fix build 2025-08-20 17:47:47 +03:00
vchikalkin
3f7d1526da fix(service-card): remove unnecessary padding from expand button for improved layout 2025-08-20 17:35:10 +03:00
vchikalkin
7960323c0a fix(service-card): improve expand button visibility logic for service description
- Added logic to determine when to show the expand button based on description length and line breaks.
- Enhanced user experience by ensuring the button appears only when necessary, improving readability of service descriptions.
2025-08-20 17:31:15 +03:00
vchikalkin
540145d80a feat(service-card): add price and description fields to service data card
- Introduced NumberField for price input and TextareaField for service description in the ServiceDataCard component.
- Updated ServiceCard component to display the new description and price fields, enhancing service details visibility.
- Added formatMoney utility for consistent currency formatting across the application.
- Updated GraphQL fragments and types to include price and description fields for services.
2025-08-20 17:22:51 +03:00
vchikalkin
6ba18cb87d refactor(order-card): enhance layout and styling for order state display
- Updated the layout of the OrderCard component to improve responsiveness and visual clarity.
- Adjusted flex properties for better alignment and spacing of elements.
- Moved the order state badge into a dedicated div for improved styling control.
2025-08-19 19:45:54 +03:00
vchikalkin
64dfec1355 refactor(order-form): update service handling to support multiple services
- Renamed `ServiceSelect` to `ServicesSelect` for clarity.
- Updated state management to handle multiple service IDs instead of a single service ID.
- Adjusted related components (`DateSelect`, `TimeSelect`, `SubmitButton`, and `NextButton`) to accommodate the new services structure.
- Removed the deprecated `service-select.tsx` file and refactored related logic in the order store and API to support multiple services.
- Enhanced error handling in the slots service to validate multiple services correctly.
2025-08-19 19:14:14 +03:00
vchikalkin
b7554b89c8 .gitignore: add *.cmd 2025-08-19 12:09:57 +03:00
vchikalkin
b44d92cef3 Update Docker images in docker-compose and GitHub Actions workflow to use dynamic tags
- Changed Docker image references in docker-compose.yml to utilize environment variables for versioning.
- Updated GitHub Actions workflow to generate and use dynamic image tags based on the commit SHA for both web and bot images.
- Ensured that the .env file is populated with the new image tags during the deployment process.
2025-08-15 21:15:10 +03:00
Vlad Chikalkin
7d94521c8b
Issues/76 (#77)
* fix(jwt): update import path for isTokenExpired function to remove file extension

* packages/graphql: add slot tests

* fix(slots): update error handling for customer and slot retrieval, enhance time validation in slot updates

* fix(slots): update error messages for missing datetime fields and improve validation logic in slot updates

* fix(slots): update error messages and validation logic for slot creation and updates, including handling of datetime fields and master status

* refactor(slots): rename checkUpdateIsTimeChanging to checkUpdateDatetime for clarity in slot update validation

* test(slots): add comprehensive tests for getAvailableTimeSlots method, including edge cases and error handling

* fix(api): standardize error messages for customer and slot retrieval, and improve validation logic in slots service

* refactor(slots): rename validation methods for clarity and consistency in slot service

* OrdersService: add checkBeforeCreate

* add orders.test.js

* test(orders): add validation test for missing datetime_end in order creation

* feat(orders): implement updateOrder functionality with comprehensive validation tests

- Added updateOrder method in OrdersService with checks for permissions, order state, and datetime validation.
- Implemented tests for various scenarios including successful updates, permission errors, and validation failures.
- Enhanced error handling for overlapping time and invalid state changes.
- Updated GraphQL operations to support sorting in GetOrders query.

* fix(orders): update datetime validation logic and test cases for order creation and completion

- Modified order creation tests to set datetime_start to one hour in the past for past orders.
- Updated the OrdersService to use isNowOrAfter for validating order completion against the start time.
- Enhanced datetime utility function to accept a unit parameter for more flexible comparisons.

* fix(calendar): initialize selected date in ScheduleCalendar component if not set

- Added useEffect to set the selected date to the current date if it is not already defined.
- Imported useEffect alongside useState for managing component lifecycle.

* fix(order-form): initialize selected date in DateSelect component if not set

- Added useEffect to set the selected date to the current date if it is not already defined.
- Renamed setDate to setSelectedDate for clarity in state management.

* refactor(orders): streamline order creation logic and enhance test setup

- Removed redundant variable assignments in the createOrder method for cleaner code.
- Updated test setup in orders.test.js to use global mocks for user and service retrieval, improving test clarity and maintainability.
- Added checks for required fields in order creation to ensure data integrity.
2025-08-11 16:25:14 +03:00
vchikalkin
ba88305bbf feat(orders, slots, schedule): enhance order and slot button functionality with date validation and conditional rendering 2025-08-02 20:40:09 +03:00
vchikalkin
ee6ccbef84 feat(slots): add error handling for slot deletion when orders are present 2025-08-02 19:28:38 +03:00
vchikalkin
6c4e6113f6 refactor(api): replace CustomerProfile with UserProfile and streamline user retrieval across services 2025-08-02 18:53:23 +03:00
vchikalkin
25fb9269fc refactor(calendar): comment out past date disabling logic for calendar component; refactor day slots list to improve slot display and add conditional rendering for add form 2025-08-02 18:07:00 +03:00
Vlad Chikalkin
ed197143d6
Feature/tma back button (#70)
* feat(layout): integrate TelegramProvider and BackButton into main layout for enhanced navigation

* refactor(layout): remove BackButton from main layout and update navigation imports

* use ui back button for non tma mode
2025-08-02 15:42:06 +03:00
vchikalkin
278da049a5 refactor(service-card): add text truncation to service name for improved layout 2025-08-02 11:11:29 +03:00
vchikalkin
9061c6eda3 feat(slots): add time validation to prevent past slot selection 2025-08-02 11:07:18 +03:00
Vlad Chikalkin
10981e2afb
Issues/66 (#67)
* feat(profile): add 'Услуги' link button to LinksCard for service management

* feat(services): add create and update service functionalities with corresponding API actions and hooks
2025-08-01 19:54:10 +03:00
Vlad Chikalkin
fde9305632
Fix/bugs features pt 3 (#64)
* chore(docker): add healthcheck to service in docker-compose.yml and update deploy workflow to include docker compose down

* refactor(orders): add useOrdersInfiniteQuery for improved pagination and add load more button in orders list components

* refactor(graphql): remove NotifyService and related notification logic from orders and API, clean up unused dependencies

* refactor(api): streamline customer, order, service, and slot actions by wrapping server functions with client action utility to rethrow error messages to client
2025-07-23 13:15:08 +03:00
vchikalkin
ae0e7cc1a7 refactor(orders-list): replace HorizontalCalendar with Calendar component and update date selection logic for improved clarity and functionality 2025-07-19 16:52:52 +03:00
Vlad Chikalkin
ccfc65ca9b
Fix/bugs features pt 2 (#58)
* refactor(profile): comment out change role feature

* refactor(orders): update OrderServices and ServiceSelect components to utilize ServiceCard, and enhance service fields with duration in GraphQL types

* refactor(schedule): implement forbidden order states to disable editing slots with active orders

* fix(deploy): update SSH configuration to use dynamic port from secrets for improved flexibility

* refactor(api/orders): simplify order creation logic by removing unnecessary validations and improving error handling

* refactor(contact-row): replace role display logic with useIsMaster hook for improved clarity

* refactor(profile/orders-list): update header text from "Общие записи" to "Недавние записи" for better clarity
gql: GetOrders add sort slot.date:desc

* refactor(profile/orders-list): enhance OrderCard component by adding avatarSource prop based on user role

* feat(order-form): implement date selection with event highlighting and monthly view for available time slots

* refactor(i18n/config): update timeZone from 'Europe/Amsterdam' to 'Europe/Moscow'

* refactor(order-form/datetime-select): enhance date selection logic to include slot availability check

* refactor(datetime-format): integrate dayjs timezone support with default Moscow timezone for date and time formatting

* fix(contact-row): replace useIsMaster hook with isCustomerMaster utility for role display logic

* refactor(service-card): replace formatTime with getMinutes for duration display

* refactor(order-datetime): update date and time handling to use datetime_start and datetime_end for improved consistency

* refactor(profile): streamline profile and slot pages by integrating session user retrieval and updating booking logic with BookButton component

* fix(navigation): append query parameter to bottom-nav links and enhance back navigation logic in success page
2025-07-18 17:11:43 +03:00
Vlad Chikalkin
1075e47904
Update message.ts 2025-07-04 10:08:05 +03:00
vchikalkin
6a8804abb1 refactor(api/notify): format orderCreated method parameters for improved readability 2025-07-03 22:52:16 +03:00
vchikalkin
53af172e34 feat(api/notify): enhance order creation notifications with dynamic emoji and confirmation text based on creator role 2025-07-03 22:51:03 +03:00
vchikalkin
cc91c5cb30 feat(api/notify): update notification messages with dynamic emojis based on order state 2025-07-03 22:44:28 +03:00
vchikalkin
686fe60b80 feat(api/orders): add validation to prevent masters from recording other masters as clients 2025-07-03 22:31:41 +03:00
vchikalkin
1e4e4aa336 fix(bot): improve text clarity in messages and commands list 2025-07-03 22:03:09 +03:00
vchikalkin
1c295a4b41 refactor(bot): add comments 2025-07-03 21:36:44 +03:00
vchikalkin
d9b054df14 feat(bot): add phone number validation and error handling for contact messages
set active: true after full registration
2025-07-03 21:30:17 +03:00
vchikalkin
ac897a77f8 chore(docker-compose): remove build context and dockerfile references for web and bot services 2025-07-03 20:55:50 +03:00
vchikalkin
9efa022cd6 fix build 2025-07-03 20:54:08 +03:00
vchikalkin
33a20b9f2e refactor(bot): replace CustomersService with RegistrationService for customer management 2025-07-03 19:44:36 +03:00
vchikalkin
d41194f177 fix(bot): streamline customer creation logic by checking for existing customer before creating a new one 2025-07-03 19:02:25 +03:00
vchikalkin
28e88e02aa fix(bot): remove extra newline in commands list for improved formatting 2025-07-03 18:19:44 +03:00
vchikalkin
8feb0d3c05 feat(bot): add profile editing prompt to commands list 2025-07-03 18:03:33 +03:00
vchikalkin
339fff1879 fix(api/orders): refine permission checks for order access based on client and master roles 2025-07-03 17:23:36 +03:00
vchikalkin
c8bf3d9358 deploy: add BOT_URL 2025-07-03 16:51:46 +03:00
Vlad Chikalkin
7bcae12d54
Fix/bugs after first release (#26)
Some checks failed
Build & Deploy Web & Bot / Build and Push to Docker Hub (push) Has been cancelled
Build & Deploy Web & Bot / Deploy to VPS (push) Has been cancelled
* web/packages: upgrade next

* fix(api/orders): update master validation logic to handle optional masters

* fix(api/notify, api/orders): enhance notification messages and update order state handling for masters

* fix react typings

* refactor(order-buttons, action-panel): streamline button handlers and add return functionality

* fix(contacts, orders): replace empty state messages with DataNotFound component for better user feedback

* feat(bot): add share bot command and update environment configuration for BOT_URL

* fix: pnpm-lock.yaml

* feat(bot): implement add contact wizard scene and enhance contact handling logic

* feat(profile): add BookContactButton component to enhance booking functionality

* fix(order-buttons): update cancel and confirm button logic based on order state

* feat(service-select): share services list for all
enhance service card display with duration formatting and improve layout
2025-07-03 16:36:10 +03:00
252 changed files with 18141 additions and 3962 deletions

View File

@ -1,19 +1,43 @@
name: Build & Deploy Web & Bot
name: Build & Deploy Web, Bot & Cache Proxy
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build-and-push:
name: Build and Push to Docker Hub
runs-on: ubuntu-latest
outputs:
web_tag: ${{ steps.vars.outputs.web_tag }}
bot_tag: ${{ steps.vars.outputs.bot_tag }}
cache_proxy_tag: ${{ steps.vars.outputs.cache_proxy_tag }}
# Добавляем output-ы для отслеживания, какие проекты были собраны
web_built: ${{ steps.filter.outputs.web }}
bot_built: ${{ steps.filter.outputs.bot }}
cache_proxy_built: ${{ steps.filter.outputs.cache_proxy }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create fake .env file for build
# --- НОВОЕ: Шаг 1: dorny/paths-filter для условной сборки ---
- name: Filter changed paths
uses: dorny/paths-filter@v2
id: filter
with:
filters: |
web:
- 'apps/web/**'
- 'packages/**'
bot:
- 'apps/bot/**'
- 'packages/**'
cache_proxy:
- 'apps/cache-proxy/**'
# -----------------------------------------------------------
- name: Create .env file for build
run: |
echo "BOT_TOKEN=fake" > .env
echo "LOGIN_GRAPHQL=fake" >> .env
@ -21,25 +45,55 @@ jobs:
echo "URL_GRAPHQL=http://localhost/graphql" >> .env
echo "EMAIL_GRAPHQL=fake@example.com" >> .env
echo "NEXTAUTH_SECRET=fakesecret" >> .env
echo "BOT_URL=http://localhost:3000" >> .env
echo "REDIS_PASSWORD=fake" >> .env
echo "BOT_PROVIDER_TOKEN=fake" >> .env
echo "SUPPORT_TELEGRAM_URL=${{ secrets.SUPPORT_TELEGRAM_URL }}" >> .env
echo "URL_OFFER=${{ secrets.URL_OFFER }}" >> .env
echo "URL_PRIVACY=${{ secrets.URL_PRIVACY }}" >> .env
echo "URL_FAQ=${{ secrets.URL_FAQ }}" >> .env
- name: Set image tags
id: vars
run: |
echo "web_tag=web-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
echo "bot_tag=bot-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
echo "cache_proxy_tag=cache-proxy-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
# --- ИЗМЕНЕНО: Условное выполнение Build/Push ---
- name: Build web image
if: steps.filter.outputs.web == 'true'
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-web:latest -f ./apps/web/Dockerfile .
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-web:${{ steps.vars.outputs.web_tag }} -f ./apps/web/Dockerfile .
- name: Push web image to Docker Hub
if: steps.filter.outputs.web == 'true'
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-web:latest
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-web:${{ steps.vars.outputs.web_tag }}
- name: Build bot image
if: steps.filter.outputs.bot == 'true'
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-bot:latest -f ./apps/bot/Dockerfile .
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-bot:${{ steps.vars.outputs.bot_tag }} -f ./apps/bot/Dockerfile .
- name: Push bot image to Docker Hub
if: steps.filter.outputs.bot == 'true'
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-bot:latest
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-bot:${{ steps.vars.outputs.bot_tag }}
- name: Build cache-proxy image
if: steps.filter.outputs.cache_proxy == 'true'
run: |
docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-cache-proxy:${{ steps.vars.outputs.cache_proxy_tag }} -f ./apps/cache-proxy/Dockerfile .
- name: Push cache-proxy image to Docker Hub
if: steps.filter.outputs.cache_proxy == 'true'
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/zapishis-cache-proxy:${{ steps.vars.outputs.cache_proxy_tag }}
# -------------------------------------------------
deploy:
name: Deploy to VPS
@ -55,46 +109,119 @@ jobs:
mkdir -p ~/.ssh
echo "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.VPS_HOST }} >> ~/.ssh/known_hosts
ssh-keyscan -p ${{ secrets.VPS_PORT }} -H ${{ secrets.VPS_HOST }} >> ~/.ssh/known_hosts
- name: Ensure zapishis directory exists on VPS
run: |
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} "mkdir -p /home/${{ secrets.VPS_USER }}/zapishis"
ssh -i ~/.ssh/id_rsa -p ${{ secrets.VPS_PORT }} -o StrictHostKeyChecking=no ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} "mkdir -p /home/${{ secrets.VPS_USER }}/zapishis"
- name: Create real .env file for production
# --- НОВОЕ: Шаг 2: Создание основного .env БЕЗ ТЕГОВ ---
- name: Create .env file for deploy
run: |
# Включаем все секреты, КРОМЕ тегов
echo "BOT_TOKEN=${{ secrets.BOT_TOKEN }}" > .env
echo "LOGIN_GRAPHQL=${{ secrets.LOGIN_GRAPHQL }}" >> .env
echo "PASSWORD_GRAPHQL=${{ secrets.PASSWORD_GRAPHQL }}" >> .env
echo "URL_GRAPHQL=${{ secrets.URL_GRAPHQL }}" >> .env
echo "EMAIL_GRAPHQL=${{ secrets.EMAIL_GRAPHQL }}" >> .env
echo "NEXTAUTH_SECRET=${{ secrets.NEXTAUTH_SECRET }}" >> .env
echo "BOT_URL=${{ secrets.BOT_URL }}" >> .env
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" >> .env
echo "REDIS_PASSWORD=${{ secrets.REDIS_PASSWORD }}" >> .env
echo "BOT_PROVIDER_TOKEN=${{ secrets.BOT_PROVIDER_TOKEN }}" >> .env
echo "SUPPORT_TELEGRAM_URL=${{ secrets.SUPPORT_TELEGRAM_URL }}" >> .env
echo "URL_OFFER=${{ secrets.URL_OFFER }}" >> .env
echo "URL_PRIVACY=${{ secrets.URL_PRIVACY }}" >> .env
echo "URL_FAQ=${{ secrets.URL_FAQ }}" >> .env
- name: Copy .env to VPS via SCP
# --- НОВОЕ: Шаг 3: Создание файлов тегов (.project.env) ---
- name: Create Project Tag Env Files
run: |
# Создаем файлы, которые будут содержать только одну переменную с тегом
echo "WEB_IMAGE_TAG=${{ needs.build-and-push.outputs.web_tag }}" > .env.web
echo "BOT_IMAGE_TAG=${{ needs.build-and-push.outputs.bot_tag }}" > .env.bot
echo "CACHE_PROXY_IMAGE_TAG=${{ needs.build-and-push.outputs.cache_proxy_tag }}" > .env.cache-proxy
# --- Шаг 4: Копирование .env и УСЛОВНОЕ копирование тегов ---
# Копируем основной .env всегда
- name: Copy .env to VPS via SCP (Always)
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: 22
port: ${{ secrets.VPS_PORT }}
source: '.env'
target: '/home/${{ secrets.VPS_USER }}/zapishis/'
# Копируем .env.web ТОЛЬКО, если web был собран (обновляем тег на VPS)
- name: Copy .env.web to VPS
if: ${{ needs.build-and-push.outputs.web_built == 'true' }}
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}
source: '.env.web'
target: '/home/${{ secrets.VPS_USER }}/zapishis/'
# Копируем .env.bot ТОЛЬКО, если bot был собран
- name: Copy .env.bot to VPS
if: ${{ needs.build-and-push.outputs.bot_built == 'true' }}
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}
source: '.env.bot'
target: '/home/${{ secrets.VPS_USER }}/zapishis/'
# Копируем .env.cache-proxy ТОЛЬКО, если cache-proxy был собран
- name: Copy .env.cache-proxy to VPS
if: ${{ needs.build-and-push.outputs.cache_proxy_built == 'true' }}
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}
source: '.env.cache-proxy'
target: '/home/${{ secrets.VPS_USER }}/zapishis/'
- name: Copy docker-compose.yml to VPS via SCP
uses: appleboy/scp-action@master
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
port: 22
port: ${{ secrets.VPS_PORT }}
source: 'docker-compose.yml'
target: '/home/${{ secrets.VPS_USER }}/zapishis/'
# --- ФИНАЛЬНЫЙ ДЕПЛОЙ ---
- name: Login and deploy on VPS
run: |
ssh ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} "
ssh -i ~/.ssh/id_rsa -p ${{ secrets.VPS_PORT }} -o StrictHostKeyChecking=no ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} "
cd /home/${{ secrets.VPS_USER }}/zapishis && \
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} && \
docker compose pull && \
# 1. Объединение ВСЕХ ENV-файлов в один основной .env
# Теги из .env.web/.env.bot переопределят любые старые/пустые значения,
# и .env станет полным и актуальным.
echo \"Merging environment files into .env...\" && \
cat .env .env.web .env.bot .env.cache-proxy > .temp_env && \
mv .temp_env .env && \
# 2. Логин
docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }}
# 3. Pull ВСЕХ сервисов (Docker Compose автоматически использует обновленный .env)
echo \"Pulling all services...\" && \
docker compose pull
# 4. Перезапуск
docker compose down && \
docker compose up -d
"

1
.gitignore vendored
View File

@ -36,3 +36,4 @@ yarn-error.log*
# Misc
.DS_Store
*.pem
*.cmd

View File

@ -11,7 +11,7 @@ ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN apk add --no-cache libc6-compat && \
corepack enable && \
pnpm install turbo dotenv-cli --global
pnpm install turbo@2.3.2 dotenv-cli --global
FROM base AS pruner
ARG PROJECT

View File

@ -5,5 +5,10 @@ export default [
...typescript,
{
ignores: ['**/types/**', '*.config.*'],
rules: {
'@typescript-eslint/naming-convention': 'off',
'unicorn/prevent-abbreviations': 'off',
'canonical/id-match': 'off',
},
},
];

148
apps/bot/locales/ru.ftl Normal file
View File

@ -0,0 +1,148 @@
# Общие
-support-contact = По всем вопросам и обратной связи: @v_dev_support
# Описание бота
short-description =
Запись к мастерам, тренерам и репетиторам на вашем смартфоне 📱📅
{ -support-contact }
description =
📲 Запишись.онлайн — это встроенное в Telegram приложение + бот для мастеров и тренеров в вашем смартфоне.
Возможности:
• 📅 Ведение графика и запись клиентов
• 👥 Клиентская база в одном месте
• 🔔 Уведомления о новых и предстоящих записях
• 🧑‍ Работа мастером или тренером прямо в Telegram
• 🚀 Создание записи на услугу в пару кликов
✨ Всё, что нужно — ваш смартфон.
{ -support-contact }
# Команды
start =
.description = Запуск бота
addcontact =
.description = Добавить контакт
sharebot =
.description = Поделиться ботом
subscribe =
.description = Приобрести Pro доступ
pro =
.description = Информация о вашем Pro доступе
help =
.description = Список команд и поддержка
commands-list =
📋 Доступные команды:
• /addcontact — добавить контакт
• /sharebot — поделиться ботом
• /subscribe — приобрести Pro доступ
• /pro — информация о вашем Pro доступе
• /help — список команд
Откройте приложение кнопкой "Открыть", чтобы отредактировать свой профиль или создать запись
support =
{ -support-contact }
documents =
.description = Документы
# Кнопки
btn-add-contact = 👤 Добавить контакт
btn-share-bot = 🤝 Поделиться ботом
btn-pro = 👑 Pro доступ
btn-subscribe = 👑 Приобрести Pro
btn-pro-info = Мой Pro доступ
btn-open-app = 📱 Открыть приложение
btn-faq = 📖 Инструкция
btn-documents = 📋 Документы
btn-back = ◀️ Назад
# Согласие
share-phone-agreement =
<i> Нажимая кнопку <b>«Отправить номер телефона»</b></i>,
<i>вы:
- соглашаетесь с <a href='{ $offerUrl }'>Публичной офертой</a>
- подтверждаете согласие на обработку персональных данных согласно <a href='{ $privacyUrl }'>Политике конфиденциальности</a></i>
share-contact-agreement =
<i> Отправляя контакт, имя и номер телефона, вы подтверждаете, что имеете согласие этого человека на передачу его контактных данных и на их обработку в рамках нашего сервиса.
(Пункт 4.5 <a href='{ $privacyUrl }'>Политики конфиденциальности</a>)</i>
payment-agreement =
Совершая оплату, вы соглашаетесь с <a href='{ $offerUrl }'>Публичной офертой</a>
agreement-links =
<a href='{ $offerUrl }'>Публичная оферта</a>
<a href='{ $privacyUrl }'>Политика конфиденциальности</a>
# Приветственные сообщения
msg-welcome =
👋 Добро пожаловать!
Пожалуйста, поделитесь своим номером телефона для регистрации
msg-welcome-back = 👋 С возвращением, { $name }!
# Сообщения о телефоне
msg-need-phone = 📱 Чтобы добавить контакт, сначала поделитесь своим номером телефона.
msg-phone-saved =
✅ Спасибо! Мы сохранили ваш номер телефона
Теперь вы можете открыть приложение или воспользоваться командами бота
msg-already-registered =
✅ Вы уже зарегистрированы в системе
<i>Для смены номера телефона обратитесь в поддержку (Контакты в профиле бота)</i>
msg-invalid-phone = ❌ Некорректный номер телефона. Пример: +79999999999
# Сообщения о контактах
msg-send-client-contact = 👤 Отправьте контакт пользователя, которого вы хотите добавить.
msg-send-client-contact-or-phone = 👤 Отправьте контакт пользователя или введите его номер телефона в сообщении
msg-send-contact = Пожалуйста, отправьте контакт пользователя через кнопку Telegram
msg-send-client-name = ✍️ Введите имя пользователя одним сообщением
msg-send-client-surname = ✍️ Введите фамилию пользователя одним сообщением
msg-invalid-name = ❌ Некорректное имя. Попробуйте еще раз
msg-contact-added =
✅ Добавили { $fullname } в список ваших контактов
Пригласите пользователя в приложение, чтобы вы могли добавлять с ним записи
msg-contact-forward = <i>Перешлите пользователю следующее сообщение, чтобы он мог начать пользоваться ботом ⬇️</i>
# Сообщения для шаринга
msg-share-bot =
📅 Воспользуйтесь этим ботом для записи к вашему мастеру!
Нажмите кнопку ниже, чтобы начать
# Системные сообщения
msg-cancel = ❌ Операция отменена
msg-unhandled = ❓ Неизвестная команда. Попробуйте /start
msg-cancel-operation = <i>Для отмены операции используйте команду /cancel</i>
# Ошибки
err-generic = ⚠️ Что-то пошло не так. Попробуйте еще раз через несколько секунд
err-banned = 🚫 Ваш аккаунт заблокирован
err-with-details = ❌ Произошла ошибка
{ $error }
err-limit-exceeded = 🚫 Слишком много запросов! Подождите немного
err-missing-telegram-id = ❌ Telegram ID не найден
err-cannot-add-self = ❌ Нельзя добавить свой номер телефона как контакт
# Сообщения о доступе
msg-subscribe =
👑 Pro доступ
• Разблокирует неограниченное количество заказов
msg-subscribe-success = ✅ Платеж успешно обработан!
msg-subscribe-error = ❌ Произошла ошибка при обработке платежа
msg-subscription-inactive = 🔴 Pro доступ неактивен
msg-subscription-active = 🟢 Ваш Pro доступ активен
msg-subscription-active-until = 👑 Ваш Pro доступ активен до { $date }
msg-subscription-active-days = 👑 Осталось дней вашего Pro доступа: { $days }
msg-subscription-active-days-short = Осталось дней: { $days }
msg-subscription-expired =
Ваш Pro доступ истек.
Воспользуйтесь командой /subscribe, чтобы получить неограниченное количество заказов
msg-subscribe-disabled = 🟢 Pro доступ отключен для всех. Ограничения сняты! Наслаждайтесь полным доступом! 🎉
# Информация о лимитах
msg-remaining-orders-this-month = 🧾 Доступно заказов в этом месяце: { $count }

View File

@ -12,10 +12,27 @@
"lint-staged": "lint-staged"
},
"dependencies": {
"@grammyjs/auto-chat-action": "^0.1.1",
"@grammyjs/commands": "^1.2.0",
"@grammyjs/conversations": "^2.1.0",
"@grammyjs/hydrate": "^1.6.0",
"@grammyjs/i18n": "^1.1.2",
"@grammyjs/menu": "^1.3.1",
"@grammyjs/parse-mode": "^2.2.0",
"@grammyjs/ratelimiter": "^1.2.1",
"@grammyjs/runner": "^2.0.3",
"@grammyjs/storage-redis": "^2.5.1",
"@grammyjs/types": "^3.22.1",
"@repo/graphql": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@types/node": "catalog:",
"telegraf": "catalog:",
"dayjs": "catalog:",
"grammy": "^1.38.1",
"ioredis": "^5.7.0",
"libphonenumber-js": "^1.12.24",
"pino": "^9.9.0",
"pino-pretty": "^13.1.1",
"radashi": "catalog:",
"tsup": "^8.5.0",
"typescript": "catalog:",
"zod": "catalog:"

View File

@ -0,0 +1,14 @@
import { type AutoChatActionFlavor } from '@grammyjs/auto-chat-action';
import { type CommandsFlavor } from '@grammyjs/commands';
import { type ConversationFlavor } from '@grammyjs/conversations';
import { type HydrateFlavor } from '@grammyjs/hydrate';
import { type I18nFlavor } from '@grammyjs/i18n';
import { type Context as DefaultContext, type SessionFlavor } from 'grammy';
export type Context = ConversationFlavor<
HydrateFlavor<
AutoChatActionFlavor & CommandsFlavor & DefaultContext & I18nFlavor & SessionFlavor<SessionData>
>
>;
export type SessionData = {};

View File

@ -0,0 +1,156 @@
/* eslint-disable sonarjs/cognitive-complexity */
/* eslint-disable id-length */
import { type Context } from '@/bot/context';
import { env } from '@/config/env';
import { KEYBOARD_SHARE_BOT, KEYBOARD_SHARE_PHONE } from '@/config/keyboards';
import { parseContact } from '@/utils/contact';
import { combine } from '@/utils/messages';
import { type Conversation } from '@grammyjs/conversations';
import { CustomersService } from '@repo/graphql/api/customers';
import { RegistrationService } from '@repo/graphql/api/registration';
import parsePhoneNumber from 'libphonenumber-js';
export async function addContact(conversation: Conversation<Context, Context>, ctx: Context) {
// Все пользователи могут добавлять контакты
const telegramId = ctx.from?.id;
if (!telegramId) {
return ctx.reply(await conversation.external(({ t }) => t('err-generic')));
}
const registrationService = new RegistrationService();
const { customer } = await registrationService._NOCACHE_GetCustomer({ telegramId });
if (!customer) {
return ctx.reply(
await conversation.external(({ t }) =>
combine(
t('msg-need-phone'),
t('share-phone-agreement', {
offerUrl: env.URL_OFFER,
privacyUrl: env.URL_PRIVACY,
}),
),
),
{ ...KEYBOARD_SHARE_PHONE, parse_mode: 'HTML' },
);
}
// Просим отправить контакт или номер телефона
await ctx.reply(
await conversation.external(({ t }) =>
combine(
t('msg-send-client-contact-or-phone'),
t('msg-cancel-operation'),
t('share-contact-agreement', {
offerUrl: env.URL_OFFER,
privacyUrl: env.URL_PRIVACY,
}),
),
),
{
parse_mode: 'HTML',
},
);
// Ждём первое сообщение: контакт или текст с номером
const firstCtx = await conversation.wait();
let name = '';
let surname = '';
let phone = '';
if (firstCtx.message?.contact) {
/**
* Отправлен контакт
*/
const { contact } = firstCtx.message;
const parsedContact = parseContact(contact);
const parsedPhone = parsePhoneNumber(contact.phone_number, 'RU');
name = parsedContact.name;
surname = parsedContact.surname;
if (!parsedPhone?.isValid() || !parsedPhone.number) {
return ctx.reply(await conversation.external(({ t }) => t('msg-invalid-phone')));
}
phone = parsedPhone.number;
} else if (firstCtx.message?.text) {
/**
* Номер в тексте сообщения
*/
const parsedPhone = parsePhoneNumber(firstCtx.message.text, 'RU');
if (!parsedPhone?.isValid() || !parsedPhone.number) {
return ctx.reply(await conversation.external(({ t }) => t('msg-invalid-phone')));
}
// Нельзя добавлять свой собственный номер телефона
if (customer.phone && customer.phone === parsedPhone.number) {
return ctx.reply(await conversation.external(({ t }) => t('err-cannot-add-self')));
}
phone = parsedPhone.number;
// Просим ввести имя клиента
await ctx.reply(await conversation.external(({ t }) => t('msg-send-client-name')));
const nameCtx = await conversation.wait();
const typedName = nameCtx.message?.text?.trim() || '';
if (!typedName) {
return ctx.reply(await conversation.external(({ t }) => t('msg-invalid-name')));
}
name = typedName;
// Просим ввести фамилию клиента
await ctx.reply(await conversation.external(({ t }) => t('msg-send-client-surname')));
const surnameCtx = await conversation.wait();
const typedSurname = surnameCtx.message?.text?.trim() || '';
if (!typedSurname) {
return ctx.reply(await conversation.external(({ t }) => t('msg-invalid-surname')));
}
surname = typedSurname;
} else {
return ctx.reply(await conversation.external(({ t }) => t('msg-send-client-contact-or-phone')));
}
try {
// Проверяем, есть ли клиент с таким номером
const { customer: existingCustomer } = await registrationService._NOCACHE_GetCustomer({
phone,
});
let documentId = existingCustomer?.documentId;
// Если клиента нет, создаём нового
if (!documentId) {
const createCustomerResult = await registrationService.createCustomer({
data: { name, phone, surname },
});
documentId = createCustomerResult?.createCustomer?.documentId;
if (!documentId) throw new Error('Клиент не создан');
}
// Добавляем текущего пользователя к приглашенному
const invitedBy = [customer.documentId];
const customerService = new CustomersService({ telegramId });
await customerService.addInvitedBy({ data: { invitedBy }, documentId });
// Отправляем подтверждения и инструкции
await ctx.reply(
await conversation.external(({ t }) =>
t('msg-contact-added', { fullname: [name, surname].filter(Boolean).join(' ') }),
),
);
await ctx.reply(await conversation.external(({ t }) => t('msg-contact-forward')), {
parse_mode: 'HTML',
});
await ctx.reply(await conversation.external(({ t }) => t('msg-share-bot')), KEYBOARD_SHARE_BOT);
} catch (error) {
await ctx.reply(
await conversation.external(({ t }) => t('err-with-details', { error: String(error) })),
);
}
return conversation.halt();
}

View File

@ -0,0 +1,2 @@
export * from './add-contact';
export * from './subscription';

View File

@ -0,0 +1,193 @@
/* eslint-disable id-length */
import { type Context } from '@/bot/context';
import { env } from '@/config/env';
import { formatMoney } from '@/utils/format';
import { combine } from '@/utils/messages';
import { type Conversation } from '@grammyjs/conversations';
import { fmt, i } from '@grammyjs/parse-mode';
import { CustomersService } from '@repo/graphql/api/customers';
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
import * as GQL from '@repo/graphql/types';
import { InlineKeyboard } from 'grammy';
import { sift } from 'radashi';
export async function subscription(conversation: Conversation<Context, Context>, ctx: Context) {
const telegramId = ctx.from?.id;
if (!telegramId) {
return replyError(ctx, conversation);
}
const subscriptionsService = new SubscriptionsService({ telegramId });
const {
hasActiveSubscription,
remainingDays,
subscription: currentSubscription,
} = await subscriptionsService.getSubscription({
telegramId,
});
const { subscriptionPrices } = await subscriptionsService.getSubscriptionPrices({
filters: {
active: {
eq: true,
},
period: {
ne: GQL.Enum_Subscriptionprice_Period.Trial,
},
},
});
const prices = sift(subscriptionPrices);
// строим клавиатуру с указанием даты окончания после покупки
const keyboard = buildPricesKeyboard(
prices,
currentSubscription?.expiresAt,
hasActiveSubscription,
);
// сообщение с выбором плана
const messageWithPrices = await ctx.reply(
combine(
await conversation.external(({ t }) => {
let statusLine = t('msg-subscribe');
if (hasActiveSubscription && currentSubscription?.expiresAt) {
statusLine = t('msg-subscription-active-until', {
date: new Date(currentSubscription.expiresAt).toLocaleDateString('ru-RU', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
}),
});
} else if (remainingDays) {
statusLine = t('msg-subscription-active-days', { days: remainingDays });
}
return combine(statusLine, fmt`${i}${t('msg-cancel-operation')}${i}`.text);
}),
),
{ parse_mode: 'HTML', reply_markup: keyboard },
);
// ждём выбора
const selectPlanWaitCtx = await conversation.wait();
// удаляем сообщение с выбором
try {
await ctx.api.deleteMessage(telegramId, messageWithPrices.message_id);
} catch {
/* игнорируем, если не удалось удалить */
}
const selectedPeriod = selectPlanWaitCtx.callbackQuery?.data;
if (!selectedPeriod) return replyError(ctx, conversation);
const selectedPrice = prices.find((price) => price?.period === selectedPeriod);
if (!selectedPrice) return replyError(ctx, conversation);
// создаём invoice (с указанием даты, до которой будет доступ)
const baseDate = currentSubscription?.expiresAt
? new Date(Math.max(Date.now(), new Date(currentSubscription.expiresAt).getTime()))
: new Date();
const targetDate = addDays(baseDate, selectedPrice.days ?? 0);
const targetDateRu = targetDate.toLocaleDateString('ru-RU', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
});
const agreementText = await conversation.external(({ t }) => {
return t('payment-agreement', {
offerUrl: env.URL_OFFER,
privacyUrl: env.URL_PRIVACY,
});
});
await ctx.reply(agreementText, {
parse_mode: 'HTML',
});
const customerService = new CustomersService({ telegramId });
const { customer } = await customerService.getCustomer({ telegramId });
return ctx.replyWithInvoice(
'Оплата Pro доступа',
combine(
`${selectedPrice.description || 'Pro доступ'} — до ${targetDateRu}`,
'(Автопродление отключено)',
),
JSON.stringify({ period: selectedPrice.period }),
'RUB',
[
{
amount: selectedPrice.amount * 100, // Telegram ждёт в копейках
label: `${selectedPrice.description || 'К оплате'} — до ${targetDateRu}`,
},
],
{
protect_content: true,
provider_data: JSON.stringify({
receipt: {
customer: {
phone: customer?.phone.replaceAll(/\D/gu, ''),
},
items: [
{
amount: {
currency: 'RUB',
value: selectedPrice.amount,
},
description: selectedPrice.description || 'Pro доступ',
payment_mode: 'full_payment',
payment_subject: 'payment',
quantity: 1,
vat_code: 1,
},
],
tax_system_code: 1,
},
}),
provider_token: env.BOT_PROVIDER_TOKEN,
start_parameter: 'get_access',
},
);
}
// --- helpers ---
function addDays(date: Date, days: number) {
const d = new Date(date);
d.setDate(d.getDate() + days);
return d;
}
function buildPricesKeyboard(
prices: GQL.SubscriptionPriceFieldsFragment[],
currentExpiresAt?: string,
hasActiveSubscription = false,
) {
const keyboard = new InlineKeyboard();
const baseTime = currentExpiresAt
? Math.max(Date.now(), new Date(currentExpiresAt).getTime())
: Date.now();
for (const price of prices) {
const targetDate = addDays(new Date(baseTime), price.days ?? 0);
const targetDateRu = targetDate.toLocaleDateString('ru-RU', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
});
keyboard.row({
callback_data: price.period,
pay: true,
text: `${hasActiveSubscription ? 'Продлить' : 'Доступ'} до ${targetDateRu} (${formatMoney(price.amount)})`,
});
}
return keyboard;
}
async function replyError(ctx: Context, conversation: Conversation<Context, Context>) {
return ctx.reply(await conversation.external(({ t }) => t('err-generic')));
}

View File

@ -0,0 +1,12 @@
import { handleAddContact } from '../handlers/add-contact';
import { type Context } from '@/bot/context';
import { logHandle } from '@/bot/helpers/logging';
import { Composer } from 'grammy';
const composer = new Composer<Context>();
const feature = composer.chatType('private');
feature.command('addcontact', logHandle('command-add-contact'), handleAddContact);
export { composer as addContact };

View File

@ -0,0 +1,12 @@
import { handleDocuments } from '../handlers/documents';
import { type Context } from '@/bot/context';
import { logHandle } from '@/bot/helpers/logging';
import { Composer } from 'grammy';
const composer = new Composer<Context>();
const feature = composer.chatType('private');
feature.command('documents', logHandle('command-documents'), handleDocuments);
export { composer as documents };

View File

@ -0,0 +1,14 @@
import { type Context } from '@/bot/context';
import { logHandle } from '@/bot/helpers/logging';
import { mainMenu } from '@/config/keyboards';
import { Composer } from 'grammy';
const composer = new Composer<Context>();
const feature = composer.chatType('private');
feature.command('help', logHandle('command-help'), async (ctx) => {
return ctx.reply(ctx.t('support'), { reply_markup: mainMenu });
});
export { composer as help };

View File

@ -0,0 +1,8 @@
export * from './add-contact';
export * from './documents';
export * from './help';
export * from './pro';
export * from './registration';
export * from './share-bot';
export * from './subscription';
export * from './welcome';

View File

@ -0,0 +1,11 @@
import { handlePro } from '../handlers/pro';
import { type Context } from '@/bot/context';
import { logHandle } from '@/bot/helpers/logging';
import { Composer } from 'grammy';
const composer = new Composer<Context>();
const feature = composer.chatType('private');
feature.command('pro', logHandle('command-pro'), handlePro);
export { composer as pro };

View File

@ -0,0 +1,81 @@
import { type Context } from '@/bot/context';
import { logHandle } from '@/bot/helpers/logging';
import { KEYBOARD_REMOVE, mainMenu } from '@/config/keyboards';
import { parseContact } from '@/utils/contact';
import { RegistrationService } from '@repo/graphql/api/registration';
import { Composer } from 'grammy';
import parsePhoneNumber from 'libphonenumber-js';
const composer = new Composer<Context>();
const feature = composer.chatType('private');
// Обработка получения контакта от пользователя (регистрация или обновление)
feature.on(':contact', logHandle('contact-registration'), async (ctx) => {
const telegramId = ctx.from.id;
const { contact } = ctx.message;
const { name, surname } = parseContact(contact);
// Проверяем, не зарегистрирован ли уже пользователь
const registrationService = new RegistrationService();
const { customer: existingCustomer } = await registrationService._NOCACHE_GetCustomer({
telegramId,
});
if (existingCustomer) {
return ctx.reply(ctx.t('msg-already-registered'), {
...KEYBOARD_REMOVE,
parse_mode: 'HTML',
});
}
// Проверка наличия номера телефона
if (!contact.phone_number) {
return ctx.reply(ctx.t('msg-invalid-phone'));
}
// Нормализация и валидация номера
const parsedPhone = parsePhoneNumber(contact.phone_number, 'RU');
if (!parsedPhone?.isValid() || !parsedPhone?.number) {
return ctx.reply(ctx.t('msg-invalid-phone'));
}
try {
const { customer } = await registrationService._NOCACHE_GetCustomer({
phone: parsedPhone.number,
});
if (customer && !customer.telegramId) {
// Пользователь добавлен ранее мастером — обновляем данные
await registrationService.updateCustomer({
data: { active: true, name, surname, telegramId },
documentId: customer.documentId,
});
await ctx.reply(ctx.t('msg-phone-saved'), { ...KEYBOARD_REMOVE });
return ctx.reply(ctx.t('support'), { reply_markup: mainMenu });
}
// Новый пользователь — создаём и активируем
const response = await registrationService.createCustomer({
data: { name, phone: parsedPhone.number, surname, telegramId },
});
const documentId = response?.createCustomer?.documentId;
if (!documentId) return ctx.reply(ctx.t('err-generic'));
await registrationService.updateCustomer({
data: { active: true },
documentId,
});
await ctx.reply(ctx.t('msg-phone-saved'), { ...KEYBOARD_REMOVE });
return ctx.reply(ctx.t('support'), { reply_markup: mainMenu });
} catch (error) {
return ctx.reply(ctx.t('err-with-details', { error: String(error) }));
}
});
export { composer as registration };

View File

@ -0,0 +1,12 @@
import { handleShareBot } from '../handlers/share-bot';
import { type Context } from '@/bot/context';
import { logHandle } from '@/bot/helpers/logging';
import { Composer } from 'grammy';
const composer = new Composer<Context>();
const feature = composer.chatType('private');
feature.command('sharebot', logHandle('command-share-bot'), handleShareBot);
export { composer as shareBot };

View File

@ -0,0 +1,48 @@
import { handleSubscribe } from '../handlers/subscription';
import { type Context } from '@/bot/context';
import { logHandle } from '@/bot/helpers/logging';
import { logger } from '@/utils/logger';
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
import { Composer } from 'grammy';
const composer = new Composer<Context>();
// Telegram требует отвечать на pre_checkout_query
composer.on('pre_checkout_query', logHandle('pre-checkout-query'), async (ctx) => {
await ctx.answerPreCheckoutQuery(true);
});
const feature = composer.chatType('private');
// команда для входа в flow подписки
feature.command('subscribe', logHandle('command-subscribe'), handleSubscribe);
// успешная оплата
feature.on(':successful_payment', logHandle('successful-payment'), async (ctx) => {
const telegramId = ctx.from.id;
const subscriptionsService = new SubscriptionsService({ telegramId });
try {
const rawPayload = ctx.message?.successful_payment.invoice_payload;
if (!rawPayload) throw new Error('Missing invoice payload');
const payload = JSON.parse(rawPayload);
const provider_payment_charge_id = ctx.message?.successful_payment?.provider_payment_charge_id;
const { formattedDate } = await subscriptionsService.createOrUpdateSubscription(
payload,
provider_payment_charge_id,
);
await ctx.reply(ctx.t('msg-subscribe-success'));
await ctx.reply(ctx.t('msg-subscription-active-until', { date: formattedDate }));
} catch (error) {
await ctx.reply(ctx.t('msg-subscribe-error'));
logger.error(
'Failed to process subscription after successful payment\n' + (error as Error)?.message,
);
}
});
export { composer as subscription };

View File

@ -0,0 +1,17 @@
import { type Context } from '@/bot/context';
import { logHandle } from '@/bot/helpers/logging';
import { Composer } from 'grammy';
const composer = new Composer<Context>();
const feature = composer.chatType('private');
feature.on('message', logHandle('unhandled-message'), (ctx) => {
return ctx.reply(ctx.t('msg-unhandled'));
});
feature.on('callback_query', logHandle('unhandled-callback-query'), (ctx) => {
return ctx.answerCallbackQuery();
});
export { composer as unhandledFeature };

View File

@ -0,0 +1,42 @@
import { type Context } from '@/bot/context';
import { logHandle } from '@/bot/helpers/logging';
import { env } from '@/config/env';
import { KEYBOARD_SHARE_PHONE, mainMenu } from '@/config/keyboards';
import { combine } from '@/utils/messages';
import { RegistrationService } from '@repo/graphql/api/registration';
import { Composer } from 'grammy';
const composer = new Composer<Context>();
const feature = composer.chatType('private');
feature.command('start', logHandle('command-start'), async (ctx) => {
const telegramId = ctx.from.id;
const registrationService = new RegistrationService();
const { customer } = await registrationService._NOCACHE_GetCustomer({ telegramId });
if (customer) {
// Пользователь уже зарегистрирован — приветствуем
return ctx.reply(ctx.t('msg-welcome-back', { name: customer.name }), {
reply_markup: mainMenu,
});
}
// Новый пользователь — просим поделиться номером
return ctx.reply(
combine(
ctx.t('msg-welcome'),
ctx.t('share-phone-agreement', {
offerUrl: env.URL_OFFER,
privacyUrl: env.URL_PRIVACY,
}),
),
{
...KEYBOARD_SHARE_PHONE,
parse_mode: 'HTML',
},
);
});
export { composer as welcome };

View File

@ -0,0 +1,7 @@
import { type Context } from '@/bot/context';
async function handler(ctx: Context) {
await ctx.conversation.enter('addContact');
}
export { handler as handleAddContact };

View File

@ -0,0 +1,18 @@
import { type Context } from '@/bot/context';
import { env } from '@/config/env';
import { KEYBOARD_REMOVE } from '@/config/keyboards';
async function handler(ctx: Context) {
await ctx.reply(
ctx.t('agreement-links', {
offerUrl: env.URL_OFFER,
privacyUrl: env.URL_PRIVACY,
}),
{
...KEYBOARD_REMOVE,
parse_mode: 'HTML',
},
);
}
export { handler as handleDocuments };

View File

@ -0,0 +1,19 @@
import { type Context } from '../context';
import { getUpdateInfo } from '../helpers/logging';
import { KEYBOARD_REMOVE } from '@/config/keyboards';
import { logger } from '@/utils/logger';
import { ERRORS } from '@repo/graphql/constants/errors';
import { type ErrorHandler } from 'grammy';
export const errorHandler: ErrorHandler<Context> = async (error) => {
const { ctx } = error;
const text = error.message.includes(ERRORS.NO_PERMISSION) ? 'err-banned' : 'err-generic';
await ctx.reply(ctx.t(text), { ...KEYBOARD_REMOVE, parse_mode: 'HTML' });
logger.error({
err: error.error,
update: getUpdateInfo(ctx),
});
};

View File

@ -0,0 +1,5 @@
export * from './add-contact';
export * from './documents';
export * from './pro';
export * from './share-bot';
export * from './subscription';

View File

@ -0,0 +1,41 @@
import { type Context } from '@/bot/context';
import { combine } from '@/utils/messages';
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
async function handler(ctx: Context) {
const telegramId = ctx?.from?.id;
if (!telegramId) throw new Error(ctx.t('err-missing-telegram-id'));
const subscriptionsService = new SubscriptionsService({ telegramId });
const { subscriptionSetting } = await subscriptionsService.getSubscriptionSettings();
const proEnabled = subscriptionSetting?.proEnabled;
if (!proEnabled) {
await ctx.reply(ctx.t('msg-subscribe-disabled'));
}
const { hasActiveSubscription, remainingDays, remainingOrdersCount } =
await subscriptionsService.getSubscription({ telegramId });
if (hasActiveSubscription && remainingDays > 0) {
await ctx.reply(
combine(
ctx.t('msg-subscription-active'),
ctx.t('msg-subscription-active-days-short', { days: remainingDays }),
remainingDays === 0 ? ctx.t('msg-subscription-expired') : '',
),
);
} else {
await ctx.reply(
combine(
ctx.t('msg-subscription-inactive'),
ctx.t('msg-remaining-orders-this-month', { count: remainingOrdersCount }),
remainingOrdersCount === 0 ? ctx.t('msg-subscription-expired') : '',
),
);
}
}
export { handler as handlePro };

View File

@ -0,0 +1,9 @@
import { type Context } from '@/bot/context';
import { KEYBOARD_SHARE_BOT } from '@/config/keyboards';
async function handler(ctx: Context) {
await ctx.reply(ctx.t('msg-contact-forward'), { parse_mode: 'HTML' });
await ctx.reply(ctx.t('msg-share-bot'), { ...KEYBOARD_SHARE_BOT, parse_mode: 'HTML' });
}
export { handler as handleShareBot };

View File

@ -0,0 +1,22 @@
import { type Context } from '@/bot/context';
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
async function handler(ctx: Context) {
const telegramId = ctx?.from?.id;
if (!telegramId) throw new Error(ctx.t('err-missing-telegram-id'));
const subscriptionsService = new SubscriptionsService({ telegramId });
const { subscriptionSetting } = await subscriptionsService.getSubscriptionSettings();
const proEnabled = subscriptionSetting?.proEnabled;
if (proEnabled) {
await ctx.conversation.enter('subscription');
} else {
await ctx.reply(ctx.t('msg-subscribe-disabled'));
}
}
export { handler as handleSubscribe };

View File

@ -0,0 +1,22 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { type Context } from '../context';
import { logger } from '@/utils/logger';
import { type Update } from '@grammyjs/types';
import { type Middleware } from 'grammy';
export function getUpdateInfo(context: Context): Omit<Update, 'update_id'> {
const { update_id, ...update } = context.update;
return update;
}
export function logHandle(id: string): Middleware<Context> {
return (context, next) => {
logger.info({
msg: `Handle "${id}"`,
...(id.startsWith('unhandled') ? { update: getUpdateInfo(context) } : {}),
});
return next();
};
}

14
apps/bot/src/bot/i18n.ts Normal file
View File

@ -0,0 +1,14 @@
import { type Context } from './context';
import { I18n } from '@grammyjs/i18n';
import path from 'node:path';
export const i18n = new I18n<Context>({
defaultLocale: 'ru',
directory: path.resolve(process.cwd(), 'locales'),
fluentBundleOptions: {
useIsolating: false,
},
useSession: true,
});
export const isMultipleLocales = i18n.locales.length > 1;

71
apps/bot/src/bot/index.ts Normal file
View File

@ -0,0 +1,71 @@
import { type Context } from './context';
import * as conversations from './conversations';
import * as features from './features';
import { unhandledFeature } from './features/unhandled';
import { errorHandler } from './handlers/errors';
import { i18n } from './i18n';
import * as middlewares from './middlewares';
import { setCommands, setInfo } from './settings';
import { env } from '@/config/env';
import { mainMenu } from '@/config/keyboards';
import { getRedisInstance } from '@/utils/redis';
import { autoChatAction, chatAction } from '@grammyjs/auto-chat-action';
import { createConversation, conversations as grammyConversations } from '@grammyjs/conversations';
import { hydrate } from '@grammyjs/hydrate';
import { limit } from '@grammyjs/ratelimiter';
import { Bot } from 'grammy';
type Parameters_ = {
token: string;
};
const redis = getRedisInstance();
export function createBot({ token }: Parameters_) {
const bot = new Bot<Context>(token);
bot.use(i18n);
bot.use(
limit({
keyGenerator: (ctx) => ctx.from?.id.toString(),
limit: env.RATE_LIMIT,
onLimitExceeded: async (ctx) => {
await ctx.reply(ctx.t('err-limit-exceeded'));
},
storageClient: redis,
timeFrame: env.RATE_LIMIT_TIME,
}),
);
bot.use(autoChatAction(bot.api));
bot.use(chatAction('typing'));
bot.use(grammyConversations()).command('cancel', async (ctx) => {
await ctx.conversation.exitAll();
await ctx.reply(ctx.t('msg-cancel'));
});
for (const conversation of Object.values(conversations)) {
bot.use(createConversation(conversation));
}
bot.use(mainMenu);
setInfo(bot);
setCommands(bot);
const protectedBot = bot.errorBoundary(errorHandler);
protectedBot.use(middlewares.updateLogger());
protectedBot.use(hydrate());
for (const feature of Object.values(features)) {
protectedBot.use(feature);
}
protectedBot.use(unhandledFeature);
return bot;
}

View File

@ -0,0 +1,2 @@
export * from './session';
export * from './update-logger';

View File

@ -0,0 +1,20 @@
import { type Context } from '@/bot/context';
import { TTL_SESSION } from '@/config/redis';
import { getRedisInstance } from '@/utils/redis';
import { getSessionKey } from '@/utils/session';
import { RedisAdapter } from '@grammyjs/storage-redis';
import { session as createSession, type Middleware } from 'grammy';
const storage = new RedisAdapter({
autoParseDates: true,
instance: getRedisInstance(),
ttl: TTL_SESSION,
});
export function session(): Middleware<Context> {
return createSession({
getSessionKey,
initial: () => ({}),
storage,
});
}

View File

@ -0,0 +1,35 @@
import { type Context } from '@/bot/context';
import { getUpdateInfo } from '@/bot/helpers/logging';
import { logger } from '@/utils/logger';
import { type Middleware } from 'grammy';
import { performance } from 'node:perf_hooks';
export function updateLogger(): Middleware<Context> {
return async (ctx, next) => {
ctx.api.config.use((previous, method, payload, signal) => {
logger.debug({
method,
msg: 'Bot API call',
payload,
});
return previous(method, payload, signal);
});
logger.debug({
msg: 'Update received',
update: getUpdateInfo(ctx),
});
const startTime = performance.now();
try {
return next();
} finally {
const endTime = performance.now();
logger.debug({
elapsed: endTime - startTime,
msg: 'Update processed',
});
}
};
}

View File

@ -0,0 +1,47 @@
import { type Context } from '@/bot/context';
import { i18n } from '@/bot/i18n';
import { Command, CommandGroup } from '@grammyjs/commands';
import { type LanguageCode } from '@grammyjs/types';
import { type Api, type Bot, type RawApi } from 'grammy';
export async function setCommands({ api }: Bot<Context, Api<RawApi>>) {
const commands = createCommands([
'start',
'addcontact',
'sharebot',
'help',
'subscribe',
'pro',
'documents',
]);
for (const command of commands) {
addLocalizations(command);
}
const commandsGroup = new CommandGroup().add(commands);
await commandsGroup.setCommands({ api });
}
function addLocalizations(command: Command) {
for (const locale of i18n.locales) {
command.localize(
locale as LanguageCode,
command.name,
i18n.t(locale, `${command.name}.description`),
);
}
return command;
}
function createCommand(name: string) {
return new Command(name, i18n.t('en', `${name}.description`)).addToScope({
type: 'all_private_chats',
});
}
function createCommands(names: string[]) {
return names.map((name) => createCommand(name));
}

View File

@ -0,0 +1,2 @@
export * from './commands';
export * from './info';

View File

@ -0,0 +1,10 @@
import { type Context } from '../context';
import { i18n } from '../i18n';
import { type Api, type Bot, type RawApi } from 'grammy';
export async function setInfo({ api }: Bot<Context, Api<RawApi>>) {
for (const locale of i18n.locales) {
await api.setMyDescription(i18n.t(locale, 'description'));
await api.setMyShortDescription(i18n.t(locale, 'short-description'));
}
}

View File

@ -1,8 +1,26 @@
/* eslint-disable unicorn/prevent-abbreviations */
import { z } from 'zod';
export const envSchema = z.object({
BOT_PROVIDER_TOKEN: z.string(),
BOT_TOKEN: z.string(),
BOT_URL: z.string(),
RATE_LIMIT: z
.string()
.transform((value) => Number.parseInt(value, 10))
.default('2'),
RATE_LIMIT_TIME: z
.string()
.transform((value) => Number.parseInt(value, 10))
.default('3000'),
REDIS_HOST: z.string().default('redis'),
REDIS_PASSWORD: z.string(),
REDIS_PORT: z
.string()
.transform((value) => Number.parseInt(value, 10))
.default('6379'),
URL_FAQ: z.string(),
URL_OFFER: z.string(),
URL_PRIVACY: z.string(),
});
export const env = envSchema.parse(process.env);

View File

@ -0,0 +1,73 @@
import { env } from './env';
import { type Context } from '@/bot/context';
import {
handleAddContact,
handleDocuments,
handlePro,
handleShareBot,
handleSubscribe,
} from '@/bot/handlers';
import { Menu } from '@grammyjs/menu';
import {
type InlineKeyboardMarkup,
type ReplyKeyboardMarkup,
type ReplyKeyboardRemove,
} from '@grammyjs/types';
export const KEYBOARD_SHARE_PHONE = {
reply_markup: {
keyboard: [
[
{
request_contact: true,
text: ' Отправить номер телефона',
},
],
],
one_time_keyboard: true,
} as ReplyKeyboardMarkup,
};
export const KEYBOARD_REMOVE = {
reply_markup: {
remove_keyboard: true,
} as ReplyKeyboardRemove,
};
export const KEYBOARD_SHARE_BOT = {
reply_markup: {
inline_keyboard: [
[
{
text: ' Воспользоваться ботом',
url: env.BOT_URL + '?start=new',
},
],
],
} as InlineKeyboardMarkup,
};
// Главное меню
export const mainMenu = new Menu<Context>('main-menu', { autoAnswer: true })
.text((ctx) => ctx.t('btn-add-contact'), handleAddContact)
.row()
.text((ctx) => ctx.t('btn-subscribe'), handleSubscribe)
.text((ctx) => ctx.t('btn-pro-info'), handlePro)
.row()
.text((ctx) => ctx.t('btn-share-bot'), handleShareBot)
.row()
.text((ctx) => ctx.t('btn-documents'), handleDocuments)
.row()
.url(
(ctx) => ctx.t('btn-faq'),
() => env.URL_FAQ,
)
.row()
.url(
(ctx) => ctx.t('btn-open-app'),
() => {
const botUrl = new URL(env.BOT_URL);
botUrl.searchParams.set('startapp', '');
return botUrl.toString();
},
);

View File

@ -0,0 +1 @@
export const TTL_SESSION = 5 * 60; // 5 minutes in seconds

View File

@ -1,150 +1,46 @@
/* eslint-disable canonical/id-match */
/* eslint-disable consistent-return */
import { createBot } from './bot';
import { env as environment } from './config/env';
import {
commandsList,
KEYBOARD_REMOVE,
KEYBOARD_SHARE_PHONE,
MESSAGE_NOT_MASTER,
MSG_ALREADY_MASTER,
MSG_BECOME_MASTER,
MSG_CONTACT_ADDED,
MSG_ERROR,
MSG_NEED_PHONE,
MSG_PHONE_SAVED,
MSG_SEND_CLIENT_CONTACT,
MSG_WELCOME,
MSG_WELCOME_BACK,
} from './message';
import { normalizePhoneNumber } from './utils/phone';
import { CustomersService } from '@repo/graphql/api/customers';
import { Enum_Customer_Role } from '@repo/graphql/types';
import { Telegraf } from 'telegraf';
import { message } from 'telegraf/filters';
import { logger } from './utils/logger';
import { getRedisInstance } from './utils/redis';
import { run } from '@grammyjs/runner';
const bot = new Telegraf(environment.BOT_TOKEN);
bot.start(async (context) => {
const telegramId = context.from.id;
const customerService = new CustomersService({ telegramId });
const { customer } = await customerService.getCustomer({ telegramId });
if (customer) {
return context.reply(MSG_WELCOME_BACK(customer.name) + commandsList, {
...KEYBOARD_REMOVE,
parse_mode: 'HTML',
});
}
return context.reply(MSG_WELCOME, { ...KEYBOARD_SHARE_PHONE, parse_mode: 'HTML' });
const bot = createBot({
token: environment.BOT_TOKEN,
});
bot.command('addcontact', async (context) => {
const telegramId = context.from.id;
const customerService = new CustomersService({ telegramId });
const { customer } = await customerService.getCustomer({ telegramId });
if (!customer) {
return context.reply(MSG_NEED_PHONE, { ...KEYBOARD_SHARE_PHONE, parse_mode: 'HTML' });
}
if (customer.role !== Enum_Customer_Role.Master) {
return context.reply(MESSAGE_NOT_MASTER, { parse_mode: 'HTML' });
}
return context.reply(MSG_SEND_CLIENT_CONTACT, { parse_mode: 'HTML' });
bot.catch((error) => {
logger.error('Grammy bot error:');
logger.error(`Message: ${error?.message}`);
logger.error(error.error);
});
bot.command('becomemaster', async (context) => {
const telegramId = context.from.id;
const runner = run(bot);
const redis = getRedisInstance();
const customerService = new CustomersService({ telegramId });
const { customer } = await customerService.getCustomer({ telegramId });
async function gracefulShutdown(signal: string) {
logger.info(`Received ${signal}, starting graceful shutdown...`);
if (!customer) {
return context.reply(MSG_NEED_PHONE, { ...KEYBOARD_SHARE_PHONE, parse_mode: 'HTML' });
try {
await runner.stop();
logger.info('Bot stopped');
redis.disconnect();
logger.info('Redis disconnected');
} catch (error) {
const err_ = error as Error;
logger.error('Error during graceful shutdown:' + err_.message || '');
}
}
if (customer.role === Enum_Customer_Role.Master) {
return context.reply(MSG_ALREADY_MASTER, { parse_mode: 'HTML' });
}
process.once('SIGINT', () => gracefulShutdown('SIGINT'));
process.once('SIGTERM', () => gracefulShutdown('SIGTERM'));
const response = await customerService
.updateCustomer({
data: {
role: Enum_Customer_Role.Master,
},
})
.catch((error) => {
context.reply(MSG_ERROR(error), { parse_mode: 'HTML' });
});
if (response) {
return context.reply(MSG_BECOME_MASTER, { parse_mode: 'HTML' });
}
process.on('unhandledRejection', (reason) => {
logger.error('Unhandled Rejection: ' + reason);
});
bot.on(message('contact'), async (context) => {
const telegramId = context.from.id;
const customerService = new CustomersService({ telegramId });
const { customer } = await customerService.getCustomer({ telegramId });
const isRegistration = !customer;
const { contact } = context.message;
const name = (contact.first_name || '') + ' ' + (contact.last_name || '').trim();
const phone = normalizePhoneNumber(contact.phone_number);
if (isRegistration) {
const response = await customerService
.createCustomer({
name,
phone,
telegramId: context.from.id,
})
.catch((error) => {
context.reply(MSG_ERROR(error), { parse_mode: 'HTML' });
});
if (response) {
return context.reply(MSG_PHONE_SAVED + commandsList, {
...KEYBOARD_REMOVE,
parse_mode: 'HTML',
});
}
} else {
if (customer.role !== Enum_Customer_Role.Master) {
return context.reply(MESSAGE_NOT_MASTER, { parse_mode: 'HTML' });
}
try {
const createCustomerResult = await customerService.createCustomer({ name, phone });
const documentId = createCustomerResult?.createCustomer?.documentId;
if (!documentId) {
throw new Error('Customer not created');
}
const masters = [customer.documentId];
await customerService.addMasters({
data: { masters },
documentId,
});
return context.reply(MSG_CONTACT_ADDED(name), { parse_mode: 'HTML' });
} catch (error) {
context.reply(MSG_ERROR(error), { parse_mode: 'HTML' });
}
}
process.on('uncaughtException', (error) => {
logger.error('Uncaught Exception: ' + error);
});
bot.launch();
// Enable graceful stop
process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));
logger.info('Bot started');

View File

@ -1,55 +0,0 @@
import { type ReplyKeyboardRemove } from 'telegraf/types';
export const commandsList = `
\n<b>📋 Доступные команды:</b>
<b>/addcontact</b> добавить контакт клиента
<b>/becomemaster</b> стать мастером
`;
export const KEYBOARD_SHARE_PHONE = {
reply_markup: {
keyboard: [
[
{
request_contact: true,
text: '📱 Отправить номер телефона',
},
],
],
one_time_keyboard: true,
},
};
export const KEYBOARD_REMOVE = {
reply_markup: {
remove_keyboard: true,
} as ReplyKeyboardRemove,
};
export const MESSAGE_NOT_MASTER =
'⛔️ <b>Только мастер может добавлять контакты.</b>\nСтать мастером можно на странице профиля в приложении или с помощью команды <b>/becomemaster</b>.';
export const MSG_WELCOME =
'👋 <b>Добро пожаловать!</b>\nПожалуйста, поделитесь своим номером телефона для регистрации.';
export const MSG_WELCOME_BACK = (name: string) =>
`👋 <b>С возвращением, ${name}!</b>\nЧтобы воспользоваться сервисом, откройте приложение.\n`;
export const MSG_NEED_PHONE =
'📱 <b>Чтобы добавить контакт, сначала поделитесь своим номером телефона.</b>';
export const MSG_SEND_CLIENT_CONTACT =
'👤 <b>Отправьте контакт клиента, которого вы хотите добавить.</b>';
export const MSG_ALREADY_MASTER = '🎉 <b>Вы уже являетесь мастером!</b>';
export const MSG_BECOME_MASTER = '🥳 <b>Поздравляем! Теперь вы мастер.</b>';
export const MSG_ERROR = (error?: unknown) =>
`❌ <b>Произошла ошибка.</b>\n${error ? String(error) : ''}`;
export const MSG_PHONE_SAVED =
'✅ <b>Спасибо! Мы сохранили ваш номер телефона.</b>\nТеперь вы можете открыть приложение или воспользоваться командами бота.';
export const MSG_CONTACT_ADDED = (name: string) =>
`✅ <b>Добавили контакт:</b> <b>${name}</b>\ригласите пользователя в приложение, чтобы вы могли добавлять записи с этим контактом.`;

View File

@ -0,0 +1,9 @@
import { type Contact } from '@grammyjs/types';
export function parseContact(contact: Contact) {
return {
name: contact?.first_name?.trim() || '',
phone: contact?.phone_number?.trim() || '',
surname: contact?.last_name?.trim() || '',
};
}

View File

@ -0,0 +1,4 @@
export const formatMoney = Intl.NumberFormat('ru-RU', {
currency: 'RUB',
style: 'currency',
}).format;

View File

@ -0,0 +1,19 @@
/* eslint-disable turbo/no-undeclared-env-vars */
import pino from 'pino';
const logger = pino({
transport: {
level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
options: {
colorize: true,
translateTime: true,
},
target: 'pino-pretty',
},
});
logger.info = logger.info.bind(logger);
logger.debug = logger.debug.bind(logger);
logger.error = logger.error.bind(logger);
export { logger };

View File

@ -0,0 +1,3 @@
export function combine(...messages: Array<string | undefined>) {
return messages.filter(Boolean).join('\n\n');
}

View File

@ -1,5 +0,0 @@
export function normalizePhoneNumber(phone: string): string {
const digitsOnly = phone.replaceAll(/\D/gu, '');
return `+${digitsOnly}`;
}

View File

@ -0,0 +1,23 @@
import { env } from '@/config/env';
import { logger } from '@/utils/logger';
import Redis from 'ioredis';
const instance: Redis = createRedisInstance();
export function getRedisInstance() {
if (!instance) return createRedisInstance();
return instance;
}
function createRedisInstance() {
const redis = new Redis({
host: env.REDIS_HOST,
password: env.REDIS_PASSWORD,
port: env.REDIS_PORT,
});
redis.on('error', logger.error);
return redis;
}

View File

@ -0,0 +1,5 @@
import { type Context } from '@/bot/context';
export function getSessionKey(ctx: Omit<Context, 'session'>) {
return ctx.chat?.id.toString();
}

View File

@ -0,0 +1,5 @@
import { TIKTOK_URL_REGEX } from '@/constants/regex';
export function validateTikTokUrl(url: string) {
return TIKTOK_URL_REGEX.test(url);
}

View File

@ -8,7 +8,7 @@
"moduleResolution": "Node",
"module": "CommonJS",
"paths": {
"@/*": ["./*"]
"@/*": ["./src/*"]
}
},
"include": ["."],

View File

@ -7,7 +7,7 @@ export default defineConfig({
external: ['telegraf', 'zod'],
format: 'cjs',
loader: { '.json': 'copy' },
minify: true,
minify: false,
noExternal: ['@repo'],
outDir: './dist',
sourcemap: false,

View File

@ -0,0 +1,7 @@
.git
Dockerfile
.dockerignore
node_modules
*.log
dist
README.md

View File

@ -0,0 +1,13 @@
import { typescript } from '@repo/eslint-config/typescript';
/** @type {import("eslint").Linter.Config} */
export default [
...typescript,
{
ignores: ['**/types/**', '*.config.*', '*.config.js', '.eslintrc.js'],
rules: {
'import/no-duplicates': 'off',
'import/consistent-type-specifier-style': 'off',
},
},
];

56
apps/cache-proxy/.gitignore vendored Normal file
View File

@ -0,0 +1,56 @@
# compiled output
/dist
/node_modules
/build
# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# OS
.DS_Store
# Tests
/coverage
/.nyc_output
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# temp directory
.temp
.tmp
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

View File

@ -0,0 +1,51 @@
ARG NODE_VERSION=22
ARG PROJECT=cache-proxy
# Alpine image
FROM node:${NODE_VERSION}-alpine AS alpine
RUN apk update
RUN apk add --no-cache libc6-compat
FROM alpine as base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN apk add --no-cache libc6-compat && \
corepack enable && \
pnpm install turbo@2.3.2 dotenv-cli --global
FROM base AS pruner
ARG PROJECT
WORKDIR /app
COPY . .
RUN turbo prune --scope=${PROJECT} --docker
FROM base AS builder
WORKDIR /app
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
COPY --from=pruner /app/out/pnpm-workspace.yaml ./pnpm-workspace.yaml
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm install --prod --frozen-lockfile
COPY --from=pruner /app/out/full/ .
COPY turbo.json turbo.json
COPY .env .env
RUN dotenv -e .env turbo run build --filter=${PROJECT}...
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm prune --prod --no-optional
RUN rm -rf ./**/*/src
FROM alpine AS runner
ARG PROJECT
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 appuser
USER appuser
WORKDIR /app
COPY --from=builder --chown=nodejs:nodejs /app .
WORKDIR /app/apps/${PROJECT}
CMD ["node", "dist/main.js"]

View File

@ -0,0 +1,73 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
## Description
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
## Installation
```bash
$ pnpm install
```
## Running the app
```bash
# development
$ pnpm run start
# watch mode
$ pnpm run start:dev
# production mode
$ pnpm run start:prod
```
## Test
```bash
# unit tests
$ pnpm run test
# e2e tests
$ pnpm run test:e2e
# test coverage
$ pnpm run test:cov
```
## Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
## Stay in touch
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)
## License
Nest is [MIT licensed](LICENSE).

View File

@ -0,0 +1,9 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"monorepo": true,
"compilerOptions": {
"deleteOutDir": true
}
}

View File

@ -0,0 +1,75 @@
{
"name": "cache-proxy",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"dev": "dotenv -e ../../.env.local nest start -- --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/cache-manager": "^2.2.1",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-fastify": "^10.3.3",
"@types/node": "catalog:",
"fastify": "^4.26.1",
"dotenv-cli": "catalog:",
"cache-manager": "^5.4.0",
"cache-manager-ioredis": "^2.1.0",
"ioredis": "^5.3.2",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"source-map-support": "^0.5.21",
"tsconfig-paths": "^4.2.0",
"typescript": "catalog:",
"zod": "catalog:"
},
"devDependencies": {
"@nestjs/testing": "^10.0.0",
"@repo/eslint-config": "workspace:*",
"@repo/typescript-config": "workspace:*",
"@types/jest": "^29.5.2",
"@types/supertest": "^6.0.0",
"eslint": "catalog:",
"jest": "^29.5.0",
"prettier": "catalog:",
"supertest": "^6.3.3",
"ts-jest": "29.1.1",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}

View File

@ -0,0 +1,18 @@
import { ProxyModule } from './proxy/proxy.module';
import { HealthController } from './health/health.controller';
import { Global, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
@Global()
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
ProxyModule,
],
controllers: [HealthController],
providers: [],
})
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class AppModule {}

View File

@ -0,0 +1,3 @@
import { seconds } from 'src/utils/time';
export const DEFAULT_CACHE_TTL = seconds().fromMinutes(5);

View File

@ -0,0 +1,3 @@
import envSchema from './schema/env';
export const env = envSchema.parse(process.env);

View File

@ -0,0 +1,22 @@
import { DEFAULT_CACHE_TTL } from '../constants';
import { z } from 'zod';
const envSchema = z.object({
CACHE_TTL: z
.string()
.transform((val) => Number.parseInt(val, 10))
.default(DEFAULT_CACHE_TTL.toString()),
PORT: z
.string()
.transform((val) => Number.parseInt(val, 10))
.default('5000'),
REDIS_HOST: z.string().default('redis'),
REDIS_PASSWORD: z.string(),
REDIS_PORT: z
.string()
.transform((value) => Number.parseInt(value, 10))
.default('6379'),
URL_GRAPHQL: z.string(),
});
export default envSchema;

View File

@ -0,0 +1,11 @@
import { Controller, Get } from '@nestjs/common';
@Controller('api')
export class HealthController {
@Get('health')
public health() {
return { status: 'ok' };
}
}

View File

@ -0,0 +1,15 @@
import { AppModule } from './app.module';
import { env } from './config/env';
import { NestFactory } from '@nestjs/core';
import type { NestFastifyApplication } from '@nestjs/platform-fastify';
import { FastifyAdapter } from '@nestjs/platform-fastify';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
);
await app.listen(env.PORT, '0.0.0.0');
}
bootstrap();

View File

@ -0,0 +1,16 @@
import { seconds } from 'src/utils/time';
export const queryTTL: Record<string, number | false> = {
GetCustomer: seconds().fromHours(12),
GetCustomers: false,
GetInvited: false,
GetInvitedBy: false,
GetOrders: false,
GetServices: false,
GetSlots: false,
GetSlotsOrders: false,
GetSubscriptionHistory: false,
GetSubscriptions: false,
GetSubscriptionSettings: seconds().fromHours(12),
Login: false,
};

View File

@ -0,0 +1,8 @@
import { env } from 'src/config/env';
import { queryTTL } from './config';
export function getQueryTTL(operationName: string) {
if (operationName.includes('NOCACHE')) return false;
return queryTTL[operationName] ?? env.CACHE_TTL;
}

View File

@ -0,0 +1,138 @@
import type { GQLRequest, GQLResponse } from './types';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import {
All,
Controller,
Delete,
Get,
HttpException,
HttpStatus,
Inject,
Query,
Req,
Res,
} from '@nestjs/common';
import type { Cache } from 'cache-manager';
import { FastifyReply, FastifyRequest } from 'fastify';
import { env } from 'src/config/env';
import { extractDocumentId, getQueryType } from 'src/utils/query';
import { getQueryTTL } from './lib/utils';
type RedisStore = Omit<Cache, 'set'> & {
set: (key: string, value: unknown, { ttl }: { ttl: number }) => Promise<void>;
};
@Controller('api')
export class ProxyController {
constructor(@Inject(CACHE_MANAGER) private readonly cacheManager: RedisStore) {}
@All('/graphql')
public async graphql(@Req() req: FastifyRequest, @Res() reply: FastifyReply) {
const { operationName, query, variables } = req.body as GQLRequest;
const queryType = getQueryType(query);
const key = `${operationName} ${JSON.stringify(variables)}`;
if (queryType.action === 'query') {
const cached = await this.cacheManager.get(key);
if (cached) return reply.send(cached);
}
const response = await fetch(env.URL_GRAPHQL, {
body: JSON.stringify({ operationName, query, variables }),
headers: {
Authorization: req.headers.authorization,
'Content-Type': 'application/json',
Cookie: req.headers.cookie,
},
method: req.method,
});
const data = (await response.json()) as GQLResponse;
if (!response.ok || data?.error || data?.errors?.length)
throw new HttpException(
response.statusText,
response.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
if (queryType.action === 'mutation' && queryType.entity) {
const documentId = extractDocumentId(data);
const keys = await this.cacheManager.store.keys(`*${queryType.entity}*`);
for (const key of keys) {
if (key.includes(documentId)) {
await this.cacheManager.del(key);
// console.log(`🗑 Cache invalidated (by key): ${key}`);
continue;
}
const value = await this.cacheManager.get(key);
const serialized = typeof value === 'string' ? value : JSON.stringify(value);
if (serialized?.includes(documentId)) {
await this.cacheManager.del(key);
// console.log(`🗑 Cache invalidated (by value): ${key}`);
}
}
}
const ttl = getQueryTTL(operationName);
if (queryType.action === 'query' && data && ttl !== false)
await this.cacheManager.set(key, data, { ttl });
return reply.send(data);
}
@Get('/get-queries')
public async getQueriesList(@Res() reply: FastifyReply) {
const keys: string[] = await this.cacheManager.store.keys('*');
const entries = await Promise.all(
keys.map(async (key) => {
try {
const value = await this.cacheManager.get(key);
return { key, value };
} catch (e) {
return { key, error: e.message };
}
}),
);
return reply.send(entries);
}
@Delete('/delete-query')
public async deleteQuery(@Query('queryKey') queryKey: string, @Res() reply: FastifyReply) {
try {
await this.cacheManager.del(queryKey);
return reply.send('ok');
} catch (error) {
throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Delete('/reset')
public async reset(@Res() reply: FastifyReply) {
try {
await this.cacheManager.reset();
return reply.send('ok');
} catch (error) {
throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@Get('/get-query')
public async getQueryValue(@Query('queryKey') queryKey: string, @Res() reply: FastifyReply) {
try {
const value = await this.cacheManager.get(queryKey);
return reply.send(value);
} catch (error) {
throw new HttpException(error, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -0,0 +1,22 @@
import { ProxyController } from './proxy.controller';
import { CacheModule } from '@nestjs/cache-manager';
import { Module } from '@nestjs/common';
import * as redisStore from 'cache-manager-ioredis';
import type { RedisOptions } from 'ioredis';
import { env } from 'src/config/env';
@Module({
controllers: [ProxyController],
imports: [
CacheModule.register<RedisOptions>({
host: env.REDIS_HOST,
port: env.REDIS_PORT,
store: redisStore,
ttl: env.CACHE_TTL,
password: env.REDIS_PASSWORD,
db: 1,
}),
],
})
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class ProxyModule {}

View File

@ -0,0 +1,16 @@
export type GQLRequest = {
operationName: string;
query: string;
variables: string;
};
export type GQLResponse = {
data: unknown;
error?: unknown;
errors?: unknown[];
};
export type QueryItem = {
queries: string[];
ttl: number | false;
};

View File

@ -0,0 +1,22 @@
import { GQLResponse } from 'src/proxy/types';
export function getQueryType(query: string) {
const actionMatch = query.match(/\b(query|mutation)\b/u);
const action = actionMatch ? (actionMatch[1] as 'query' | 'mutation') : null;
const entityMatch = query.match(
/\b(mutation|query)\s+\w*([A-Z][A-Za-z0-9_]+)/u,
);
const entity = entityMatch ? entityMatch[2] : null;
return { action, entity };
}
export function extractDocumentId(data: GQLResponse) {
if (!data?.data) return null;
const firstKey = Object.keys(data.data)[0];
if (!firstKey) return null;
return data.data[firstKey]?.documentId || null;
}

View File

@ -0,0 +1,13 @@
export function seconds() {
return {
fromDays(days: number) {
return days * 24 * 60 * 60;
},
fromHours(hours: number) {
return hours * 60 * 60;
},
fromMinutes(minutes: number) {
return minutes * 60;
},
};
}

View File

@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "ES2022",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"strictNullChecks": false,
"noImplicitAny": false,
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
},
"include": ["."],
"exclude": ["dist", "build", "node_modules"]
}

View File

@ -0,0 +1,240 @@
# Система проверки бана пользователей
## Обзор
Реализована многоуровневая система проверки бана пользователей, которая предотвращает доступ заблокированных пользователей к функциональности приложения.
## 1. База данных (`bannedUntil` поле)
В Strapi добавлено поле `bannedUntil` типа `datetime` в модель `Customer`:
- `null` = пользователь не забанен
- `дата в будущем` = временный бан до указанной даты
- `дата в далеком будущем` = постоянный бан
## 2. Утилита проверки (`packages/utils/src/customer.ts`)
```typescript
export function isCustomerBanned(customer: { bannedUntil?: string | null }): boolean {
return Boolean(customer.bannedUntil && new Date() < new Date(customer.bannedUntil));
}
```
## 3. Next Auth проверка (`apps/web/config/auth.ts`)
В `authorize` callback добавлена проверка бана:
```typescript
async authorize(credentials) {
const { telegramId } = credentials ?? {};
if (!telegramId) { throw new Error('Invalid Telegram ID'); }
try {
const { query } = await getClientWithToken();
const result = await query({
query: GetCustomerDocument,
variables: { telegramId: Number(telegramId) },
});
const customer = result.data.customers.at(0);
if (!customer || isCustomerBanned(customer)) {
throw new Error('User is banned or not found');
}
return { id: telegramId };
} catch (error) {
throw new Error('Authentication failed');
}
}
```
## 4. Универсальная проверка в BaseService (`packages/graphql/api/base.ts`)
Добавлен метод `checkIsBanned()` в `BaseService`:
```typescript
/**
* Универсальная проверка статуса бана пользователя
* Должна вызываться в начале каждого метода сервиса
*/
protected async checkIsBanned() {
const { query } = await getClientWithToken();
const result = await query({
query: GQL.GetCustomerDocument,
variables: this._user,
});
const customer = result.data.customers.at(0);
if (!customer) {
throw new Error(BASE_ERRORS.NOT_FOUND_CUSTOMER);
}
if (isCustomerBanned(customer)) {
throw new Error(ERRORS.NO_PERMISSION);
}
return { customer };
}
```
**Использование в сервисах:**
```typescript
async someMethod() {
await this.checkIsBanned(); // Проверка бана в начале метода
// ... остальная логика
}
```
**Обновленные сервисы:**
- ✅ `CustomersService` - все методы
- ✅ `ServicesService` - все методы
- ✅ `OrdersService` - все методы
- ✅ `SlotsService` - все методы
- ✅ `RegistrationService` - добавлена собственная проверка
**Преимущества:**
- Автоматическая проверка во всех сервисах, наследующих от BaseService
- Единая точка проверки бана
- Работает как в веб-приложении, так и в боте
- Простота добавления в новые методы
- Защита всех API методов от забаненных пользователей
## 5. Защита от изменения статуса бана (`packages/graphql/api/customers.ts` и `registration.ts`)
Пользователи не могут изменять поле `bannedUntil` самостоятельно:
```typescript
// В CustomersService
async updateCustomer(variables: Omit<VariablesOf<typeof GQL.UpdateCustomerDocument>, 'documentId'>) {
await this.checkBanStatus();
const { customer } = await this._getUser();
// Проверяем, что пользователь не пытается изменить поле bannedUntil
if (variables.data.bannedUntil !== undefined) {
throw new Error(ERRORS.NO_PERMISSION);
}
// ... остальная логика обновления
}
// В RegistrationService
async updateCustomer(variables: VariablesOf<typeof GQL.UpdateCustomerDocument>) {
// Проверяем бан для существующего пользователя
if (variables.documentId) {
const { query } = await getClientWithToken();
const result = await query({
query: GQL.GetCustomerDocument,
variables: { documentId: variables.documentId },
});
const customer = result.data.customers.at(0);
if (customer && isCustomerBanned(customer)) {
throw new Error(ERRORS.NO_PERMISSION);
}
}
if (variables.data.bannedUntil) {
throw new Error(ERRORS.NO_PERMISSION);
}
// ... остальная логика обновления
}
```
**Преимущества:**
- Пользователи не могут снять с себя бан
- Только администраторы могут изменять статус блокировки
- Дополнительный уровень безопасности
- Защита работает во всех сервисах, которые обновляют данные пользователей
- Единая ошибка `NO_PERMISSION` для всех случаев отсутствия доступа
## 6. Client-side Check (`components/auth/ban-check.tsx`)
React компонент для проверки бана на клиенте:
```typescript
export function BanCheck({ children }: Readonly<PropsWithChildren>) {
const { data: session } = useSession();
const router = useRouter();
const isBanned = useIsBanned();
useEffect(() => {
if (session?.user?.telegramId && isBanned) {
router.push('/banned');
}
}, [session?.user?.telegramId, isBanned, router]);
if (session?.user?.telegramId && isBanned) {
return null;
}
return <>{children}</>;
}
```
**Использование в layout:**
```typescript
export default function Layout({ children }: Readonly<PropsWithChildren>) {
return (
<Provider>
<BanCheck>
<UpdateProfile />
<main className="grow">{children}</main>
<BottomNav />
</BanCheck>
</Provider>
);
}
```
## 7. Hook для проверки бана (`hooks/api/customers.ts`)
```typescript
export const useIsBanned = () => {
const { data: { customer } = {} } = useCustomerQuery();
if (!customer) return false;
return isCustomerBanned(customer);
};
```
## 8. Страница для забаненных пользователей (`apps/web/app/(auth)/banned/page.tsx`)
Создана специальная страница с информацией о бане и возможностью выхода из аккаунта.
## 9. Централизованные ошибки (`packages/graphql/constants/errors.ts`)
```typescript
export const ERRORS = {
NO_PERMISSION: 'Нет доступа',
} as const;
```
## Архитектура системы
```
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Next Auth │ │ BaseService │ │ Client-side │
│ (авторизация) │ │ (API методы) │ │ (UI) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ isCustomerBanned│ │ checkBanStatus()│ │ BanCheck │
│ (утилита) │ │ (метод) │ │ (компонент) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
└───────────────────────┼───────────────────────┘
┌─────────────────────────┐
│ bannedUntil (DB) │
│ (Strapi/PostgreSQL) │
└─────────────────────────┘
```
## Преимущества системы
**Многоуровневая защита** - проверка на всех уровнях приложения
**Универсальность** - работает в веб-приложении и боте
**Простота использования** - один вызов `checkBanStatus()` в начале метода
**Безопасность** - пользователи не могут обойти бан
**UX** - понятные сообщения и страница для забаненных
**DRY принцип** - нет дублирования кода
**Легкость расширения** - просто добавить новые проверки

View File

@ -11,7 +11,7 @@ ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN apk add --no-cache libc6-compat openssl && \
corepack enable && \
pnpm install turbo dotenv-cli --global
pnpm install turbo@2.3.2 dotenv-cli --global
FROM base AS pruner
ARG PROJECT

View File

@ -1,42 +1,9 @@
'use server';
import * as customers from './server/customers';
import { wrapClientAction } from '@/utils/actions';
import { useService } from './lib/service';
import { CustomersService } from '@repo/graphql/api/customers';
const getService = useService(CustomersService);
export async function addMasters(...variables: Parameters<CustomersService['addMasters']>) {
const service = await getService();
return service.addMasters(...variables);
}
export async function createCustomer(...variables: Parameters<CustomersService['createCustomer']>) {
const service = await getService();
return service.createCustomer(...variables);
}
export async function getClients(...variables: Parameters<CustomersService['getClients']>) {
const service = await getService();
return service.getClients(...variables);
}
export async function getCustomer(...variables: Parameters<CustomersService['getCustomer']>) {
const service = await getService();
return service.getCustomer(...variables);
}
export async function getMasters(...variables: Parameters<CustomersService['getMasters']>) {
const service = await getService();
return service.getMasters(...variables);
}
export async function updateCustomer(...variables: Parameters<CustomersService['updateCustomer']>) {
const service = await getService();
return service.updateCustomer(...variables);
}
export const addInvitedBy = wrapClientAction(customers.addInvitedBy);
export const getInvited = wrapClientAction(customers.getInvited);
export const getCustomer = wrapClientAction(customers.getCustomer);
export const getCustomers = wrapClientAction(customers.getCustomers);
export const getInvitedBy = wrapClientAction(customers.getInvitedBy);
export const updateCustomer = wrapClientAction(customers.updateCustomer);

View File

@ -1,30 +1,7 @@
'use server';
import * as orders from './server/orders';
import { wrapClientAction } from '@/utils/actions';
import { useService } from './lib/service';
import { OrdersService } from '@repo/graphql/api/orders';
const getServicesService = useService(OrdersService);
export async function createOrder(...variables: Parameters<OrdersService['createOrder']>) {
const service = await getServicesService();
return service.createOrder(...variables);
}
export async function getOrder(...variables: Parameters<OrdersService['getOrder']>) {
const service = await getServicesService();
return service.getOrder(...variables);
}
export async function getOrders(...variables: Parameters<OrdersService['getOrders']>) {
const service = await getServicesService();
return service.getOrders(...variables);
}
export async function updateOrder(...variables: Parameters<OrdersService['updateOrder']>) {
const service = await getServicesService();
return service.updateOrder(...variables);
}
export const createOrder = wrapClientAction(orders.createOrder);
export const getOrder = wrapClientAction(orders.getOrder);
export const getOrders = wrapClientAction(orders.getOrders);
export const updateOrder = wrapClientAction(orders.updateOrder);

View File

@ -0,0 +1,43 @@
'use server';
import { useService } from '../lib/service';
import { wrapServerAction } from '@/utils/actions';
import { CustomersService } from '@repo/graphql/api/customers';
const getService = useService(CustomersService);
export async function addInvitedBy(...variables: Parameters<CustomersService['addInvitedBy']>) {
const service = await getService();
return wrapServerAction(() => service.addInvitedBy(...variables));
}
export async function getCustomer(...variables: Parameters<CustomersService['getCustomer']>) {
const service = await getService();
return wrapServerAction(() => service.getCustomer(...variables));
}
export async function getCustomers(...variables: Parameters<CustomersService['getCustomers']>) {
const service = await getService();
return wrapServerAction(() => service.getCustomers(...variables));
}
export async function getInvited(...variables: Parameters<CustomersService['getInvited']>) {
const service = await getService();
return wrapServerAction(() => service.getInvited(...variables));
}
export async function getInvitedBy(...variables: Parameters<CustomersService['getInvitedBy']>) {
const service = await getService();
return wrapServerAction(() => service.getInvitedBy(...variables));
}
export async function updateCustomer(...variables: Parameters<CustomersService['updateCustomer']>) {
const service = await getService();
return wrapServerAction(() => service.updateCustomer(...variables));
}

View File

@ -0,0 +1,31 @@
'use server';
import { useService } from '../lib/service';
import { wrapServerAction } from '@/utils/actions';
import { OrdersService } from '@repo/graphql/api/orders';
const getServicesService = useService(OrdersService);
export async function createOrder(...variables: Parameters<OrdersService['createOrder']>) {
const service = await getServicesService();
return wrapServerAction(() => service.createOrder(...variables));
}
export async function getOrder(...variables: Parameters<OrdersService['getOrder']>) {
const service = await getServicesService();
return wrapServerAction(() => service.getOrder(...variables));
}
export async function getOrders(...variables: Parameters<OrdersService['getOrders']>) {
const service = await getServicesService();
return wrapServerAction(() => service.getOrders(...variables));
}
export async function updateOrder(...variables: Parameters<OrdersService['updateOrder']>) {
const service = await getServicesService();
return wrapServerAction(() => service.updateOrder(...variables));
}

View File

@ -0,0 +1,31 @@
'use server';
import { useService } from '../lib/service';
import { wrapServerAction } from '@/utils/actions';
import { ServicesService } from '@repo/graphql/api/services';
const getServicesService = useService(ServicesService);
export async function createService(...variables: Parameters<ServicesService['createService']>) {
const service = await getServicesService();
return wrapServerAction(() => service.createService(...variables));
}
export async function getService(...variables: Parameters<ServicesService['getService']>) {
const service = await getServicesService();
return wrapServerAction(() => service.getService(...variables));
}
export async function getServices(...variables: Parameters<ServicesService['getServices']>) {
const service = await getServicesService();
return wrapServerAction(() => service.getServices(...variables));
}
export async function updateService(...variables: Parameters<ServicesService['updateService']>) {
const service = await getServicesService();
return wrapServerAction(() => service.updateService(...variables));
}

View File

@ -0,0 +1,45 @@
'use server';
import { useService } from '../lib/service';
import { wrapServerAction } from '@/utils/actions';
import { SlotsService } from '@repo/graphql/api/slots';
const getService = useService(SlotsService);
export async function createSlot(...variables: Parameters<SlotsService['createSlot']>) {
const service = await getService();
return wrapServerAction(() => service.createSlot(...variables));
}
export async function deleteSlot(...variables: Parameters<SlotsService['deleteSlot']>) {
const service = await getService();
return wrapServerAction(() => service.deleteSlot(...variables));
}
export async function getAvailableTimeSlots(
...variables: Parameters<SlotsService['getAvailableTimeSlots']>
) {
const service = await getService();
return wrapServerAction(() => service.getAvailableTimeSlots(...variables));
}
export async function getSlot(...variables: Parameters<SlotsService['getSlot']>) {
const service = await getService();
return wrapServerAction(() => service.getSlot(...variables));
}
export async function getSlots(...variables: Parameters<SlotsService['getSlots']>) {
const service = await getService();
return wrapServerAction(() => service.getSlots(...variables));
}
export async function updateSlot(...variables: Parameters<SlotsService['updateSlot']>) {
const service = await getService();
return wrapServerAction(() => service.updateSlot(...variables));
}

View File

@ -0,0 +1,84 @@
'use server';
import { useService } from '../lib/service';
import { wrapServerAction } from '@/utils/actions';
import { SubscriptionsService } from '@repo/graphql/api/subscriptions';
const getService = useService(SubscriptionsService);
export async function createSubscription(
...variables: Parameters<SubscriptionsService['createSubscription']>
) {
const service = await getService();
return wrapServerAction(() => service.createSubscription(...variables));
}
export async function createSubscriptionHistory(
...variables: Parameters<SubscriptionsService['createSubscriptionHistory']>
) {
const service = await getService();
return wrapServerAction(() => service.createSubscriptionHistory(...variables));
}
export async function createTrialSubscription() {
const service = await getService();
return wrapServerAction(() => service.createTrialSubscription());
}
export async function getSubscription(
...variables: Parameters<SubscriptionsService['getSubscription']>
) {
const service = await getService();
return wrapServerAction(() => service.getSubscription(...variables));
}
export async function getSubscriptionHistory(
...variables: Parameters<SubscriptionsService['getSubscriptionHistory']>
) {
const service = await getService();
return wrapServerAction(() => service.getSubscriptionHistory(...variables));
}
export async function getSubscriptionPrices(
...variables: Parameters<SubscriptionsService['getSubscriptionPrices']>
) {
const service = await getService();
return wrapServerAction(() => service.getSubscriptionPrices(...variables));
}
export async function getSubscriptions(
...variables: Parameters<SubscriptionsService['getSubscriptions']>
) {
const service = await getService();
return wrapServerAction(() => service.getSubscriptions(...variables));
}
export async function getSubscriptionSettings(
...variables: Parameters<SubscriptionsService['getSubscriptionSettings']>
) {
const service = await getService();
return wrapServerAction(() => service.getSubscriptionSettings(...variables));
}
export async function updateSubscription(
...variables: Parameters<SubscriptionsService['updateSubscription']>
) {
const service = await getService();
return wrapServerAction(() => service.updateSubscription(...variables));
}
export async function updateSubscriptionHistory(
...variables: Parameters<SubscriptionsService['updateSubscriptionHistory']>
) {
const service = await getService();
return wrapServerAction(() => service.updateSubscriptionHistory(...variables));
}

View File

@ -1,18 +1,7 @@
'use server';
import * as services from './server/services';
import { wrapClientAction } from '@/utils/actions';
import { useService } from './lib/service';
import { ServicesService } from '@repo/graphql/api/services';
const getServicesService = useService(ServicesService);
export async function getService(...variables: Parameters<ServicesService['getService']>) {
const service = await getServicesService();
return service.getService(...variables);
}
export async function getServices(...variables: Parameters<ServicesService['getServices']>) {
const service = await getServicesService();
return service.getServices(...variables);
}
export const getServices = wrapClientAction(services.getServices);
export const getService = wrapClientAction(services.getService);
export const createService = wrapClientAction(services.createService);
export const updateService = wrapClientAction(services.updateService);

View File

@ -1,44 +1,9 @@
'use server';
import * as slots from './server/slots';
import { wrapClientAction } from '@/utils/actions';
import { useService } from './lib/service';
import { SlotsService } from '@repo/graphql/api/slots';
const getService = useService(SlotsService);
export async function createSlot(...variables: Parameters<SlotsService['createSlot']>) {
const service = await getService();
return service.createSlot(...variables);
}
export async function deleteSlot(...variables: Parameters<SlotsService['deleteSlot']>) {
const service = await getService();
return service.deleteSlot(...variables);
}
export async function getAvailableTimeSlots(
...variables: Parameters<SlotsService['getAvailableTimeSlots']>
) {
const service = await getService();
return service.getAvailableTimeSlots(...variables);
}
export async function getSlot(...variables: Parameters<SlotsService['getSlot']>) {
const service = await getService();
return service.getSlot(...variables);
}
export async function getSlots(...variables: Parameters<SlotsService['getSlots']>) {
const service = await getService();
return service.getSlots(...variables);
}
export async function updateSlot(...variables: Parameters<SlotsService['updateSlot']>) {
const service = await getService();
return service.updateSlot(...variables);
}
export const getSlot = wrapClientAction(slots.getSlot);
export const getSlots = wrapClientAction(slots.getSlots);
export const createSlot = wrapClientAction(slots.createSlot);
export const updateSlot = wrapClientAction(slots.updateSlot);
export const deleteSlot = wrapClientAction(slots.deleteSlot);
export const getAvailableTimeSlots = wrapClientAction(slots.getAvailableTimeSlots);

View File

@ -0,0 +1,13 @@
import * as subscriptions from './server/subscriptions';
import { wrapClientAction } from '@/utils/actions';
export const getSubscription = wrapClientAction(subscriptions.getSubscription);
export const getSubscriptions = wrapClientAction(subscriptions.getSubscriptions);
export const getSubscriptionSettings = wrapClientAction(subscriptions.getSubscriptionSettings);
export const getSubscriptionPrices = wrapClientAction(subscriptions.getSubscriptionPrices);
export const getSubscriptionHistory = wrapClientAction(subscriptions.getSubscriptionHistory);
export const createSubscription = wrapClientAction(subscriptions.createSubscription);
export const updateSubscription = wrapClientAction(subscriptions.updateSubscription);
export const createSubscriptionHistory = wrapClientAction(subscriptions.createSubscriptionHistory);
export const updateSubscriptionHistory = wrapClientAction(subscriptions.updateSubscriptionHistory);
export const createTrialSubscription = wrapClientAction(subscriptions.createTrialSubscription);

View File

@ -2,12 +2,15 @@
import { authOptions } from '@/config/auth';
import { getServerSession } from 'next-auth/next';
import { redirect } from 'next/navigation';
export async function getSessionUser() {
const session = await getServerSession(authOptions);
const user = session?.user;
if (!user?.telegramId) throw new Error('Missing session');
if (!user?.telegramId) {
return redirect('/');
}
return user;
}

View File

@ -0,0 +1,57 @@
'use client';
import { Container } from '@/components/layout';
import { Button } from '@repo/ui/components/ui/button';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@repo/ui/components/ui/card';
import { AlertTriangle, Ban } from 'lucide-react';
import { signOut } from 'next-auth/react';
const handleSignOut = () => {
signOut({ callbackUrl: '/' });
};
export default function BannedPage() {
return (
<Container>
<div className="flex min-h-screen items-center justify-center">
<Card className="w-full max-w-md">
<CardHeader className="text-center">
<div className="mx-auto mb-4 flex size-16 items-center justify-center rounded-full bg-destructive/10">
<Ban className="size-8 text-destructive" />
</div>
<CardTitle className="text-xl">Аккаунт заблокирован</CardTitle>
<CardDescription>
Ваш аккаунт был заблокирован администратором. Для получения дополнительной информации
обратитесь в поддержку.
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="rounded-lg bg-muted p-4">
<div className="flex items-start gap-3">
<AlertTriangle className="mt-0.5 size-5 text-yellow-500" />
<div className="text-sm text-muted-foreground">
<p className="mb-1 font-medium text-foreground">Возможные причины блокировки:</p>
<ul className="list-inside list-disc space-y-1">
<li>Нарушение правил использования сервиса</li>
<li>Спам или нежелательная активность</li>
<li>Множественные жалобы от других пользователей</li>
<li>Технические проблемы с аккаунтом</li>
</ul>
</div>
</div>
</div>
<Button className="w-full" onClick={handleSignOut} variant="outline">
Выйти из аккаунта
</Button>
</CardContent>
</Card>
</div>
</Container>
);
}

View File

@ -22,7 +22,18 @@ export default function Auth() {
signIn('telegram', {
callbackUrl: '/profile',
redirect: false,
telegramId: user?.id,
telegramId: user?.id?.toString(),
}).then((result) => {
if (
result?.error &&
(result?.error?.includes('CredentialsSignin') ||
result?.error?.includes('UNREGISTERED'))
) {
// Пользователь не зарегистрирован
redirect('/unregistered');
} else if (result?.ok) {
redirect('/profile');
}
});
});
}

View File

@ -10,4 +10,6 @@ export default function Page() {
redirect(isTG ? '/telegram' : '/browser');
});
return 'Redirecting...';
}

View File

@ -1,6 +1,6 @@
import { TelegramProvider } from '@/providers/telegram';
import { type PropsWithChildren } from 'react';
export default async function Layout({ children }: Readonly<PropsWithChildren>) {
export default function Layout({ children }: Readonly<PropsWithChildren>) {
return <TelegramProvider>{children}</TelegramProvider>;
}

View File

@ -1,40 +1,79 @@
/* eslint-disable promise/prefer-await-to-then */
'use client';
import { LoadingSpinner } from '@repo/ui/components/ui/spinner';
import { initData, isMiniAppDark, useSignal } from '@telegram-apps/sdk-react';
import { signIn, useSession } from 'next-auth/react';
import { signIn, type SignInResponse, useSession } from 'next-auth/react';
import { useTheme } from 'next-themes';
import { redirect } from 'next/navigation';
import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useCallback, useEffect } from 'react';
export default function Auth() {
useTelegramTheme();
useAuth();
return null;
useTelegramAuth();
return <LoadingSpinner />;
}
function useAuth() {
/**
* Хук для авторизации пользователя через NextAuth
*/
function useTelegramAuth() {
const initDataUser = useSignal(initData.user);
const { status } = useSession();
const { data: session, status } = useSession();
const router = useRouter();
const handleSignInResult = useCallback(
(result: SignInResponse | undefined) => {
if (!result) return;
if (
result.error &&
(result.error.includes('CredentialsSignin') || result.error.includes('UNREGISTERED'))
) {
router.replace('/unregistered');
} else if (result.ok) {
router.replace('/profile');
}
},
[router],
);
useEffect(() => {
if (!initDataUser?.id) return;
const telegramId = initDataUser?.id;
if (!telegramId) return;
if (status === 'authenticated') {
redirect('/profile');
// Если telegramId есть в сессии — редирект
if (session?.user?.telegramId) {
router.replace('/profile');
} else {
// Если telegramId отсутствует — пробуем заново signIn
void signIn('telegram', {
callbackUrl: '/profile',
redirect: false,
telegramId: telegramId.toString(),
}).then(handleSignInResult);
}
return;
}
if (status === 'unauthenticated') {
signIn('telegram', {
void signIn('telegram', {
callbackUrl: '/profile',
redirect: false,
telegramId: initDataUser.id,
}).then(() => redirect('/profile'));
telegramId: telegramId.toString(),
}).then(handleSignInResult);
}
}, [initDataUser?.id, status]);
}, [initDataUser?.id, status, session?.user?.telegramId, router, handleSignInResult]);
}
/**
* Хук для установки темы из Telegram Mini App
*/
function useTelegramTheme() {
const isDark = isMiniAppDark();
const { setTheme } = useTheme();

View File

@ -0,0 +1,54 @@
import { UnregisteredClient } from './unregistered-client';
import { Container } from '@/components/layout';
import { env } from '@/config/env';
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from '@repo/ui/components/ui/card';
import { Bot, MessageCircle } from 'lucide-react';
export default function UnregisteredPage() {
return (
<Container>
<div className="flex min-h-screen items-center justify-center">
<Card className="w-full max-w-md">
<CardHeader className="text-center">
<div className="mx-auto mb-4 flex size-16 items-center justify-center rounded-full bg-blue-100 dark:bg-blue-900/20">
<Bot className="size-8 text-blue-600 dark:text-blue-400" />
</div>
<CardTitle className="text-xl">Давайте познакомимся</CardTitle>
<CardDescription>
Для использования приложения необходимо поделиться своим номером телефона с ботом
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="rounded-lg bg-muted p-4">
<div className="space-y-3">
<div className="flex items-start gap-3">
<MessageCircle className="mt-0.5 size-5 text-blue-500" />
<div className="text-sm">
<p className="mb-1 font-medium text-foreground">Как поделиться:</p>
<ol className="list-inside list-decimal space-y-1 text-muted-foreground">
<li>Вернитесь к Telegram боту</li>
<li>
Отправьте команду{' '}
<code className="rounded bg-muted px-1 py-0.5 text-xs">/start</code>
</li>
<li>Нажмите на появившуюся кнопку "Отправить номер телефона"</li>
<li>Закройте и откройте это приложение еще раз</li>
</ol>
</div>
</div>
</div>
</div>
<UnregisteredClient botUrl={env.BOT_URL} />
</CardContent>
</Card>
</div>
</Container>
);
}

View File

@ -0,0 +1,37 @@
'use client';
import { Button } from '@repo/ui/components/ui/button';
import { Bot, ExternalLink } from 'lucide-react';
import Link from 'next/link';
import { signOut } from 'next-auth/react';
type UnregisteredClientProps = {
readonly botUrl: string;
};
export function UnregisteredClient({ botUrl }: UnregisteredClientProps) {
const handleSignOut = () => {
signOut({ callbackUrl: '/' });
};
const handleRefresh = () => {
window.location.reload();
};
return (
<div className="flex flex-col gap-2">
<Button asChild className="w-full">
<Link href={botUrl} rel="noopener noreferrer" target="_blank">
<Bot className="mr-2 size-4" />
Перейти к боту
<ExternalLink className="ml-2 size-4" />
</Link>
</Button>
<Button className="w-full" onClick={handleRefresh} variant="outline">
Обновить страницу
</Button>
<Button className="w-full" onClick={handleSignOut} variant="outline">
Выйти из аккаунта
</Button>
</div>
);
}

View File

@ -0,0 +1,6 @@
import { DocumentsLayout } from '@/components/documents/layout';
import { type PropsWithChildren } from 'react';
export default function Layout({ children }: Readonly<PropsWithChildren>) {
return <DocumentsLayout title="Публичная оферта">{children}</DocumentsLayout>;
}

View File

@ -0,0 +1,99 @@
import { env } from '@/config/env';
export const metadata = {
title: 'Публичная оферта',
description: 'Публичная оферта бота / мини-приложения «Запишись.онлайн» (@zapishis_online_bot)',
};
### Договор-оферта на использование сервиса «Запишись.онлайн» (@zapishis_online_bot)
Настоящий документ является публичной офертой в соответствии с пунктом 2 статьи 437 Гражданского кодекса Российской Федерации и представляет собой предложение индивидуального предпринимателя (самозанятого) — далее именуемого «Администрация», заключить Договор на использование Сервиса (далее «Договор», «Оферта») с любым физическим лицом, принявшим условия настоящей Оферты (далее «Пользователь»).
#### 1. Термины и определения
1.1. Оферта — настоящий документ, постоянно размещенный в сети Интернет по адресу <a href={env.URL_OFFER}>{env.URL_OFFER}</a>.
1.2. Акцепт — полное и безоговорочное принятие условий Оферты Пользователем путем оплаты доступа через встроенный платежный бот ЮKassa в Telegram.
1.3. Сервис — Telegram-бот и мини-приложение, позволяющее пользователям создавать и принимать заказы, управлять расписанием и взаимодействовать друг с другом без необходимости регистрации.
1.4. Администрация — самозанятое лицо, являющееся разработчиком и правообладателем Сервиса.
1.5. Пользователь — любое физическое лицо, использующее Сервис в личных или профессиональных целях.
1.6. Доступ — право использования функционала Сервиса на определённый оплаченный период (например, неделя, месяц, год).
1.7. Оплата — денежные средства, перечисленные Пользователем через платёжный бот ЮKassa в Telegram.
#### 2. Акцепт оферты и заключение договора
2.1. Акцептом настоящей Оферты считается оплата Пользователем доступа к Сервису любым доступным способом.
2.2. С момента совершения оплаты Пользователь считается заключившим Договор с Администрацией на условиях, изложенных в настоящей Оферте.
2.3. Пользователь подтверждает, что ему понятны все условия настоящей Оферты и он принимает их без ограничений.
#### 3. Предмет договора
3.1. Администрация предоставляет Пользователю неисключительное право (доступ) на использование функционала Сервиса в пределах оплаченного периода времени.
3.2. Сервис предоставляется в онлайн-формате через Telegram-бота без установки дополнительного программного обеспечения.
3.3. Пользователь получает право использовать функционал Сервиса в личных целях, в том числе для организации и планирования заказов, встреч и тренировок.
#### 4. Порядок оплаты и использование
4.1. Оплата производится через встроенные инструменты Telegram-бота с использованием платёжной системы ЮKassa.
4.2. Комиссия платёжной системы включена в итоговую стоимость. Администрация не взимает дополнительных платежей.
4.3. Доступ активируется автоматически после успешного подтверждения оплаты.
4.4. Пользователь может продлить доступ путём повторной оплаты. Автоматическое продление не применяется.
4.5. Возврат денежных средств возможен только в случае технических ошибок, по письменному обращению на адрес поддержки.
#### 5. Права и обязанности сторон
5.1. Пользователь обязуется:
- не использовать Сервис в противоправных целях;
- не вмешиваться в работу Сервиса и не предпринимать действий, направленных на нарушение его функционирования;
- предоставлять достоверную информацию при оплате и использовании Сервиса;
- при добавлении контактов других лиц (например, клиентов, мастеров) гарантировать, что у него есть согласие этих лиц на передачу и обработку их персональных данных в рамках Сервиса;
5.2. Администрация обязуется:
- обеспечивать бесперебойную работу Сервиса, за исключением периодов технического обслуживания;
- обрабатывать персональные данные Пользователей в соответствии с Политикой конфиденциальности;
- принимать обращения и запросы Пользователей по вопросам работы Сервиса. 6. Ответственность сторон;
6.1. Сервис предоставляется «как есть». Администрация не несёт ответственности за временные сбои, потерю данных или недоступность Сервиса, возникшие по причинам, не зависящим от неё.
6.2. Пользователь несёт полную ответственность за корректность совершаемых платежей и действий, совершаемых через свой Telegram-аккаунт.
#### 7. Обработка персональных данных
7.1. Администрация обрабатывает персональные данные Пользователя в соответствии с Федеральным законом №152-ФЗ «О персональных данных» и Политикой конфиденциальности.
7.2. Использование Сервиса означает согласие Пользователя на обработку его персональных данных.
#### 8. Срок действия и расторжение договора
8.1. Договор вступает в силу с момента оплаты доступа и действует в течение оплаченного периода.
8.2. Пользователь может прекратить использование Сервиса в любое время без возврата оплаченных средств.
8.3. Администрация вправе приостановить доступ в случае нарушения Пользователем условий настоящей Оферты.
#### 9. Заключительные положения
9.1. Настоящий Договор регулируется законодательством Российской Федерации.
9.2. Все споры и разногласия решаются путём переговоров, а при недостижении соглашения — в судебном порядке по месту нахождения Администрации.
9.3. Администрация оставляет за собой право изменять условия Оферты с размещением новой редакции на сайте.
#### 10. Контакты
Если у Вас есть вопросы по настоящему договору публичной оферты персональных данных, пожалуйста, свяжитесь с Разработчиком. Контакты указаны в описании бота.

View File

@ -0,0 +1,6 @@
import { DocumentsLayout } from '@/components/documents/layout';
import { type PropsWithChildren } from 'react';
export default function Layout({ children }: Readonly<PropsWithChildren>) {
return <DocumentsLayout title="Политика конфиденциальности">{children}</DocumentsLayout>;
}

View File

@ -0,0 +1,131 @@
export const metadata = {
title: 'Политика конфиденциальности',
description:
'Политика конфиденциальности бота / мини-приложения «Запишись.онлайн» (@zapishis_online_bot)',
};
### Политика конфиденциальности бота / мини-приложения «Запишись.онлайн» (@zapishis_online_bot)
#### 1. Термины и определения
- **Telegram** Telegram Messenger Inc. (платформа, на которой работает бот и мини-приложение).
- **Платформа** экосистема ботов и мини-приложений Telegram.
- **Разработчик** физическое лицо, самозанятый, владелец и оператор сервиса «Запишись.онлайн» (@zapishis_online_bot) - (далее — «Разработчик»).
- **Сторонний сервис** бот/мини-приложение Разработчика, предоставляемое в Платформе.
- **Пользователь** лицо, использующее Сторонний сервис через свою учетную запись Telegram (далее — «Вы»).
- **Политика** настоящий документ, регулирующий отношения между Разработчиком и Пользователем в части сбора и - обработки персональных данных.
#### 2. Общие положения
2.1. Настоящая Политика регулирует исключительно отношения между Разработчиком и Пользователем. Она не заменяет и не изменяет Политику конфиденциальности Telegram: [https://telegram.org/privacy](https://telegram.org/privacy).
2.2. Разработчик соблюдает применимые требования платформы Telegram к конфиденциальности и защите данных.
2.3. Использование Сервиса Пользователем и/или активация платного доступа означает согласие Пользователя с условиями настоящей Политики.
2.4. Если Вы не согласны с условиями Политики — прекратите использование Сервиса.
#### 3. Отказ от ответственности
3.1. Сторонний сервис является независимым приложением и не поддерживается, не одобряется и не аффилирован с Telegram (за исключением использования API и инфраструктуры Telegram).
3.2. Разработчик вправе изменять настоящую Политику — изменения вступают в силу с момента их публикации. Вы обязаны самостоятельно отслеживать обновления.
3.3. Используя Сервис, Вы подтверждаете, что ознакомлены и согласны с условиями использования Telegram для ботов и мини-приложений: [https://telegram.org/tos/bots](https://telegram.org/tos/bots), [https://telegram.org/tos/mini-apps](https://telegram.org/tos/mini-apps).
3.4. Вы гарантируете, что используете Сервис в соответствии с действующим законодательством и обладаете правом взаимодействовать с ним (например, достигли возраста, необходимого для использования услуг).
3.5. Вы обязуетесь предоставлять точную и актуальную информацию, если Сервис запрашивает её.
3.6. Любая информация, которую Вы делаете общедоступной самостоятельно (через профиль Telegram, публичные сообщения и т.п.), может стать доступна другим пользователям и не подпадает под защиту настоящей Политики в части конфиденциальности этой общедоступной информации.
#### 4. Сбор персональных данных
4.1. Telegram по умолчанию предоставляет сторонним сервисам ограниченный набор данных о Пользователе — подробнее: [https://telegram.org/privacy#6-bot-messages](https://telegram.org/privacy#6-bot-messages).
4.2. Сторонний сервис может дополнительно получать данные, которые Вы передаёте в чате бота или в мини-приложении (например, контакт, телефон), если Вы явно их отправляете.
4.3. В случае мини-приложения дополнительно могут передаваться данные в соответствии с правилами мини-приложений Telegram: [https://telegram.org/tos/mini-apps#4-privacy](https://telegram.org/tos/mini-apps#4-privacy).
4.4. Сторонний сервис может собирать также анонимную статистику использования (диагностика, события взаимодействия), не связываемую напрямую с персоной.
4.5. Пользователь может передавать данные третьих лиц (например, контактные данные клиентов или мастеров) для использования в Сервисе. При этом пользователь гарантирует, что эти лица дали согласие на обработку их персональных данных в рамках Сервиса.
#### 5. Какие данные мы собираем и как используем
5.1. Разработчик запрашивает, собирает и обрабатывает только те данные, которые необходимы для корректной работы функций Сервиса, в частности:
- Telegram ID и (опционально) отображаемое имя пользователя;
- телефон, только если Вы предоставили его добровольно (например, при регистрации);
- данные о заказах: дата/время, описание заказа, статус;
- информация о факте покупки Pro-доступа: период доступа, тип покупки (детали платёжной транзакции обрабатывает платёжный оператор — ЮKassa);
5.2. Цели обработки:
- предоставление и поддержка работы Сервиса (создание заказов, напоминания, управление доступом);
- подтверждение и учет оплат (взаимодействие с платёжным оператором для актуализации статуса доступа);
- реализация реферальной программы (хранение связей «кто пригласил/кого пригласили»);
- анализ использования и улучшение сервиса;
- выполнение юридических обязательств (хранение информации о транзакциях и др.);
> **Важно:** детальные платёжные данные (реквизиты карт и т.д.) не хранятся у Разработчика — их обрабатывает платёжный оператор (ЮKassa) и Telegram-платежный бот.
#### 6. Передача данных третьим лицам
6.1. Разработчик не передаёт персональные данные третьим лицам, за исключением следующих случаев:
- платёжному оператору (ЮKassa) и связанным службам для обработки платежей;
- Telegram как платформе для функционирования бота и мини-приложения;
- в случае необходимости — исполнителям, оказывающим техническую поддержку, при условии подписания ими обязательств о конфиденциальности;
- если передача требуется по закону (запросы уполномоченных органов и т.п.);
6.2. Разработчик не продаёт и не передаёт персональные данные для рекламных целей третьим лицам без Вашего отдельного согласия.
#### 7. Защита и хранение данных
7.1. Разработчик применяет разумные технические и организационные меры для защиты персональных данных (использование надежного VPS, ограничения доступа, резервное копирование и т.п.).
7.2. Доступ к персональным данным имеет только Разработчик (и/или доверенные исполнители технической поддержки при необходимости).
7.3. Данные хранятся на серверах, указанных Разработчиком. Если используются внешние сервисы/облачные хранилища — это будет указано в соответствующих местах Политики или сообщения при сборе данных.
#### 8. Права и обязанности сторон
8.1. Права Разработчика:
- вносить изменения в Политику с публикацией новой версии;
- ограничивать доступ к API/сервису при подозрении в злоупотреблениях;
- запросить подтверждение личности при необходимости обработки привилегированных запросов;
8.2. Обязанности Разработчика:
- обеспечивать доступность Политики и исполнять её условия;
- обрабатывать законные запросы пользователей о доступе, изменении или удалении данных в разумные сроки (не позднее 30 дней, если иное не установлено законом);
- соблюдать применимое законодательство о защите персональных данных;
8.3. Права Пользователя:
- запросить копию своих персональных данных, хранящихся у Разработчика;
- потребовать исправления неточных данных;
- потребовать удаления персональных данных в пределах, допустимых законом (с сохранением данных, необходимых для выполнения юридических обязательств, например, по учёту платежей);
- отозвать согласие на обработку персональных данных, если такое согласие предоставлялось добровольно;
- подать жалобу в уполномоченные органы по защите персональных данных, если считает, что его права нарушены;
8.4. Обязанности Пользователя:
- предоставлять точную и актуальную информацию;
- не использовать Сервис в нарушении законодательства и условий Telegram.
#### 9. Реклама и использование данных для аналитики
9.1. На текущем этапе Разработчик не использует персональные данные для демонстрации таргетированной рекламы третьих лиц без явного согласия Пользователя.
9.2. Разработчик может собирать агрегированную (анонимную) статистику использования Сервиса для улучшения функционала.
#### 10. Изменения Политики
10.1. Разработчик вправе вносить изменения в настоящую Политику. Все изменения публикуются на этой странице и вступают в силу с момента публикации.
#### 11. Контакты
Если у Вас есть вопросы по Политике конфиденциальности или запросы в отношении персональных данных, пожалуйста, свяжитесь с Разработчиком. Контакты указаны в описании бота.

View File

@ -1,4 +1,4 @@
import { ContactsFilter, ContactsList } from '@/components/contacts';
import { ContactsList } from '@/components/contacts';
import { ContactsContextProvider } from '@/context/contacts';
import { Card } from '@repo/ui/components/ui/card';
@ -8,7 +8,7 @@ export default function ContactsPage() {
<Card>
<div className="flex flex-row items-center justify-between space-x-4 p-4">
<h1 className="font-bold">Контакты</h1>
<ContactsFilter />
{/* <ContactsFilter /> */}
</div>
<div className="p-4 pt-0">
<ContactsList />

View File

@ -1,13 +1,24 @@
import { UpdateProfile } from '@/components/auth';
'use client';
import { CheckBanned, UpdateProfile } from '@/components/auth';
import { BottomNav } from '@/components/navigation';
import { EmptyProvider } from '@/providers/empty';
import { TelegramProvider } from '@/providers/telegram';
import { isTMA } from '@telegram-apps/sdk-react';
import { type PropsWithChildren } from 'react';
export default async function Layout({ children }: Readonly<PropsWithChildren>) {
export default function Layout({ children }: Readonly<PropsWithChildren>) {
const isTG = isTMA('simple');
const Provider = isTG ? TelegramProvider : EmptyProvider;
return (
<>
<UpdateProfile />
<main className="grow">{children}</main>
<BottomNav />
</>
<CheckBanned>
<Provider>
<UpdateProfile />
<main className="grow">{children}</main>
<BottomNav />
</Provider>
</CheckBanned>
);
}

View File

@ -1,4 +1,3 @@
import { getOrder } from '@/actions/api/orders';
import { Container } from '@/components/layout';
import { PageHeader } from '@/components/navigation';
import {
@ -9,23 +8,14 @@ import {
OrderStatus,
} from '@/components/orders';
import { type OrderPageParameters } from '@/components/orders/types';
import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query';
type Props = { params: Promise<OrderPageParameters> };
export default async function ProfilePage(props: Readonly<Props>) {
const parameters = await props.params;
const documentId = parameters.documentId;
const queryClient = new QueryClient();
await queryClient.prefetchQuery({
queryFn: () => getOrder({ documentId }),
queryKey: ['order', documentId],
});
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<>
<PageHeader title="Запись" />
<Container>
<OrderDateTime {...parameters} />
@ -35,6 +25,6 @@ export default async function ProfilePage(props: Readonly<Props>) {
<div className="pb-24" />
<OrderButtons {...parameters} />
</Container>
</HydrationBoundary>
</>
);
}

Some files were not shown because too many files have changed in this diff Show More