various fixes
raw sql to drizzle
This commit is contained in:
1 parent
ffd3aabc55
commit
d6a77fcd23
5 files changed
+57
-30
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { eq, sql } from "@fitai/database";
|
||||
import { db } from "@fitai/database";
|
||||
import { db, gyms as gymsTable } from "@fitai/database";
|
||||
import log from "@/lib/logger";
|
||||
|
||||
async function ensureGymsTable() {
|
||||
@@ -27,12 +27,16 @@ export async function GET(
|
||||
const { id: gymId } = await params;
|
||||
await ensureGymsTable();
|
||||
|
||||
// Get gym info
|
||||
const gymRows = await db.all(sql`SELECT * FROM gyms WHERE id = ${gymId}`);
|
||||
if (gymRows.length === 0) {
|
||||
return new NextResponse("Gym not found", { status: 404 });
|
||||
// Get gym info using Drizzle ORM
|
||||
const gym = await db
|
||||
.select()
|
||||
.from(gymsTable)
|
||||
.where(eq(gymsTable.id, gymId))
|
||||
.get();
|
||||
|
||||
if (!gym) {
|
||||
return NextResponse.json({ error: "Gym not found" }, { status: 404 });
|
||||
}
|
||||
const gym = gymRows[0];
|
||||
|
||||
// Get user counts
|
||||
const usersResult = await db.all(
|
||||
@@ -100,6 +104,9 @@ export async function GET(
|
||||
return NextResponse.json({ gym, stats });
|
||||
} catch (error) {
|
||||
log.error("Failed to get gym stats", error);
|
||||
return new NextResponse("Internal Server Error", { status: 500 });
|
||||
return NextResponse.json(
|
||||
{ error: "Internal Server Error" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user