update : setup restuarant
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { IsString, IsOptional, IsNumber } from 'class-validator';
|
import { IsString, IsOptional, IsNumber } from 'class-validator';
|
||||||
|
|
||||||
export class CreateRestaurantDto {
|
export class SetupRestaurantDto {
|
||||||
@ApiProperty({ example: 'کافه ژیوان', description: 'نام رستوران' })
|
@ApiProperty({ example: 'کافه ژیوان', description: 'نام رستوران' })
|
||||||
@IsString()
|
@IsString()
|
||||||
name!: string;
|
name!: string;
|
||||||
@@ -13,12 +13,12 @@ export class CreateRestaurantDto {
|
|||||||
@ApiPropertyOptional({ example: 2020, description: 'سال تأسیس' })
|
@ApiPropertyOptional({ example: 2020, description: 'سال تأسیس' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsNumber()
|
@IsNumber()
|
||||||
establishedYear?: number;
|
establishedYear: number;
|
||||||
|
|
||||||
@ApiPropertyOptional({ example: '09123456789', description: 'شماره تلفن' })
|
@ApiPropertyOptional({ example: '09123456789', description: 'شماره تلفن' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
phone?: string;
|
phone: string;
|
||||||
|
|
||||||
@ApiProperty({ example: 'sub_1234567890', description: 'شناسه اشتراک' })
|
@ApiProperty({ example: 'sub_1234567890', description: 'شناسه اشتراک' })
|
||||||
@IsString()
|
@IsString()
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { UpdateIconDto } from "./DTO/update-icon.dto";
|
|||||||
import { CreateGroupDto } from "./DTO/create-group.dto";
|
import { CreateGroupDto } from "./DTO/create-group.dto";
|
||||||
import { UpdateGroupDto } from "./DTO/update-group.dto";
|
import { UpdateGroupDto } from "./DTO/update-group.dto";
|
||||||
import { FindRestaurantsDto } from "./DTO/find-restaurants.dto";
|
import { FindRestaurantsDto } from "./DTO/find-restaurants.dto";
|
||||||
import { CreateRestaurantDto } from "./DTO/create-restaurant.dto";
|
import { SetupRestaurantDto } from "./DTO/create-restaurant.dto";
|
||||||
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
||||||
import { PermissionsDec } from "../../common/decorators/permission.decorator";
|
import { PermissionsDec } from "../../common/decorators/permission.decorator";
|
||||||
import { PermissionEnum } from "../users/enums/permission.enum";
|
import { PermissionEnum } from "../users/enums/permission.enum";
|
||||||
@@ -113,7 +113,7 @@ export class DmenuController {
|
|||||||
|
|
||||||
@Post('restaurants')
|
@Post('restaurants')
|
||||||
@ApiOperation({ summary: "Create restaurant" })
|
@ApiOperation({ summary: "Create restaurant" })
|
||||||
createRestaurant(@Body() dto: CreateRestaurantDto, @UserDec("id") userId: string) {
|
createRestaurant(@Body() dto: SetupRestaurantDto, @UserDec("id") userId: string) {
|
||||||
return this.restaurantService.createRestaurant(dto, userId);
|
return this.restaurantService.createRestaurant(dto, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,3 +2,15 @@ export enum PlanEnum {
|
|||||||
Base = 'base',
|
Base = 'base',
|
||||||
Premium = 'premium',
|
Premium = 'premium',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface ISetupRestaurant {
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
establishedYear: number;
|
||||||
|
phone: string;
|
||||||
|
plan: PlanEnum;
|
||||||
|
subscriptionId: string;
|
||||||
|
subscriptionEndDate: string|Date;
|
||||||
|
subscriptionStartDate: string|Date;
|
||||||
|
}
|
||||||
@@ -7,8 +7,8 @@ import { catchError, firstValueFrom, throwError } from "rxjs";
|
|||||||
import { IDmenuConfig } from "../../../configs/icons.config";
|
import { IDmenuConfig } from "../../../configs/icons.config";
|
||||||
import { DMENU_CONFIG } from "../constants";
|
import { DMENU_CONFIG } from "../constants";
|
||||||
import { FindRestaurantsDto } from "../DTO/find-restaurants.dto";
|
import { FindRestaurantsDto } from "../DTO/find-restaurants.dto";
|
||||||
import { CreateRestaurantDto } from "../DTO/create-restaurant.dto";
|
import { SetupRestaurantDto } from "../DTO/create-restaurant.dto";
|
||||||
import { PlanEnum } from "../interface/plan.interface";
|
import { PlanEnum, ISetupRestaurant } from "../interface/plan.interface";
|
||||||
import { SubscriptionsService } from "../../subscriptions/providers/subscriptions.service";
|
import { SubscriptionsService } from "../../subscriptions/providers/subscriptions.service";
|
||||||
import { SubscriptionMessage } from "../../../common/enums/message.enum";
|
import { SubscriptionMessage } from "../../../common/enums/message.enum";
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ export class RestaurantService {
|
|||||||
@Inject(DMENU_CONFIG) private readonly config: IDmenuConfig,
|
@Inject(DMENU_CONFIG) private readonly config: IDmenuConfig,
|
||||||
private readonly httpService: HttpService,
|
private readonly httpService: HttpService,
|
||||||
private readonly subscriptionService: SubscriptionsService,
|
private readonly subscriptionService: SubscriptionsService,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
private getHeaders(): Record<string, string> {
|
private getHeaders(): Record<string, string> {
|
||||||
const credentials = Buffer.from(`${this.config.username}:${this.config.password}`).toString("base64");
|
const credentials = Buffer.from(`${this.config.username}:${this.config.password}`).toString("base64");
|
||||||
@@ -71,17 +71,29 @@ export class RestaurantService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async createRestaurant(dto: CreateRestaurantDto, userId: string) {
|
async createRestaurant(dto: SetupRestaurantDto, userId: string) {
|
||||||
const { userSubscription } = await this.subscriptionService.getUserSubscriptionById(dto.userSubscriptionId, userId);
|
const { userSubscription } = await this.subscriptionService.getUserSubscriptionById(dto.userSubscriptionId, userId);
|
||||||
if (!userSubscription) {
|
if (!userSubscription) {
|
||||||
throw new BadRequestException(SubscriptionMessage.USER_SUBS_NOT_FOUND);
|
throw new BadRequestException(SubscriptionMessage.USER_SUBS_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
const plan = userSubscription.plan.name.includes('دلیوری') ? PlanEnum.Premium : PlanEnum.Base;
|
||||||
|
|
||||||
|
const setupRestaurantDto: ISetupRestaurant = {
|
||||||
|
name: dto.name,
|
||||||
|
slug: dto.slug,
|
||||||
|
establishedYear: dto.establishedYear,
|
||||||
|
phone: dto.phone,
|
||||||
|
plan,
|
||||||
|
subscriptionId: dto.userSubscriptionId,
|
||||||
|
subscriptionEndDate: userSubscription.endDate,
|
||||||
|
subscriptionStartDate: userSubscription.startDate,
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data } = await firstValueFrom(
|
const { data } = await firstValueFrom(
|
||||||
this.httpService
|
this.httpService
|
||||||
.post(`${this.config.baseUrl}/super-admin/restaurants`, {
|
.post(`${this.config.baseUrl}/super-admin/restaurants`, {
|
||||||
...dto,
|
setupRestaurantDto
|
||||||
plan: PlanEnum.Base,
|
|
||||||
}, {
|
}, {
|
||||||
headers: this.getHeaders(),
|
headers: this.getHeaders(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
import { Controller, Get, Param } from "@nestjs/common";
|
|
||||||
import { ApiBearerAuth, ApiOperation, ApiParam, ApiTags } from "@nestjs/swagger";
|
|
||||||
|
|
||||||
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
|
|
||||||
import { PermissionsDec } from "../../common/decorators/permission.decorator";
|
|
||||||
import { PermissionEnum } from "../users/enums/permission.enum";
|
|
||||||
import { RestaurantService } from "./providers/restaurant.service";
|
|
||||||
|
|
||||||
@ApiTags("super-admin")
|
|
||||||
@Controller("super-admin")
|
|
||||||
@AuthGuards()
|
|
||||||
@PermissionsDec(PermissionEnum.DMENU)
|
|
||||||
@ApiBearerAuth()
|
|
||||||
export class SuperAdminController {
|
|
||||||
constructor(
|
|
||||||
private readonly restaurantService: RestaurantService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
@Get('restaurants/subscription/:subscriptionId')
|
|
||||||
@ApiOperation({ summary: "Get restaurant subscription by subscription ID" })
|
|
||||||
@ApiParam({ name: "subscriptionId", required: true, type: String })
|
|
||||||
getRestaurantSubscription(@Param("subscriptionId") subscriptionId: string) {
|
|
||||||
return this.restaurantService.getRestaurantSubscription(subscriptionId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user