user id -> user name
in attendace
This commit is contained in:
parent
36f52b42c6
commit
1be7dc2858
@ -34,7 +34,33 @@ export async function GET(req: NextRequest) {
|
|||||||
? await getAttendanceByGym(targetGymId)
|
? await getAttendanceByGym(targetGymId)
|
||||||
: await db.getAllAttendance();
|
: await db.getAllAttendance();
|
||||||
|
|
||||||
return successResponse({ records: attendance });
|
// Get all users to enrich attendance with user names
|
||||||
|
const allUsers = await db.getAllUsers();
|
||||||
|
const userMap = new Map(
|
||||||
|
allUsers.map((u) => [
|
||||||
|
u.id,
|
||||||
|
{
|
||||||
|
firstName: u.firstName,
|
||||||
|
lastName: u.lastName,
|
||||||
|
email: u.email,
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Enrich attendance records with user information
|
||||||
|
const enrichedAttendance = attendance.map((record) => {
|
||||||
|
const userInfo = userMap.get(record.userId);
|
||||||
|
return {
|
||||||
|
...record,
|
||||||
|
userName: userInfo
|
||||||
|
? `${userInfo.firstName} ${userInfo.lastName}`.trim() ||
|
||||||
|
userInfo.email
|
||||||
|
: record.userId,
|
||||||
|
userEmail: userInfo?.email,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return successResponse({ records: enrichedAttendance });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Admin attendance error:", error);
|
console.error("Admin attendance error:", error);
|
||||||
return new NextResponse("Internal Server Error", { status: 500 });
|
return new NextResponse("Internal Server Error", { status: 500 });
|
||||||
|
|||||||
@ -63,7 +63,7 @@ export default function AttendancePage() {
|
|||||||
className="border-b border-border/50 hover:bg-muted/50 transition-colors"
|
className="border-b border-border/50 hover:bg-muted/50 transition-colors"
|
||||||
>
|
>
|
||||||
<td className="py-3 px-4 text-sm">
|
<td className="py-3 px-4 text-sm">
|
||||||
{record.userId.substring(0, 8)}...
|
{record.userName || record.userId.substring(0, 8) + "..."}
|
||||||
</td>
|
</td>
|
||||||
<td className="py-3 px-4 text-sm capitalize text-muted-foreground">
|
<td className="py-3 px-4 text-sm capitalize text-muted-foreground">
|
||||||
{record.type}
|
{record.type}
|
||||||
|
|||||||
@ -55,6 +55,8 @@ export interface Gym {
|
|||||||
export interface AttendanceRecord {
|
export interface AttendanceRecord {
|
||||||
id: string;
|
id: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
|
userName?: string;
|
||||||
|
userEmail?: string;
|
||||||
checkInTime: Date;
|
checkInTime: Date;
|
||||||
checkOutTime?: Date;
|
checkOutTime?: Date;
|
||||||
date: string;
|
date: string;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user