fix: pcat groups query — use schema_images.category_id instead of car_groups
Some checks failed
CI / Lint, Typecheck, Test & Build (push) Has been cancelled

car_groups junction table only has data for 2K of 68K cars. Derive groups
from schema_images.category_id which covers 92.6% of records. Also fix
getSchemaImages to filter by category_id instead of empty group_id.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 20:30:53 +00:00
parent ca4437b245
commit 51f630db3c

View File

@@ -192,17 +192,29 @@ export class PcatCatalogService {
? await this.db.execute<{
id: string; catalog_id: string; parent_id: string | null; name: string; img_url: string | null; has_subgroups: boolean; has_parts: boolean;
}>(
sql`SELECT DISTINCT g.id, g.catalog_id, g.parent_id, g.name, g.img_url, g.has_subgroups, g.has_parts
FROM pc.car_groups cg JOIN pc.groups g ON g.id = cg.group_id
WHERE cg.car_id = ${carId} AND g.parent_id = ${parentId}
sql`WITH car_cats AS (
SELECT DISTINCT category_id FROM pc.schema_images WHERE car_id = ${carId}
)
SELECT g.id, g.catalog_id, g.parent_id, g.name, g.img_url,
EXISTS(SELECT 1 FROM car_cats cc JOIN pc.groups g2 ON g2.id = cc.category_id WHERE g2.parent_id = g.id) as has_subgroups,
true as has_parts
FROM car_cats cc
JOIN pc.groups g ON g.id = cc.category_id
WHERE g.parent_id = ${parentId}
ORDER BY g.name`,
)
: await this.db.execute<{
id: string; catalog_id: string; parent_id: string | null; name: string; img_url: string | null; has_subgroups: boolean; has_parts: boolean;
}>(
sql`SELECT DISTINCT g.id, g.catalog_id, g.parent_id, g.name, g.img_url, g.has_subgroups, g.has_parts
FROM pc.car_groups cg JOIN pc.groups g ON g.id = cg.group_id
WHERE cg.car_id = ${carId} AND g.parent_id IS NULL
sql`WITH car_cats AS (
SELECT DISTINCT category_id FROM pc.schema_images WHERE car_id = ${carId}
)
SELECT g.id, g.catalog_id, g.parent_id, g.name, g.img_url,
EXISTS(SELECT 1 FROM car_cats cc JOIN pc.groups g2 ON g2.id = cc.category_id WHERE g2.parent_id = g.id) as has_subgroups,
true as has_parts
FROM car_cats cc
JOIN pc.groups g ON g.id = cc.category_id
WHERE g.parent_id IS NULL
ORDER BY g.name`,
);
@@ -229,7 +241,7 @@ export class PcatCatalogService {
id: number; name: string | null; img_url: string | null; parts_count: number;
}>(
sql`SELECT id, name, img_url, parts_count FROM pc.schema_images
WHERE car_id = ${carId} AND group_id = ${groupId} AND is_active = true
WHERE car_id = ${carId} AND category_id = ${groupId} AND is_active = true
ORDER BY name`,
);