diff --git a/apps/admin/data/fitai.db b/apps/admin/data/fitai.db index 76de494..4a83ea7 100755 Binary files a/apps/admin/data/fitai.db and b/apps/admin/data/fitai.db differ diff --git a/apps/admin/src/app/api/attendance/check-in/route.ts b/apps/admin/src/app/api/attendance/check-in/route.ts index 10d9122..e12a2b8 100644 --- a/apps/admin/src/app/api/attendance/check-in/route.ts +++ b/apps/admin/src/app/api/attendance/check-in/route.ts @@ -13,21 +13,8 @@ export async function POST(req: Request) { // Ensure user exists in DB (sync from Clerk if needed) await ensureUserSynced(userId, db) - let client = await db.getClientByUserId(userId) - - if (!client) { - // Auto-create client profile if it doesn't exist - console.log('Client profile not found, creating new one for user:', userId) - client = await db.createClient({ - userId, - membershipType: 'basic', - membershipStatus: 'active', - joinDate: new Date() - }) - } - // Check if already checked in - const activeCheckIn = await db.getActiveCheckIn(client.id) + const activeCheckIn = await db.getActiveCheckIn(userId) if (activeCheckIn) { return new NextResponse('Already checked in', { status: 400 }) } @@ -35,7 +22,7 @@ export async function POST(req: Request) { const body = await req.json() const { type = 'gym', notes } = body - const attendance = await db.checkIn(client.id, type, notes) + const attendance = await db.checkIn(userId, type, notes) return NextResponse.json(attendance) } catch (error) { console.error('Check-in error:', error) diff --git a/apps/admin/src/app/api/attendance/check-out/route.ts b/apps/admin/src/app/api/attendance/check-out/route.ts index 2bfdbcb..dcec964 100644 --- a/apps/admin/src/app/api/attendance/check-out/route.ts +++ b/apps/admin/src/app/api/attendance/check-out/route.ts @@ -8,13 +8,8 @@ export async function POST(req: Request) { if (!userId) return new NextResponse('Unauthorized', { status: 401 }) const db = await getDatabase() - const client = await db.getClientByUserId(userId) - if (!client) { - return new NextResponse('Client profile not found', { status: 404 }) - } - - const activeCheckIn = await db.getActiveCheckIn(client.id) + const activeCheckIn = await db.getActiveCheckIn(userId) if (!activeCheckIn) { return new NextResponse('No active check-in found', { status: 404 }) } diff --git a/apps/admin/src/app/api/attendance/history/route.ts b/apps/admin/src/app/api/attendance/history/route.ts index 14b276c..0eddbbd 100644 --- a/apps/admin/src/app/api/attendance/history/route.ts +++ b/apps/admin/src/app/api/attendance/history/route.ts @@ -22,20 +22,7 @@ export async function GET(req: Request) { // Ensure user exists in DB (sync from Clerk if needed) await ensureUserSynced(userId, db) - let client = await db.getClientByUserId(userId) - - if (!client) { - // Auto-create client profile if it doesn't exist - console.log('Client profile not found, creating new one for user:', userId) - client = await db.createClient({ - userId, - membershipType: 'basic', - membershipStatus: 'active', - joinDate: new Date() - }) - } - - const history = await db.getAttendanceHistory(client.id) + const history = await db.getAttendanceHistory(userId) return NextResponse.json(history) } catch (error) { console.error('History error:', error) diff --git a/apps/admin/src/components/users/UserManagement.tsx b/apps/admin/src/components/users/UserManagement.tsx index b1b9da8..15b7066 100644 --- a/apps/admin/src/components/users/UserManagement.tsx +++ b/apps/admin/src/components/users/UserManagement.tsx @@ -506,29 +506,27 @@ export function UserManagement() { )} - {selectedUser.client && ( -
- Last Check-In:{" "} - {selectedUser.lastCheckInTime - ? new Date( - selectedUser.lastCheckInTime, - ).toLocaleString() - : "Never"} -
-- This Week:{" "} - {selectedUser.checkInsThisWeek || 0} check-ins -
-- This Month:{" "} - {selectedUser.checkInsThisMonth || 0} check-ins -
-+ Last Check-In:{" "} + {selectedUser.lastCheckInTime + ? new Date( + selectedUser.lastCheckInTime, + ).toLocaleString() + : "Never"} +
++ This Week:{" "} + {selectedUser.checkInsThisWeek || 0} check-ins +
++ This Month:{" "} + {selectedUser.checkInsThisMonth || 0} check-ins +