fix(api/notify, api/orders): enhance notification messages and update order state handling for masters
This commit is contained in:
parent
7f86fc164d
commit
4983e7b36b
@ -1,4 +1,4 @@
|
||||
import type * as GQL from '../types';
|
||||
import * as GQL from '../types';
|
||||
import { notifyByTelegramId } from '../utils/notify';
|
||||
import { BaseService } from './base';
|
||||
import { CustomersService } from './customers';
|
||||
@ -29,6 +29,9 @@ export class NotifyService extends BaseService {
|
||||
const serviceId = String(variables.input.services?.[0] ?? '');
|
||||
const timeStart = String(variables.input.time_start ?? '');
|
||||
const clientId = String(variables.input.client ?? '');
|
||||
const state = String(variables.input.state ?? '');
|
||||
|
||||
const isApproved = state === GQL.Enum_Order_State.Approved;
|
||||
|
||||
const { slot } = await slotsService.getSlot({ documentId: slotId });
|
||||
const { service } = await servicesService.getService({ documentId: serviceId });
|
||||
@ -45,13 +48,13 @@ export class NotifyService extends BaseService {
|
||||
|
||||
// Мастеру
|
||||
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>Запись создана${isApproved ? ' и подтверждена' : ''}!</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>Запись создана!</b>\n<b>Дата:</b> ${slotDate}\n<b>Время:</b> ${timeStartString} - ${timeEndString}\n<b>Мастер:</b> ${master?.name ?? '-'}\n<b>Услуга:</b> ${service?.name ?? '-'}`;
|
||||
const message = `✅ <b>Запись создана${isApproved ? ' и подтверждена' : ''}!</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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/* eslint-disable canonical/id-match */
|
||||
import { getClientWithToken } from '../apollo/client';
|
||||
import * as GQL from '../types';
|
||||
import { Enum_Customer_Role, Enum_Slot_State } from '../types';
|
||||
import { Enum_Slot_State } from '../types';
|
||||
import { BaseService } from './base';
|
||||
import { CustomersService } from './customers';
|
||||
import { NotifyService } from './notify';
|
||||
@ -41,13 +41,18 @@ export class OrdersService extends BaseService {
|
||||
const servicesService = new ServicesService(this.customer);
|
||||
|
||||
const { customer } = await customersService.getCustomer(this.customer);
|
||||
|
||||
if (!customer) throw new Error(ERRORS.MISSING_USER);
|
||||
|
||||
const { slot } = await slotsService.getSlot({ documentId: variables.input.slot });
|
||||
|
||||
if (slot?.state === Enum_Slot_State.Closed) {
|
||||
throw new Error(ERRORS.SLOT_CLOSED);
|
||||
}
|
||||
|
||||
if (customer?.role === Enum_Customer_Role.Client) {
|
||||
const isMaster = isCustomerMaster(customer);
|
||||
|
||||
if (!isMaster) {
|
||||
if (customer.documentId !== variables.input.client) {
|
||||
throw new Error(ERRORS.INVALID_CLIENT);
|
||||
}
|
||||
@ -61,10 +66,7 @@ export class OrdersService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
customer?.role === Enum_Customer_Role.Master &&
|
||||
slot?.master?.documentId !== customer.documentId
|
||||
) {
|
||||
if (isMaster && slot?.master?.documentId !== customer.documentId) {
|
||||
throw new Error(ERRORS.INVALID_MASTER);
|
||||
}
|
||||
|
||||
@ -84,6 +86,7 @@ export class OrdersService extends BaseService {
|
||||
...variables,
|
||||
input: {
|
||||
...variables.input,
|
||||
state: isMaster ? GQL.Enum_Order_State.Approved : GQL.Enum_Order_State.Created,
|
||||
time_end: formatTime(endTime).db(),
|
||||
},
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user