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
@@ -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;
}
}
}