diff --git a/src/modules/dmenu/DTO/update-restaurant.dto.ts b/src/modules/dmenu/DTO/update-restaurant.dto.ts index b47069f..fc0c793 100644 --- a/src/modules/dmenu/DTO/update-restaurant.dto.ts +++ b/src/modules/dmenu/DTO/update-restaurant.dto.ts @@ -1,5 +1,5 @@ import { ApiPropertyOptional } from '@nestjs/swagger'; -import { IsString, IsOptional, IsNumber, IsEnum, IsDate } from 'class-validator'; +import { IsString, IsOptional, IsNumber, IsEnum, IsDate, IsBoolean } from 'class-validator'; import { Type } from 'class-transformer'; import { PlanEnum } from '../interface/plan.interface'; @@ -24,6 +24,11 @@ export class UpdateRestaurantDto { @IsString() phone?: string; + @ApiPropertyOptional() + @IsOptional() + @IsBoolean() + isActive?: boolean; + @ApiPropertyOptional({ example: 'base', enum: PlanEnum, description: 'پلن رستوران' }) @IsOptional() @IsEnum(PlanEnum) diff --git a/src/modules/dmenu/dmenu.controller.ts b/src/modules/dmenu/dmenu.controller.ts index b2241f2..8d86c7d 100644 --- a/src/modules/dmenu/dmenu.controller.ts +++ b/src/modules/dmenu/dmenu.controller.ts @@ -156,6 +156,14 @@ export class DmenuController { return this.restaurantService.updateRestaurant(id, dto); } + @PermissionsDec(PermissionEnum.DMENU) + @Delete('admin/dmenu/restaurants/:id/hard-delete') + @ApiOperation({ summary: "Hard delete restaurant" }) + @ApiParam({ name: "id", required: true, type: String }) + hardDeleteRestaurant(@Param("id") id: string) { + return this.restaurantService.hardDeleteRestaurant(id); + } + @PermissionsDec(PermissionEnum.DMENU) @Get('admin/dmenu/system-roles') @ApiOperation({ summary: "Get system roles" }) diff --git a/src/modules/dmenu/providers/restaurant.service.ts b/src/modules/dmenu/providers/restaurant.service.ts index 5bfe14f..1ab37b7 100644 --- a/src/modules/dmenu/providers/restaurant.service.ts +++ b/src/modules/dmenu/providers/restaurant.service.ts @@ -402,6 +402,36 @@ export class RestaurantService { } } + async hardDeleteRestaurant(id: string) { + try { + const { data } = await firstValueFrom( + this.httpService + .delete(`${this.config.baseUrl}/super-admin/restaurants/${id}/hard-delete`, { + headers: this.getHeaders(), + data: {}, + }) + .pipe( + catchError((err: AxiosError) => { + this.logger.error(`Failed to hard delete 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 hard deleting restaurant: ${error instanceof Error ? error.message : "Unknown error"}`); + throw error; + } + } + async directLogin(userSubscriptionId: string, userId: string) { try { // 1. Get userSubscription by id