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.
This commit is contained in:
vchikalkin 2025-10-09 09:44:43 +03:00
parent aa11ecfcec
commit 1e9fd66e27

View File

@ -17,8 +17,8 @@ export async function addContact(conversation: Conversation<Context, Context>, c
return ctx.reply(await conversation.external(({ t }) => t('err-generic')));
}
const customerService = new CustomersService({ telegramId });
const { customer } = await customerService.getCustomer({ telegramId });
const registrationService = new RegistrationService();
const { customer } = await registrationService.checkCustomerExists({ telegramId });
if (!customer) {
return ctx.reply(
@ -108,7 +108,6 @@ export async function addContact(conversation: Conversation<Context, Context>, c
try {
// Проверяем, есть ли клиент с таким номером
const registrationService = new RegistrationService();
const { customer: existingCustomer } = await registrationService.checkCustomerExists({ phone });
let documentId = existingCustomer?.documentId;
@ -124,6 +123,7 @@ export async function addContact(conversation: Conversation<Context, Context>, c
// Добавляем текущего пользователя к приглашенному
const invitedBy = [customer.documentId];
const customerService = new CustomersService({ telegramId });
await customerService.addInvitedBy({ data: { invitedBy }, documentId });
// Отправляем подтверждения и инструкции