feat: enhance RSVP and stats fetching logic to include detailed device and user information

This commit is contained in:
2026-01-29 13:57:19 +02:00
parent d1162a5f9d
commit b0b54e2e60
2 changed files with 12 additions and 6 deletions

View File

@@ -66,6 +66,10 @@ async function fetchRSVPDataFromDatabase() {
.filter((g: { rsvpTimestamp: Date | null }) => g.rsvpTimestamp !== null)
.map((guest: any) => {
const ipData = guest.ipData as any;
const userAgent = typeof ipData?.userAgent === "string" ? ipData.userAgent : "";
const deviceType = typeof ipData?.device?.type === "string" ? ipData.device.type : (typeof ipData?.deviceType === "string" ? ipData.deviceType : "Unknown");
const browserName = typeof ipData?.browser === "string" ? ipData.browser : (userAgent ? userAgent.split(" ")[0] : "Unknown");
const osName = typeof ipData?.os === "string" ? ipData.os : (typeof ipData?.platform === "string" ? ipData.platform : "Unknown");
return {
id: guest.id,
name: guest.name,
@@ -87,10 +91,10 @@ async function fetchRSVPDataFromDatabase() {
city: guest.ipCity || ipData?.city || "Unknown",
},
device: {
type: ipData?.device?.type || ipData?.deviceType || "Unknown",
browser: ipData?.browser || ipData?.userAgent?.split(" ")[0] || "Unknown",
os: ipData?.os || ipData?.platform || "Unknown",
uuid: ipData?.uuid || ipData?.sessionId || "N/A",
type: deviceType,
browser: browserName || "Unknown",
os: osName || "Unknown",
uuid: typeof ipData?.uuid === "string" ? ipData.uuid : (typeof ipData?.sessionId === "string" ? ipData.sessionId : "N/A"),
},
metadata: ipData || {},
};

View File

@@ -154,15 +154,17 @@ async function fetchStatsFromDatabase() {
}
if (latestSong) {
const timeAgo = getTimeAgo(latestSong.createdAt);
const requesterName = latestSong.guest?.name || "Guest";
latestActivity.push({
text: `${latestSong.guest.name} requested '${latestSong.title}'`,
text: `${requesterName} requested '${latestSong.title}'`,
time: timeAgo,
});
}
if (latestPhoto) {
const timeAgo = getTimeAgo(latestPhoto.createdAt);
const photoGuestName = latestPhoto.guest?.name || "Guest";
latestActivity.push({
text: `${latestPhoto.guest.name} uploaded a photo`,
text: `${photoGuestName} uploaded a photo`,
time: timeAgo,
});
}