add : dmenu:get restarants pagination and filters
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user