fix debugging errors

This commit is contained in:
chark1es 2025-03-01 15:59:37 -08:00
parent 5fd2eb67a0
commit c4e5689593
2 changed files with 41 additions and 1 deletions

View file

@ -28,13 +28,26 @@ const EventCheckIn = () => {
const get = Get.getInstance();
const auth = Authentication.getInstance();
const dataSync = DataSyncService.getInstance();
const logger = SendLog.getInstance();
const currentUser = auth.getCurrentUser();
if (!currentUser) {
await logger.send(
"error",
"event_check_in",
"Check-in failed: User not logged in"
);
toast.error("You must be logged in to check in to events");
return;
}
// Log the check-in attempt
await logger.send(
"attempt",
"event_check_in",
`User ${currentUser.id} attempted to check in with code: ${eventCode}`
);
// Find the event with the given code using IndexedDB
// Force sync to ensure we have the latest data
await dataSync.syncCollection(Collections.EVENTS, `event_code = "${eventCode}"`);
@ -49,12 +62,22 @@ const EventCheckIn = () => {
const event = events.length > 0 ? events[0] : null;
if (!event) {
await logger.send(
"error",
"event_check_in",
`Check-in failed: Invalid event code "${eventCode}"`
);
throw new Error("Invalid event code");
}
// Check if user is already checked in
const attendees = event.attendees || [];
if (attendees.some((entry) => entry.user_id === currentUser.id)) {
await logger.send(
"error",
"event_check_in",
`Check-in failed: User ${currentUser.id} already checked in to event ${event.event_name} (${event.id})`
);
throw new Error("You have already checked in to this event");
}
@ -64,13 +87,30 @@ const EventCheckIn = () => {
const eventEndDate = new Date(event.end_date); // Now properly converted to local time by Get
if (eventStartDate > currentTime) {
await logger.send(
"error",
"event_check_in",
`Check-in failed: Event ${event.event_name} (${event.id}) has not started yet`
);
throw new Error("This event has not started yet");
}
if (eventEndDate < currentTime) {
await logger.send(
"error",
"event_check_in",
`Check-in failed: Event ${event.event_name} (${event.id}) has already ended`
);
throw new Error("This event has already ended");
}
// Log successful validation before proceeding
await logger.send(
"info",
"event_check_in",
`Check-in validation successful for user ${currentUser.id} to event ${event.event_name} (${event.id})`
);
// If event has food, show food selection modal
if (event.has_food) {
setCurrentCheckInEvent(event);

View file

@ -106,7 +106,7 @@ export class AuthSyncService {
await this.dataSync.syncCollection(Collections.USERS, `id = "${userId}"`);
// Log the sync operation
await this.logger.send('login', 'auth', 'User data synchronized on login');
console.log('User data synchronized on login');
}
// Sync all collections in parallel with conflict resolution