feat: enhance RSVP and stats fetching logic to include detailed device and user information
This commit is contained in:
@@ -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 || {},
|
||||
};
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user