fix
This commit is contained in:
parent
d7d270510f
commit
62e2255b5e
Binary file not shown.
@ -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)
|
||||||
|
|||||||
@ -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 })
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -506,7 +506,6 @@ 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">
|
||||||
@ -528,7 +527,6 @@ export function UserManagement() {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@ -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 = {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user