diff --git a/packages/graphql/api/notify.ts b/packages/graphql/api/notify.ts
index 089471f..39cbe0d 100644
--- a/packages/graphql/api/notify.ts
+++ b/packages/graphql/api/notify.ts
@@ -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 = `✅ Запись создана!\nДата: ${slotDate}\nВремя: ${timeStartString} - ${timeEndString}\nКлиент: ${client?.name ?? '-'}\nУслуга: ${service?.name ?? '-'}`;
+ const message = `✅ Запись создана${isApproved ? ' и подтверждена' : ''}!\nДата: ${slotDate}\nВремя: ${timeStartString} - ${timeEndString}\nКлиент: ${client?.name ?? '-'}\nУслуга: ${service?.name ?? '-'}`;
await notifyByTelegramId(String(master.telegramId), message);
}
// Клиенту
if (client?.telegramId) {
- const message = `✅ Запись создана!\nДата: ${slotDate}\nВремя: ${timeStartString} - ${timeEndString}\nМастер: ${master?.name ?? '-'}\nУслуга: ${service?.name ?? '-'}`;
+ const message = `✅ Запись создана${isApproved ? ' и подтверждена' : ''}!\nДата: ${slotDate}\nВремя: ${timeStartString} - ${timeEndString}\nМастер: ${master?.name ?? '-'}\nУслуга: ${service?.name ?? '-'}`;
await notifyByTelegramId(String(client.telegramId), message);
}
}
diff --git a/packages/graphql/api/orders.ts b/packages/graphql/api/orders.ts
index 2b2f274..0ff7ea1 100644
--- a/packages/graphql/api/orders.ts
+++ b/packages/graphql/api/orders.ts
@@ -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(),
},
},