various fixes

raw sql to drizzle
This commit is contained in:
dimitar committed 2026-03-19 00:57:04 +01:00
1 parent ffd3aabc55
commit d6a77fcd23
5 files changed
+57 -30

No files matched your search

+14 -8
View File
@@ -1,7 +1,7 @@
import { NextResponse } from "next/server";
import { auth } from "@clerk/nextjs/server";
import { eq, sql } from "@fitai/database";
import { db, users as usersTable } from "@fitai/database";
import { db, users as usersTable, gyms as gymsTable } from "@fitai/database";
import { ensureUserSynced } from "@/lib/sync-user";
import log from "@/lib/logger";
@@ -68,16 +68,22 @@ export async function DELETE(
await ensureGymsTable();
// Check if gym exists
const gymRows = await db.all(sql`SELECT * FROM gyms WHERE id = ${gymId}`);
if (gymRows.length === 0) {
// Check if gym exists using Drizzle ORM
const existingGym = await db
.select()
.from(gymsTable)
.where(eq(gymsTable.id, gymId))
.get();
if (!existingGym) {
return NextResponse.json({ error: "Gym not found" }, { status: 404 });
}
// Soft delete - mark as inactive
await db.run(
sql`UPDATE gyms SET status = 'inactive', updated_at = ${Date.now()} WHERE id = ${gymId}`,
);
// Soft delete - mark as inactive using Drizzle ORM
await db
.update(gymsTable)
.set({ status: "inactive", updatedAt: new Date() })
.where(eq(gymsTable.id, gymId));
return NextResponse.json({
success: true,