update : setup restuarant
This commit is contained in:
@@ -7,8 +7,8 @@ import { catchError, firstValueFrom, throwError } from "rxjs";
|
||||
import { IDmenuConfig } from "../../../configs/icons.config";
|
||||
import { DMENU_CONFIG } from "../constants";
|
||||
import { FindRestaurantsDto } from "../DTO/find-restaurants.dto";
|
||||
import { CreateRestaurantDto } from "../DTO/create-restaurant.dto";
|
||||
import { PlanEnum } from "../interface/plan.interface";
|
||||
import { SetupRestaurantDto } from "../DTO/create-restaurant.dto";
|
||||
import { PlanEnum, ISetupRestaurant } from "../interface/plan.interface";
|
||||
import { SubscriptionsService } from "../../subscriptions/providers/subscriptions.service";
|
||||
import { SubscriptionMessage } from "../../../common/enums/message.enum";
|
||||
|
||||
@@ -20,7 +20,7 @@ export class RestaurantService {
|
||||
@Inject(DMENU_CONFIG) private readonly config: IDmenuConfig,
|
||||
private readonly httpService: HttpService,
|
||||
private readonly subscriptionService: SubscriptionsService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
private getHeaders(): Record<string, string> {
|
||||
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);
|
||||
if (!userSubscription) {
|
||||
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 {
|
||||
const { data } = await firstValueFrom(
|
||||
this.httpService
|
||||
.post(`${this.config.baseUrl}/super-admin/restaurants`, {
|
||||
...dto,
|
||||
plan: PlanEnum.Base,
|
||||
setupRestaurantDto
|
||||
}, {
|
||||
headers: this.getHeaders(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user