feat: implement fully dynamic filter sidebar in backend getActiveFilters and frontend ArchivePage mapping with URL sync
This commit is contained in:
1 parent
2745125c5b
commit
0ccf37f922
5 files changed
+142
-37
No files matched your search
@@ -61,6 +61,22 @@ export class ProductsController {
|
||||
return this.productsService.findAll(query);
|
||||
}
|
||||
|
||||
@Get('filters')
|
||||
@ApiOperation({ summary: 'دریافت فیلترهای فعال محصولات (دسته، علائم، نوع پت)' })
|
||||
@ApiOkResponse({
|
||||
description: 'لیست فیلترهای پویا استخراج شده از دیتابیس',
|
||||
schema: {
|
||||
example: {
|
||||
categories: [{ id: '1', name: 'مفاصل و استخوان', slug: 'joints' }],
|
||||
symptoms: ['لنگش', 'ریزش مو'],
|
||||
petTypes: ['سگ', 'گربه', 'هر دو']
|
||||
}
|
||||
}
|
||||
})
|
||||
getActiveFilters() {
|
||||
return this.productsService.getActiveFilters();
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'دریافت اطلاعات محصول با شناسه یکتا (ID)' })
|
||||
@ApiOkResponse({
|
||||
|
||||
@@ -63,4 +63,39 @@ export class ProductsService {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async getActiveFilters() {
|
||||
const [categories, symptomsDb, petTypesDb] = await Promise.all([
|
||||
this.prisma.category.findMany({
|
||||
where: {
|
||||
products: {
|
||||
some: {}
|
||||
}
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
}
|
||||
}),
|
||||
this.prisma.productSymptom.findMany({
|
||||
distinct: ['symptom'],
|
||||
select: {
|
||||
symptom: true,
|
||||
}
|
||||
}),
|
||||
this.prisma.product.findMany({
|
||||
distinct: ['suitableFor'],
|
||||
select: {
|
||||
suitableFor: true,
|
||||
}
|
||||
})
|
||||
]);
|
||||
|
||||
return {
|
||||
categories,
|
||||
symptoms: symptomsDb.map(s => s.symptom).filter(Boolean),
|
||||
petTypes: petTypesDb.map(p => p.suitableFor).filter(Boolean),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user