-
Notifications
You must be signed in to change notification settings - Fork 0
duplicated changes from monorepo for undo endpoint #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -108,6 +108,46 @@ async function updateAttendanceRecords(eventId: string, userId: string) { | |||||||||||||||||||||||||||||||||||||
| .throwOnError(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| async function undoAttendanceRecords(eventId: string, userId: string) { | ||||||||||||||||||||||||||||||||||||||
| // 1. Remove from attendee attendances array | ||||||||||||||||||||||||||||||||||||||
| const { data: attendeeAttendance } = | ||||||||||||||||||||||||||||||||||||||
| await SupabaseDB.ATTENDEE_ATTENDANCES.select("eventsAttended") | ||||||||||||||||||||||||||||||||||||||
| .eq("userId", userId) | ||||||||||||||||||||||||||||||||||||||
| .maybeSingle() | ||||||||||||||||||||||||||||||||||||||
| .throwOnError(); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const eventsAttended = attendeeAttendance?.eventsAttended || []; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (eventsAttended.includes(eventId)) { | ||||||||||||||||||||||||||||||||||||||
| const newEventsAttended = eventsAttended.filter((id) => id !== eventId); | ||||||||||||||||||||||||||||||||||||||
| await SupabaseDB.ATTENDEE_ATTENDANCES.upsert({ | ||||||||||||||||||||||||||||||||||||||
| userId: userId, | ||||||||||||||||||||||||||||||||||||||
| eventsAttended: newEventsAttended, | ||||||||||||||||||||||||||||||||||||||
| }).throwOnError(); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // 2. Delete the row from EVENT_ATTENDANCES | ||||||||||||||||||||||||||||||||||||||
| await SupabaseDB.EVENT_ATTENDANCES.delete() | ||||||||||||||||||||||||||||||||||||||
| .eq("eventId", eventId) | ||||||||||||||||||||||||||||||||||||||
| .eq("attendee", userId) | ||||||||||||||||||||||||||||||||||||||
| .throwOnError(); | ||||||||||||||||||||||||||||||||||||||
|
milindkumar1 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+181
to
+185
|
||||||||||||||||||||||||||||||||||||||
| await SupabaseDB.EVENT_ATTENDANCES.delete() | |
| .eq("eventId", eventId) | |
| .eq("attendee", userId) | |
| .throwOnError(); | |
| const { data: deletedAttendances } = await SupabaseDB.EVENT_ATTENDANCES | |
| .delete() | |
| .eq("eventId", eventId) | |
| .eq("attendee", userId) | |
| .select("eventId") | |
| .throwOnError(); | |
| if (!deletedAttendances || deletedAttendances.length === 0) { | |
| return; | |
| } |
Copilot
AI
Apr 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attendanceCount is updated with a read-modify-write sequence (select then update currentCount - 1). Under concurrent check-ins/undos, this can lose updates and produce incorrect counts. Consider moving the increment/decrement into an atomic database operation (e.g., Postgres function/RPC or a single SQL update expression) to avoid race conditions.
| // 3. Decrement attendanceCount on EVENTS | |
| const { data: eventData } = await SupabaseDB.EVENTS.select( | |
| "attendanceCount" | |
| ) | |
| .eq("eventId", eventId) | |
| .single() | |
| .throwOnError(); | |
| const currentCount = eventData?.attendanceCount || 0; | |
| if (currentCount > 0) { | |
| await SupabaseDB.EVENTS.update({ attendanceCount: currentCount - 1 }) | |
| .eq("eventId", eventId) | |
| .throwOnError(); | |
| } | |
| // 3. Atomically decrement attendanceCount on EVENTS without going below zero | |
| await SupabaseDB.rpc("decrement_event_attendance_count", { | |
| target_event_id: eventId, | |
| }).throwOnError(); |
Copilot
AI
Apr 21, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undoCheckInUserToEvent selects eventType but never uses it. Consider selecting only points (or using eventType if needed) to keep the query minimal and avoid unused-data drift over time.
| const { data: event } = await SupabaseDB.EVENTS.select("eventType, points") | |
| const { data: event } = await SupabaseDB.EVENTS.select("points") |
Uh oh!
There was an error while loading. Please reload this page.