feat: auto-register walk-in attendees during check-in

- Automatically register users who scan QR code but aren't pre-registered
- Mark walk-in registrations with wasWalkIn flag
- Show different success messages for walk-ins vs pre-registered attendees
- Check in walk-ins immediately upon registration
- Remove 'not registered' error - now handles walk-ins gracefully
- Update both QR scan and manual check-in to support walk-ins
This commit is contained in:
2025-11-20 19:10:29 +00:00
parent 2102f053da
commit 57b7cd2308
4 changed files with 66 additions and 17 deletions

View File

@@ -582,20 +582,12 @@ export const eventController = {
// Find or create the attendee user
const attendeeUserId = await findOrCreateUser(clerkUserId);
// Check in the attendee
// Check in the attendee (will auto-register if not registered)
const result = await eventService.checkInAttendee(id, attendeeUserId);
res.json(result);
} catch (error: any) {
console.error('Error checking in attendee:', error);
if (error.message.includes('not registered')) {
return res.status(404).json({
code: 'NOT_REGISTERED',
message: error.message,
timestamp: new Date().toISOString(),
});
}
if (error.message.includes('already checked in')) {
return res.status(409).json({

View File

@@ -495,7 +495,7 @@ export const eventService = {
async checkInAttendee(eventId: string, userId: string) {
// Check if user is registered
const registration = await prisma.eventRegistration.findUnique({
let registration = await prisma.eventRegistration.findUnique({
where: {
userId_eventId: {
userId,
@@ -515,15 +515,49 @@ export const eventService = {
},
});
// If not registered, register them now (walk-in)
if (!registration) {
throw new Error('User is not registered for this event');
registration = await prisma.eventRegistration.create({
data: {
userId,
eventId,
attended: true, // Check them in immediately
},
include: {
user: {
select: {
id: true,
username: true,
firstName: true,
lastName: true,
avatarUrl: true,
},
},
},
});
return {
success: true,
username: registration.user.username,
firstName: registration.user.firstName,
lastName: registration.user.lastName,
wasWalkIn: true, // Flag to indicate this was a walk-in registration
attendee: {
id: registration.id,
userId: registration.userId,
eventId: registration.eventId,
registeredAt: registration.registeredAt || new Date(),
attended: registration.attended || false,
user: registration.user,
},
};
}
if (registration.attended) {
throw new Error('User is already checked in');
}
// Update attendance
// Update attendance for pre-registered user
const updated = await prisma.eventRegistration.update({
where: {
userId_eventId: {
@@ -552,6 +586,7 @@ export const eventService = {
username: updated.user.username,
firstName: updated.user.firstName,
lastName: updated.user.lastName,
wasWalkIn: false,
attendee: {
id: updated.id,
userId: updated.userId,