added category filtering
This commit is contained in:
parent
9daca90d6b
commit
69723d0801
8 changed files with 42 additions and 11 deletions
|
|
@ -6,6 +6,7 @@ import {
|
|||
Delete,
|
||||
Body,
|
||||
Param,
|
||||
Query,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
BadRequestException,
|
||||
|
|
@ -23,8 +24,12 @@ export class CategoriesController {
|
|||
|
||||
@Get()
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async findAll(): Promise<Category[]> {
|
||||
return await this.categoriesService.findAll();
|
||||
public async find(@Query() filters: GetCategoryFilters): Promise<Category[]> {
|
||||
const ids = Array.isArray(filters.ids) ? filters.ids : filters.ids ? [filters.ids] : [];
|
||||
const categories = Array.isArray(filters.categories) ? filters.categories : filters.categories ? [filters.categories] : [];
|
||||
const sort = filters.sort?.toLowerCase() === 'desc' ? 'desc' : 'asc';
|
||||
|
||||
return await this.categoriesService.find({ ids, categories, sort});
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
|
|
@ -73,3 +78,9 @@ export class CategoriesController {
|
|||
return await this.categoriesService.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
export interface GetCategoryFilters {
|
||||
ids?: string[];
|
||||
categories?: string[];
|
||||
sort?: 'asc' | 'desc';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue