add: endpoints to create admin for restuarant

This commit is contained in:
2025-12-28 10:59:53 +03:30
parent 127e13e36d
commit 610d82e77d
4 changed files with 262 additions and 3 deletions
@@ -8,6 +8,8 @@ import { IDmenuConfig } from "../../../configs/icons.config";
import { DMENU_CONFIG } from "../constants";
import { FindRestaurantsDto } from "../DTO/find-restaurants.dto";
import { SetupRestaurantDto } from "../DTO/create-restaurant.dto";
import { UpdateRestaurantDto } from "../DTO/update-restaurant.dto";
import { CreateMyRestaurantAdminDto } from "../DTO/create-restaurant-admin.dto";
import { PlanEnum, ISetupRestaurant } from "../interface/plan.interface";
import { SubscriptionsService } from "../../subscriptions/providers/subscriptions.service";
import { SubscriptionMessage } from "../../../common/enums/message.enum";
@@ -125,6 +127,35 @@ export class RestaurantService {
}
}
async updateRestaurant(id: string, dto: UpdateRestaurantDto) {
try {
const { data } = await firstValueFrom(
this.httpService
.patch(`${this.config.baseUrl}/super-admin/restaurants/${id}`, dto, {
headers: this.getHeaders(),
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error(`Failed to update restaurant: ${err.message}`, err.stack);
return throwError(() => err);
}),
),
);
return data;
} catch (error: unknown) {
if (error instanceof AxiosError && error.response) {
this.logger.error(`External API error response:`, error.response.data);
const errorResponse = {
...error.response.data,
message: error.response.data.error?.message || error.message,
};
throw new HttpException(errorResponse, error.response.status);
}
this.logger.error(`Error updating restaurant: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
async getRestaurantSubscription(subscriptionId: string) {
try {
const { data } = await firstValueFrom(
@@ -183,5 +214,121 @@ export class RestaurantService {
throw error;
}
}
async getSystemRoles() {
try {
const { data } = await firstValueFrom(
this.httpService
.get(`${this.config.baseUrl}/super-admin/system-roles`, {
headers: this.getHeaders(),
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error(`Failed to get system roles: ${err.message}`, err.stack);
return throwError(() => err);
}),
),
);
return data;
} catch (error: unknown) {
if (error instanceof AxiosError && error.response) {
this.logger.error(`External API error response:`, error.response.data);
const errorResponse = {
...error.response.data,
message: error.response.data.error?.message || error.message,
};
throw new HttpException(errorResponse, error.response.status);
}
this.logger.error(`Error getting system roles: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
async getRestaurantAdmins(restaurantId: string) {
try {
const { data } = await firstValueFrom(
this.httpService
.get(`${this.config.baseUrl}/super-admin/restaurants/${restaurantId}/admins`, {
headers: this.getHeaders(),
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error(`Failed to get restaurant admins: ${err.message}`, err.stack);
return throwError(() => err);
}),
),
);
return data;
} catch (error: unknown) {
if (error instanceof AxiosError && error.response) {
this.logger.error(`External API error response:`, error.response.data);
const errorResponse = {
...error.response.data,
message: error.response.data.error?.message || error.message,
};
throw new HttpException(errorResponse, error.response.status);
}
this.logger.error(`Error getting restaurant admins: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
async revokeRestaurantAdmin(restaurantId: string, adminId: string) {
try {
const { data } = await firstValueFrom(
this.httpService
.delete(`${this.config.baseUrl}/super-admin/restaurants/${restaurantId}/admins/${adminId}`, {
headers: this.getHeaders(),
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error(`Failed to revoke restaurant admin: ${err.message}`, err.stack);
return throwError(() => err);
}),
),
);
return data;
} catch (error: unknown) {
if (error instanceof AxiosError && error.response) {
this.logger.error(`External API error response:`, error.response.data);
const errorResponse = {
...error.response.data,
message: error.response.data.error?.message || error.message,
};
throw new HttpException(errorResponse, error.response.status);
}
this.logger.error(`Error revoking restaurant admin: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
async assignRestaurantAdmin(restaurantId: string, dto: CreateMyRestaurantAdminDto) {
try {
const { data } = await firstValueFrom(
this.httpService
.post(`${this.config.baseUrl}/super-admin/restaurants/${restaurantId}/admins`, dto, {
headers: this.getHeaders(),
})
.pipe(
catchError((err: AxiosError) => {
this.logger.error(`Failed to assign restaurant admin: ${err.message}`, err.stack);
return throwError(() => err);
}),
),
);
return data;
} catch (error: unknown) {
if (error instanceof AxiosError && error.response) {
this.logger.error(`External API error response:`, error.response.data);
const errorResponse = {
...error.response.data,
message: error.response.data.error?.message || error.message,
};
throw new HttpException(errorResponse, error.response.status);
}
this.logger.error(`Error assigning restaurant admin: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
}