feat(orders, subscriptions): implement banned user checks and improve remaining orders calculation

- Added `checkIsBanned` method calls in the `createOrder`, `getOrder`, `getOrders`, and `updateOrder` methods of the `OrdersService` to prevent actions from banned users.
- Updated the calculation of `remainingOrdersCount` in the `SubscriptionsService` to ensure it does not go below zero, enhancing subscription management accuracy.
This commit is contained in:
vchikalkin 2025-09-02 21:02:50 +03:00
parent fd3785a436
commit f2ad3dff17
2 changed files with 7 additions and 1 deletions

View File

@ -43,6 +43,7 @@ const DEFAULT_ORDERS_SORT = ['slot.datetime_start:desc', 'datetime_start:desc'];
export class OrdersService extends BaseService {
async createOrder(variables: VariablesOf<typeof GQL.CreateOrderDocument>) {
await this.checkIsBanned();
const { customer } = await this._getUser();
// Проверки на существование обязательных полей для предотвращения ошибок типов
@ -107,6 +108,7 @@ export class OrdersService extends BaseService {
}
async getOrder(variables: VariablesOf<typeof GQL.GetOrderDocument>) {
await this.checkIsBanned();
const { query } = await getClientWithToken();
const result = await query({
@ -118,6 +120,7 @@ export class OrdersService extends BaseService {
}
async getOrders(variables: VariablesOf<typeof GQL.GetOrdersDocument>) {
await this.checkIsBanned();
const { query } = await getClientWithToken();
const result = await query({
@ -132,6 +135,7 @@ export class OrdersService extends BaseService {
}
async updateOrder(variables: VariablesOf<typeof GQL.UpdateOrderDocument>) {
await this.checkIsBanned();
await this.checkUpdatePermission(variables);
await this.checkBeforeUpdate(variables);

View File

@ -226,7 +226,9 @@ export class SubscriptionsService extends BaseService {
const { maxOrdersPerMonth } = subscriptionSetting;
const remainingOrdersCount = maxOrdersPerMonth - (orders?.length ?? 0);
let remainingOrdersCount = maxOrdersPerMonth - (orders?.length ?? 0);
if (remainingOrdersCount < 0) remainingOrdersCount = 0;
return { maxOrdersPerMonth, remainingOrdersCount };
}