feat(api/notify): enhance order creation notifications with dynamic emoji and confirmation text based on creator role
This commit is contained in:
parent
cc91c5cb30
commit
53af172e34
@ -20,7 +20,7 @@ const STATE_MAP = {
|
|||||||
export class NotifyService extends BaseService {
|
export class NotifyService extends BaseService {
|
||||||
async orderCreated(variables: {
|
async orderCreated(variables: {
|
||||||
input: Omit<VariablesOf<typeof GQL.CreateOrderDocument>['input'], 'time_end'>;
|
input: Omit<VariablesOf<typeof GQL.CreateOrderDocument>['input'], 'time_end'>;
|
||||||
}) {
|
}, createdByMaster: boolean) {
|
||||||
const customersService = new CustomersService(this.customer);
|
const customersService = new CustomersService(this.customer);
|
||||||
const slotsService = new SlotsService(this.customer);
|
const slotsService = new SlotsService(this.customer);
|
||||||
const servicesService = new ServicesService(this.customer);
|
const servicesService = new ServicesService(this.customer);
|
||||||
@ -31,7 +31,12 @@ export class NotifyService extends BaseService {
|
|||||||
const clientId = String(variables.input.client ?? '');
|
const clientId = String(variables.input.client ?? '');
|
||||||
const state = String(variables.input.state ?? '');
|
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 { slot } = await slotsService.getSlot({ documentId: slotId });
|
||||||
const { service } = await servicesService.getService({ documentId: serviceId });
|
const { service } = await servicesService.getService({ documentId: serviceId });
|
||||||
@ -48,13 +53,13 @@ export class NotifyService extends BaseService {
|
|||||||
|
|
||||||
// Мастеру
|
// Мастеру
|
||||||
if (master?.telegramId) {
|
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);
|
await notifyByTelegramId(String(master.telegramId), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Клиенту
|
// Клиенту
|
||||||
if (client?.telegramId) {
|
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);
|
await notifyByTelegramId(String(client.telegramId), message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -107,7 +107,7 @@ export class OrdersService extends BaseService {
|
|||||||
|
|
||||||
// Уведомление об создании заказа
|
// Уведомление об создании заказа
|
||||||
const notifyService = new NotifyService(this.customer);
|
const notifyService = new NotifyService(this.customer);
|
||||||
notifyService.orderCreated(variables);
|
notifyService.orderCreated(variables, isMaster);
|
||||||
|
|
||||||
return mutationResult.data;
|
return mutationResult.data;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user