* refactor(profile): comment out change role feature * refactor(orders): update OrderServices and ServiceSelect components to utilize ServiceCard, and enhance service fields with duration in GraphQL types * refactor(schedule): implement forbidden order states to disable editing slots with active orders * fix(deploy): update SSH configuration to use dynamic port from secrets for improved flexibility * refactor(api/orders): simplify order creation logic by removing unnecessary validations and improving error handling * refactor(contact-row): replace role display logic with useIsMaster hook for improved clarity * refactor(profile/orders-list): update header text from "Общие записи" to "Недавние записи" for better clarity gql: GetOrders add sort slot.date:desc * refactor(profile/orders-list): enhance OrderCard component by adding avatarSource prop based on user role * feat(order-form): implement date selection with event highlighting and monthly view for available time slots * refactor(i18n/config): update timeZone from 'Europe/Amsterdam' to 'Europe/Moscow' * refactor(order-form/datetime-select): enhance date selection logic to include slot availability check * refactor(datetime-format): integrate dayjs timezone support with default Moscow timezone for date and time formatting * fix(contact-row): replace useIsMaster hook with isCustomerMaster utility for role display logic * refactor(service-card): replace formatTime with getMinutes for duration display * refactor(order-datetime): update date and time handling to use datetime_start and datetime_end for improved consistency * refactor(profile): streamline profile and slot pages by integrating session user retrieval and updating booking logic with BookButton component * fix(navigation): append query parameter to bottom-nav links and enhance back navigation logic in success page
109 lines
4.7 KiB
TypeScript
109 lines
4.7 KiB
TypeScript
/* eslint-disable complexity */
|
|
import * as GQL from '../types';
|
|
import { notifyByTelegramId } from '../utils/notify';
|
|
import { BaseService } from './base';
|
|
import { CustomersService } from './customers';
|
|
import { OrdersService } from './orders';
|
|
import { ServicesService } from './services';
|
|
import { SlotsService } from './slots';
|
|
import { type VariablesOf } from '@graphql-typed-document-node/core';
|
|
import { formatDate, formatTime, getMinutes, sumTime } from '@repo/utils/datetime-format';
|
|
|
|
const STATE_MAP = {
|
|
approved: 'Одобрено',
|
|
cancelled: 'Отменено',
|
|
cancelling: 'Отменяется',
|
|
completed: 'Завершено',
|
|
created: 'Создано',
|
|
scheduled: 'Запланировано',
|
|
unknown: 'Неизвестно',
|
|
};
|
|
export class NotifyService extends BaseService {
|
|
async orderCreated(
|
|
variables: VariablesOf<typeof GQL.CreateOrderDocument>,
|
|
createdByMaster: boolean,
|
|
) {
|
|
const customersService = new CustomersService(this.customer);
|
|
const slotsService = new SlotsService(this.customer);
|
|
const servicesService = new ServicesService(this.customer);
|
|
|
|
const slotId = String(variables.input.slot ?? '');
|
|
const serviceId = String(variables.input.services?.[0] ?? '');
|
|
const clientId = String(variables.input.client ?? '');
|
|
|
|
if (!serviceId || !clientId || !slotId) return;
|
|
|
|
let emoji = '🆕';
|
|
let confirmText = '';
|
|
if (createdByMaster) {
|
|
emoji = '✅';
|
|
confirmText = ' и подтверждена';
|
|
}
|
|
|
|
const { slot } = await slotsService.getSlot({ documentId: slotId });
|
|
const { service } = await servicesService.getService({ documentId: serviceId });
|
|
const { customer: master } = await customersService.getCustomer({
|
|
documentId: slot?.master?.documentId ?? '',
|
|
});
|
|
const { customer: client } = await customersService.getCustomer({ documentId: clientId });
|
|
|
|
if (!slot?.datetime_start || !variables.input.datetime_start || !service?.duration) return;
|
|
|
|
const slotDate = formatDate(slot?.datetime_start).user();
|
|
const timeStartString = formatTime(variables.input.datetime_start).user();
|
|
const timeEndString = formatTime(
|
|
sumTime(variables.input.datetime_start, getMinutes(service?.duration)),
|
|
).user();
|
|
|
|
// Мастеру
|
|
if (master?.telegramId) {
|
|
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 = `${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);
|
|
}
|
|
}
|
|
|
|
async orderUpdated(variables: VariablesOf<typeof GQL.UpdateOrderDocument>) {
|
|
// Получаем order через OrdersService
|
|
const ordersService = new OrdersService(this.customer);
|
|
const { order } = await ordersService.getOrder({ documentId: variables.documentId });
|
|
if (!order) return;
|
|
|
|
const slot = order.slot;
|
|
if (!slot) return;
|
|
|
|
const service = order.services[0];
|
|
const master = slot?.master;
|
|
const client = order.client;
|
|
|
|
const orderStateString = STATE_MAP[order.state || 'unknown'];
|
|
const slotDate = formatDate(slot?.datetime_start).user();
|
|
const timeStartString = formatTime(order.datetime_start ?? '').user();
|
|
const timeEndString = formatTime(order.datetime_end ?? '').user();
|
|
|
|
let emoji = '✏️';
|
|
if (order.state === GQL.Enum_Order_State.Cancelled) {
|
|
emoji = '❌';
|
|
} else if (order.state === GQL.Enum_Order_State.Approved) {
|
|
emoji = '✅';
|
|
}
|
|
|
|
// Мастеру
|
|
if (master?.telegramId) {
|
|
const message = `${emoji} <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 = `${emoji} <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);
|
|
}
|
|
}
|
|
}
|