mirror of
https://github.com/Dvorinka/Bookra.git
synced 2026-10-28 07:41:16 +00:00
feat(waitlist): queue position on the customer manage page
A waitlisted customer saw only a bare status — worse, the badge fell back to "Pending" for both waitlisted and cancelled states. The view now carries a 1-based waitlistPosition (earlier-created waitlisted bookings on the session + 1) and the page renders a warning-tone notice with the queue spot and auto-promotion explanation, in CS/EN. Also fixed the badge's nonexistent --danger-soft/--warning-soft tokens. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
7509e82261
commit
3892e9ce8c
7 files changed
+155
-14
No files matched your search
@@ -204,6 +204,18 @@ func (r *PGRepository) GetDashboardMetrics(ctx context.Context, tenantID string,
|
||||
return metrics, err
|
||||
}
|
||||
|
||||
func (r *PGRepository) GetWaitlistPosition(ctx context.Context, sessionID, bookingID string) (int, error) {
|
||||
var position int
|
||||
err := r.pool.QueryRow(ctx, `
|
||||
SELECT COUNT(*) + 1
|
||||
FROM bookings
|
||||
WHERE class_session_id = $1
|
||||
AND status = 'waitlisted'
|
||||
AND created_at < (SELECT created_at FROM bookings WHERE id = $2)
|
||||
`, sessionID, bookingID).Scan(&position)
|
||||
return position, err
|
||||
}
|
||||
|
||||
func (r *PGRepository) CancelPendingReminderJobsForBooking(ctx context.Context, bookingID string) error {
|
||||
_, err := r.pool.Exec(ctx, `
|
||||
UPDATE reminder_jobs
|
||||
|
||||
@@ -107,6 +107,7 @@ type Repository interface {
|
||||
// Customer Booking Management
|
||||
GetBookingByReference(ctx context.Context, reference string) (BookingRecord, error)
|
||||
GetBookingByID(ctx context.Context, bookingID string) (BookingRecord, error)
|
||||
GetWaitlistPosition(ctx context.Context, sessionID, bookingID string) (int, error)
|
||||
UpdateBookingStatus(ctx context.Context, bookingID string, status string) error
|
||||
RescheduleBooking(ctx context.Context, bookingID string, startsAt time.Time, endsAt time.Time) error
|
||||
|
||||
@@ -1844,6 +1845,27 @@ func (r *MemoryRepository) GetBookingByID(_ context.Context, bookingID string) (
|
||||
return BookingRecord{}, pgx.ErrNoRows
|
||||
}
|
||||
|
||||
func (r *MemoryRepository) GetWaitlistPosition(_ context.Context, sessionID, bookingID string) (int, error) {
|
||||
var self *BookingRecord
|
||||
for index := range r.bookings {
|
||||
if r.bookings[index].ID == bookingID {
|
||||
self = &r.bookings[index]
|
||||
break
|
||||
}
|
||||
}
|
||||
if self == nil {
|
||||
return 0, pgx.ErrNoRows
|
||||
}
|
||||
position := 1
|
||||
for _, booking := range r.bookings {
|
||||
if booking.ClassSessionID != nil && *booking.ClassSessionID == sessionID &&
|
||||
booking.Status == "waitlisted" && booking.CreatedAt.Before(self.CreatedAt) {
|
||||
position++
|
||||
}
|
||||
}
|
||||
return position, nil
|
||||
}
|
||||
|
||||
func (r *MemoryRepository) UpdateBookingStatus(_ context.Context, bookingID string, status string) error {
|
||||
for i, b := range r.bookings {
|
||||
if b.ID == bookingID {
|
||||
|
||||
Reference in new issue
Block a user