This commit is contained in:
2026-06-06 15:09:46 -04:00
parent 78220d3568
commit 06295c83ca
56 changed files with 12018 additions and 440 deletions

View File

@@ -5,7 +5,7 @@
import { sql, eq } from "drizzle-orm";
import { getDb } from "@/lib/db/index";
import { plants, diseases } from "@/lib/db/schema";
import { plants, diseases, plantViews } from "@/lib/db/schema";
import type { PlantCardData } from "@/components/PlantCard";
export type { PlantCardData };
@@ -24,10 +24,14 @@ export async function getBrowsePlants(): Promise<PlantCardData[]> {
scientificName: plants.scientificName,
family: plants.family,
category: plants.category,
imageUrl: plants.imageUrl,
updatedAt: plants.updatedAt,
viewCount: sql<number>`COALESCE(${plantViews.viewCount}, 0)`,
diseaseCount: sql<number>`COUNT(${diseases.id})`,
})
.from(plants)
.leftJoin(diseases, eq(diseases.plantId, plants.id))
.leftJoin(plantViews, eq(plantViews.plantId, plants.id))
.groupBy(plants.id)
.orderBy(plants.commonName);
@@ -37,6 +41,9 @@ export async function getBrowsePlants(): Promise<PlantCardData[]> {
scientificName: r.scientificName,
family: r.family,
category: r.category,
imageUrl: r.imageUrl,
updatedAt: r.updatedAt,
viewCount: r.viewCount,
diseaseCount: r.diseaseCount,
}));
}
@@ -53,6 +60,7 @@ export async function getBrowsePlant(id: string): Promise<PlantCardData | null>
scientificName: plants.scientificName,
family: plants.family,
category: plants.category,
imageUrl: plants.imageUrl,
diseaseCount: sql<number>`COUNT(${diseases.id})`,
})
.from(plants)