-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Database } from "../../database"; | ||
|
||
export async function checkInUser(eventId: string, userId: string) { | ||
// Check if the event and attendee exist | ||
const event = await Database.EVENTS.findOne({ eventId }); | ||
const attendee = await Database.ATTENDEES.findOne({ userId }); | ||
|
||
if (!event || !attendee) { | ||
return { success: false, message: "Event or Attendee not found" }; | ||
} | ||
|
||
// Check or create event attendance record | ||
let eventAttendance = await Database.EVENTS_ATT.findOne({ eventId }); | ||
if (!eventAttendance) { | ||
eventAttendance = await Database.EVENTS_ATT.create({ | ||
eventId: eventId, | ||
attendees: [userId], | ||
}); | ||
} | ||
else { | ||
if (!eventAttendance.attendees.includes(userId)) { | ||
eventAttendance.attendees.push(userId); | ||
} | ||
} | ||
await eventAttendance.save(); | ||
|
||
// Check or create attendee attendance record | ||
let attendeeAttendance = await Database.ATTENDEES_ATT.findOne({ userId }); | ||
if (!attendeeAttendance) { | ||
attendeeAttendance = new Database.ATTENDEES_ATT({ | ||
userId: userId, | ||
eventsAttended: [eventId], | ||
}); | ||
} else { | ||
if (!attendeeAttendance.eventsAttended.includes(eventId)) { | ||
attendeeAttendance.eventsAttended.push(eventId); | ||
} | ||
} | ||
await attendeeAttendance.save(); | ||
return { success: true }; | ||
} |