add single endpoint

This commit is contained in:
2025-12-27 13:04:35 +03:30
parent e56d9888e5
commit 3cb59a0ca8
6 changed files with 170 additions and 6 deletions
@@ -1,5 +1,5 @@
import { HttpService } from "@nestjs/axios";
import { Injectable, Logger } from "@nestjs/common";
import { BadRequestException, Injectable, Logger } from "@nestjs/common";
import { Inject } from "@nestjs/common";
import { AxiosError } from "axios";
import { catchError, firstValueFrom, throwError } from "rxjs";
@@ -8,6 +8,9 @@ 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 { SubscriptionsService } from "../../subscriptions/providers/subscriptions.service";
import { SubscriptionMessage } from "../../../common/enums/message.enum";
@Injectable()
export class RestaurantService {
@@ -16,6 +19,7 @@ export class RestaurantService {
constructor(
@Inject(DMENU_CONFIG) private readonly config: IDmenuConfig,
private readonly httpService: HttpService,
private readonly subscriptionService: SubscriptionsService,
) {}
private getHeaders(): Record<string, string> {
@@ -67,11 +71,18 @@ export class RestaurantService {
}
}
async createRestaurant(dto: CreateRestaurantDto) {
async createRestaurant(dto: CreateRestaurantDto, userId: string) {
const { userSubscription } = await this.subscriptionService.getUserSubscriptionById(dto.userSubscriptionId, userId);
if (!userSubscription) {
throw new BadRequestException(SubscriptionMessage.USER_SUBS_NOT_FOUND);
}
try {
const { data } = await firstValueFrom(
this.httpService
.post(`${this.config.baseUrl}/super-admin/restaurants`, dto, {
.post(`${this.config.baseUrl}/super-admin/restaurants`, {
...dto,
plan: PlanEnum.Base,
}, {
headers: this.getHeaders(),
})
.pipe(
@@ -87,5 +98,20 @@ export class RestaurantService {
throw error;
}
}
async getRestaurantSubscription(subscriptionId: string) {
// TODO: Implement the business logic to get restaurant subscription
// This could involve querying the database, making external API calls, etc.
this.logger.log(`Getting restaurant subscription for ID: ${subscriptionId}`);
// For now, return a placeholder response
// You should implement the actual logic based on your business requirements
return {
subscriptionId,
message: "Restaurant subscription endpoint created successfully",
// Add actual data structure based on your requirements
};
}
}