orderUpdate: add status info
This commit is contained in:
parent
bb65863f81
commit
74fdefe65a
@ -3,5 +3,6 @@ import { z } from 'zod';
|
||||
|
||||
export const envSchema = z.object({
|
||||
__DEV_TELEGRAM_ID: z.string(),
|
||||
BOT_TOKEN: z.string(),
|
||||
});
|
||||
export const env = envSchema.parse(process.env);
|
||||
|
||||
@ -8,6 +8,15 @@ import { SlotsService } from './slots';
|
||||
import { type VariablesOf } from '@graphql-typed-document-node/core';
|
||||
import { formatDate, formatTime, sumTime } from '@repo/utils/datetime-format';
|
||||
|
||||
const STATE_MAP = {
|
||||
approved: 'Одобрено',
|
||||
cancelled: 'Отменено',
|
||||
cancelling: 'Отменяется',
|
||||
completed: 'Завершено',
|
||||
created: 'Создано',
|
||||
scheduled: 'Запланировано',
|
||||
unknown: 'Неизвестно',
|
||||
};
|
||||
export class NotifyService extends BaseService {
|
||||
async orderCreated(variables: {
|
||||
input: Omit<VariablesOf<typeof GQL.CreateOrderDocument>['input'], 'time_end'>;
|
||||
@ -58,19 +67,20 @@ export class NotifyService extends BaseService {
|
||||
const master = slot?.master;
|
||||
const client = order.client;
|
||||
|
||||
const orderStateString = STATE_MAP[order.state || 'unknown'];
|
||||
const slotDate = formatDate(slot?.date).user();
|
||||
const timeStartString = formatTime(order.time_start ?? '').user();
|
||||
const timeEndString = formatTime(order.time_end ?? '').user();
|
||||
|
||||
// Мастеру
|
||||
if (master?.telegramId) {
|
||||
const message = `✏️ <b>Запись изменена!</b>\n<b>Дата:</b> ${slotDate}\n<b>Время:</b> ${timeStartString} - ${timeEndString}\n<b>Клиент:</b> ${client?.name ?? '-'}\n<b>Услуга:</b> ${service?.name ?? '-'}`;
|
||||
const message = `✏️ <b>Запись изменена!</b>\n<b>Дата:</b> ${slotDate}\n<b>Время:</b> ${timeStartString} - ${timeEndString}\n<b>Клиент:</b> ${client?.name ?? '-'}\n<b>Услуга:</b> ${service?.name ?? '-'}\n<b>Статус:</b> ${orderStateString}`;
|
||||
await notifyByTelegramId(String(master.telegramId), message);
|
||||
}
|
||||
|
||||
// Клиенту
|
||||
if (client?.telegramId) {
|
||||
const message = `✏️ <b>Запись изменена!</b>\n<b>Дата:</b> ${slotDate}\n<b>Время:</b> ${timeStartString} - ${timeEndString}\n<b>Мастер:</b> ${master?.name ?? '-'}\n<b>Услуга:</b> ${service?.name ?? '-'}`;
|
||||
const message = `✏️ <b>Запись изменена!</b>\n<b>Дата:</b> ${slotDate}\n<b>Время:</b> ${timeStartString} - ${timeEndString}\n<b>Мастер:</b> ${master?.name ?? '-'}\n<b>Услуга:</b> ${service?.name ?? '-'}\n<b>Статус:</b> ${orderStateString}`;
|
||||
await notifyByTelegramId(String(client.telegramId), message);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user