add : dmenu:get restarants

This commit is contained in:
2025-12-22 16:23:37 +03:30
parent f9891facce
commit 4f59d68951
3 changed files with 54 additions and 1 deletions
+8 -1
View File
@@ -3,6 +3,7 @@ import { ApiBearerAuth, ApiOperation, ApiParam, ApiTags } from "@nestjs/swagger"
import { ContactService } from "./providers/contact.service"; import { ContactService } from "./providers/contact.service";
import { IconsService } from "./providers/icons.service"; import { IconsService } from "./providers/icons.service";
import { RestaurantService } from "./providers/restaurant.service";
import { CreateIconDto } from "./DTO/create-icon.dto"; import { CreateIconDto } from "./DTO/create-icon.dto";
import { UpdateIconDto } from "./DTO/update-icon.dto"; import { UpdateIconDto } from "./DTO/update-icon.dto";
import { CreateGroupDto } from "./DTO/create-group.dto"; import { CreateGroupDto } from "./DTO/create-group.dto";
@@ -20,7 +21,7 @@ export class DmenuController {
constructor( constructor(
private readonly iconsService: IconsService, private readonly iconsService: IconsService,
private readonly contactService: ContactService, private readonly contactService: ContactService,
private readonly restaurantService: RestaurantService,
) {} ) {}
// Icon endpoints // Icon endpoints
@@ -99,4 +100,10 @@ export class DmenuController {
findOne(@Param("id") id: string) { findOne(@Param("id") id: string) {
return this.contactService.findOne(+id); return this.contactService.findOne(+id);
} }
@Get('restaurants')
@ApiOperation({ summary: "Get all restaurants" })
findAllRestaurant() {
return this.restaurantService.findAll();
}
} }
+2
View File
@@ -4,6 +4,7 @@ import { DMENU_CONFIG } from "./constants";
import { DmenuController } from "./dmenu.controller"; import { DmenuController } from "./dmenu.controller";
import { ContactService } from "./providers/contact.service"; import { ContactService } from "./providers/contact.service";
import { IconsService } from "./providers/icons.service"; import { IconsService } from "./providers/icons.service";
import { RestaurantService } from "./providers/restaurant.service";
import { dmenuConfig } from "../../configs/icons.config"; import { dmenuConfig } from "../../configs/icons.config";
@Module({ @Module({
@@ -12,6 +13,7 @@ import { dmenuConfig } from "../../configs/icons.config";
providers: [ providers: [
IconsService, IconsService,
ContactService, ContactService,
RestaurantService,
{ {
provide: DMENU_CONFIG, provide: DMENU_CONFIG,
useFactory: dmenuConfig().useFactory, useFactory: dmenuConfig().useFactory,
@@ -0,0 +1,44 @@
import { HttpService } from "@nestjs/axios";
import { Injectable, Logger } from "@nestjs/common";
import { Inject } from "@nestjs/common";
import { AxiosError } from "axios";
import { catchError, firstValueFrom, throwError } from "rxjs";
import { IDmenuConfig } from "../../../configs/icons.config";
import { DMENU_CONFIG } from "../constants";
@Injectable()
export class RestaurantService {
private readonly logger = new Logger(RestaurantService.name);
constructor(
@Inject(DMENU_CONFIG) private readonly config: IDmenuConfig,
private readonly httpService: HttpService,
) {}
private getHeaders(): Record<string, string> {
const credentials = Buffer.from(`${this.config.username}:${this.config.password}`).toString("base64");
return {
"Content-Type": "application/json",
Authorization: `Basic ${credentials}`,
};
}
async findAll() {
try {
const { data } = await firstValueFrom(
this.httpService.get(`${this.config.baseUrl}/super-admin/restaurants`, { headers: this.getHeaders() }).pipe(
catchError((err: AxiosError) => {
this.logger.error(`Failed to fetch restaurants: ${err.message}`, err.stack);
return throwError(() => err);
}),
),
);
return data;
} catch (error: unknown) {
this.logger.error(`Error fetching restaurants: ${error instanceof Error ? error.message : "Unknown error"}`);
throw error;
}
}
}