add : dmenu:get restarants pagination and filters

This commit is contained in:
2025-12-22 16:43:27 +03:30
parent 4f59d68951
commit f946948ca4
4 changed files with 113 additions and 10 deletions
@@ -6,6 +6,7 @@ import { catchError, firstValueFrom, throwError } from "rxjs";
import { IDmenuConfig } from "../../../configs/icons.config";
import { DMENU_CONFIG } from "../constants";
import { FindRestaurantsDto } from "../DTO/find-restaurants.dto";
@Injectable()
export class RestaurantService {
@@ -24,15 +25,39 @@ export class RestaurantService {
};
}
async findAll() {
async findAll(queryDto: FindRestaurantsDto) {
try {
const params: Record<string, any> = {
page: queryDto.page || 1,
limit: queryDto.limit || 10,
orderBy: queryDto.orderBy || 'createdAt',
order: queryDto.order || 'desc',
};
if (queryDto.search) {
params.search = queryDto.search;
}
if (queryDto.isActive !== undefined) {
params.isActive = queryDto.isActive;
}
if (queryDto.plan) {
params.plan = queryDto.plan;
}
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);
}),
),
this.httpService
.get(`${this.config.baseUrl}/super-admin/restaurants`, {
params,
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) {