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

63 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* eslint-disable canonical/id-match */
import { getClientWithToken } from '../apollo/client';
import { ERRORS } from '../constants/errors';
import * as GQL from '../types';
import { isCustomerBanned } from '@repo/utils/customer';
const BASE_ERRORS = {
MISSING_TELEGRAM_ID: 'Не указан Telegram ID',
NOT_FOUND_CUSTOMER: 'Пользователь не найден',
} as const;
type UserProfile = {
telegramId: number;
};
export class BaseService {
protected _user: UserProfile;
constructor(user: UserProfile) {
if (!user?.telegramId) {
throw new Error(BASE_ERRORS.MISSING_TELEGRAM_ID);
}
this._user = user;
}
protected async _getUser() {
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 };
}
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 && isCustomerBanned(customer)) {
throw new Error(ERRORS.NO_PERMISSION);
}
return { customer };
}
}