feat(api/notify): enhance order creation notifications with dynamic emoji and confirmation text based on creator role

This commit is contained in:
vchikalkin 2025-07-03 22:51:03 +03:00
parent cc91c5cb30
commit 53af172e34
2 changed files with 10 additions and 5 deletions

View File

@ -20,7 +20,7 @@ const STATE_MAP = {
export class NotifyService extends BaseService {
async orderCreated(variables: {
input: Omit<VariablesOf<typeof GQL.CreateOrderDocument>['input'], 'time_end'>;
}) {
}, createdByMaster: boolean) {
const customersService = new CustomersService(this.customer);
const slotsService = new SlotsService(this.customer);
const servicesService = new ServicesService(this.customer);
@ -31,7 +31,12 @@ export class NotifyService extends BaseService {
const clientId = String(variables.input.client ?? '');
const state = String(variables.input.state ?? '');
const isApproved = state === GQL.Enum_Order_State.Approved;
let emoji = '🆕';
let confirmText = '';
if (createdByMaster) {
emoji = '✅';
confirmText = ' и подтверждена';
}
const { slot } = await slotsService.getSlot({ documentId: slotId });
const { service } = await servicesService.getService({ documentId: serviceId });
@ -48,13 +53,13 @@ export class NotifyService extends BaseService {
// Мастеру
if (master?.telegramId) {
const message = `🆕 <b>Запись создана${isApproved ? ' и подтверждена' : ''}!</b>\n<b>Дата:</b> ${slotDate}\n<b>Время:</b> ${timeStartString} - ${timeEndString}\n<b>Клиент:</b> ${client?.name ?? '-'}\n<b>Услуга:</b> ${service?.name ?? '-'}`;
const message = `${emoji} <b>Запись создана${confirmText}!</b>\n<b>Дата:</b> ${slotDate}\n<b>Время:</b> ${timeStartString} - ${timeEndString}\n<b>Клиент:</b> ${client?.name ?? '-'}\n<b>Услуга:</b> ${service?.name ?? '-'}`;
await notifyByTelegramId(String(master.telegramId), message);
}
// Клиенту
if (client?.telegramId) {
const message = `🆕 <b>Запись создана${isApproved ? ' и подтверждена' : ''}!</b>\n<b>Дата:</b> ${slotDate}\n<b>Время:</b> ${timeStartString} - ${timeEndString}\n<b>Мастер:</b> ${master?.name ?? '-'}\n<b>Услуга:</b> ${service?.name ?? '-'}`;
const message = `${emoji} <b>Запись создана${confirmText}!</b>\n<b>Дата:</b> ${slotDate}\n<b>Время:</b> ${timeStartString} - ${timeEndString}\n<b>Мастер:</b> ${master?.name ?? '-'}\n<b>Услуга:</b> ${service?.name ?? '-'}`;
await notifyByTelegramId(String(client.telegramId), message);
}
}

View File

@ -107,7 +107,7 @@ export class OrdersService extends BaseService {
// Уведомление об создании заказа
const notifyService = new NotifyService(this.customer);
notifyService.orderCreated(variables);
notifyService.orderCreated(variables, isMaster);
return mutationResult.data;
}