feat: add getDescendantSlugs function and update category/destination filtering logic

This commit is contained in:
Thuan Bui
2026-03-22 09:51:26 +07:00
parent 3cc4f98a19
commit 8c934213eb
3 changed files with 35 additions and 4 deletions
+23
View File
@@ -77,3 +77,26 @@ export function getTaxonomyItem(
): TaxonomyItem | undefined {
return getTaxonomyMap(type).get(slug);
}
export function getDescendantSlugs(
taxonomyType: string,
slug: string,
): string[] {
const map = getTaxonomyMap(taxonomyType);
const result: string[] = [];
for (const [key, item] of map.entries()) {
if (key === slug) continue;
// Đi ngược từ node này lên root, kiểm tra xem có qua slug không
let current: TaxonomyItem | undefined = item;
while (current?.parent) {
if (current.parent === slug) {
result.push(key);
break;
}
current = map.get(current.parent);
}
}
return result;
}