This commit is contained in:
echo 2025-12-01 23:17:40 +01:00
parent d7d270510f
commit 62e2255b5e
6 changed files with 25 additions and 58 deletions

Binary file not shown.

View File

@ -13,21 +13,8 @@ export async function POST(req: Request) {
// Ensure user exists in DB (sync from Clerk if needed) // Ensure user exists in DB (sync from Clerk if needed)
await ensureUserSynced(userId, db) 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 // Check if already checked in
const activeCheckIn = await db.getActiveCheckIn(client.id) const activeCheckIn = await db.getActiveCheckIn(userId)
if (activeCheckIn) { if (activeCheckIn) {
return new NextResponse('Already checked in', { status: 400 }) return new NextResponse('Already checked in', { status: 400 })
} }
@ -35,7 +22,7 @@ export async function POST(req: Request) {
const body = await req.json() const body = await req.json()
const { type = 'gym', notes } = body 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) return NextResponse.json(attendance)
} catch (error) { } catch (error) {
console.error('Check-in error:', error) console.error('Check-in error:', error)

View File

@ -8,13 +8,8 @@ export async function POST(req: Request) {
if (!userId) return new NextResponse('Unauthorized', { status: 401 }) if (!userId) return new NextResponse('Unauthorized', { status: 401 })
const db = await getDatabase() const db = await getDatabase()
const client = await db.getClientByUserId(userId)
if (!client) { const activeCheckIn = await db.getActiveCheckIn(userId)
return new NextResponse('Client profile not found', { status: 404 })
}
const activeCheckIn = await db.getActiveCheckIn(client.id)
if (!activeCheckIn) { if (!activeCheckIn) {
return new NextResponse('No active check-in found', { status: 404 }) return new NextResponse('No active check-in found', { status: 404 })
} }

View File

@ -22,20 +22,7 @@ export async function GET(req: Request) {
// Ensure user exists in DB (sync from Clerk if needed) // Ensure user exists in DB (sync from Clerk if needed)
await ensureUserSynced(userId, db) await ensureUserSynced(userId, db)
let client = await db.getClientByUserId(userId) const history = await db.getAttendanceHistory(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)
return NextResponse.json(history) return NextResponse.json(history)
} catch (error) { } catch (error) {
console.error('History error:', error) console.error('History error:', error)

View File

@ -506,29 +506,27 @@ export function UserManagement() {
</div> </div>
)} )}
{selectedUser.client && ( <div>
<div> <h4 className="font-medium mb-2">Check-In Statistics</h4>
<h4 className="font-medium mb-2">Check-In Statistics</h4> <div className="space-y-1 text-sm">
<div className="space-y-1 text-sm"> <p>
<p> <span className="font-medium">Last Check-In:</span>{" "}
<span className="font-medium">Last Check-In:</span>{" "} {selectedUser.lastCheckInTime
{selectedUser.lastCheckInTime ? new Date(
? new Date( selectedUser.lastCheckInTime,
selectedUser.lastCheckInTime, ).toLocaleString()
).toLocaleString() : "Never"}
: "Never"} </p>
</p> <p>
<p> <span className="font-medium">This Week:</span>{" "}
<span className="font-medium">This Week:</span>{" "} {selectedUser.checkInsThisWeek || 0} check-ins
{selectedUser.checkInsThisWeek || 0} check-ins </p>
</p> <p>
<p> <span className="font-medium">This Month:</span>{" "}
<span className="font-medium">This Month:</span>{" "} {selectedUser.checkInsThisMonth || 0} check-ins
{selectedUser.checkInsThisMonth || 0} check-ins </p>
</p>
</div>
</div> </div>
)} </div>
</div> </div>
</CardContent> </CardContent>
</Card> </Card>

View File

@ -1,5 +1,5 @@
export const API_BASE_URL = __DEV__ export const API_BASE_URL = __DEV__
? 'https://694d46f62d87.ngrok-free.app' ? 'https://8679109544e4.ngrok-free.app'
: 'https://your-production-url.com' : 'https://your-production-url.com'
export const API_ENDPOINTS = { export const API_ENDPOINTS = {