25 lines
630 B
TypeScript
25 lines
630 B
TypeScript
import { db } from "@/lib/db";
|
|
import { comparisons } from "@/lib/db/schema";
|
|
import { eq, sql } from "drizzle-orm";
|
|
import { getComparison } from "@/app/actions/comparison";
|
|
|
|
export async function GET(
|
|
_request: Request,
|
|
{ params }: { params: Promise<{ slug: string }> }
|
|
) {
|
|
const { slug } = await params;
|
|
|
|
await db
|
|
.update(comparisons)
|
|
.set({ viewCount: sql`${comparisons.viewCount} + 1` })
|
|
.where(eq(comparisons.slug, slug));
|
|
|
|
const comparison = await getComparison(slug);
|
|
|
|
if (!comparison) {
|
|
return Response.json({ error: "Not found" }, { status: 404 });
|
|
}
|
|
|
|
return Response.json(comparison);
|
|
}
|