You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Authentication: Retrieves the current user's ID using the auth() function.
Authorization Check: Throws an error if no user ID is found, indicating unauthorized access.
User Retrieval: Fetches the user from the database using the Clerk user ID.
User Existence Check: Throws an error if the user is not found in the database.
Current Time: Captures the current date and time.
Upcoming Meetings Query: Queries the database for the user's upcoming meetings, ordered by start time in ascending order, and limits the results to the next three meetings.
Return Data: Returns the list of upcoming meetings, including the event title.
actions/users.js
updateUsername(username)
Authentication: Retrieves the current user's ID using the auth() function.
Authorization Check: Throws an error if no user ID is found, indicating unauthorized access.
Username Uniqueness Check: Checks if the desired username is already taken by another user.
Conflict Check: Throws an error if the username is already taken by another user.
Database Update: Updates the user's username in the database.
Clerk Update: Updates the user's username in the Clerk system.
Return Success: Returns a success response if the update is successful.
getUserByUsername(username)
User Query: Fetches a user from the database by their username.
Data Selection: Selects specific fields to return, including user ID, name, email, image URL, and public events.
Event Filtering: Filters the user's events to include only public ones, ordered by creation date in descending order.
Return Data: Returns the user data along with their public events.
actions/meetings.js
getUserMeetings(type = "upcoming")
Authentication: Retrieves the current user's ID using the auth() function.
Authorization Check: Throws an error if no user ID is found, indicating unauthorized access.
User Retrieval: Fetches the user from the database using the Clerk user ID.
User Existence Check: Throws an error if the user is not found in the database.
Current Time: Captures the current date and time.
Meetings Query: Queries the database for the user's meetings, filtering by upcoming or past based on the type parameter.
Data Inclusion: Includes event details and the event creator's name and email.
Return Data: Returns the list of meetings, ordered by start time.
cancelMeeting(meetingId)
Authentication: Retrieves the current user's ID using the auth() function.
Authorization Check: Throws an error if no user ID is found, indicating unauthorized access.
User Retrieval: Fetches the user from the database using the Clerk user ID.
User Existence Check: Throws an error if the user is not found in the database.
Meeting Retrieval: Fetches the meeting from the database by its ID, including event and user details.
Ownership Check: Throws an error if the meeting is not found or the user is not authorized to cancel it.
Google Calendar Integration: Attempts to delete the meeting from Google Calendar using the event's Google event ID.
Database Deletion: Deletes the meeting from the database.
Return Success: Returns a success response if the cancellation is successful.
actions/availability.js
getUserAvailability()
Authentication: Retrieves the current user's ID using the auth() function.
Authorization Check: Throws an error if no user ID is found, indicating unauthorized access.
User Retrieval: Fetches the user from the database, including their availability and day-specific details.
Data Existence Check: Returns null if no user or availability data is found.
Data Transformation: Constructs an availability data object, including the time gap and day-specific availability.
Return Data: Returns the transformed availability data.
updateAvailability(data)
Authentication: Retrieves the current user's ID using the auth() function.
Authorization Check: Throws an error if no user ID is found, indicating unauthorized access.
User Retrieval: Fetches the user from the database, including their availability.
User Existence Check: Throws an error if the user is not found in the database.
Data Mapping: Maps the input data into an array of availability objects, including day, start time, and end time.
Data Update: Updates the user's existing availability or creates new availability data if none exists.
Return Success: Returns a success response if the update is successful.
actions/events.js
createEvent(data)
Authentication: Retrieves the current user's ID using the auth() function.
Authorization Check: Throws an error if no user ID is found, indicating unauthorized access.
Data Validation: Validates the input data against the eventSchema.
User Retrieval: Fetches the user from the database using the Clerk user ID.
User Existence Check: Throws an error if the user is not found in the database.
Event Creation: Creates a new event in the database with the validated data and the user's ID.
Return Event: Returns the newly created event.
getUserEvents()
Authentication: Retrieves the current user's ID using the auth() function.
Authorization Check: Throws an error if no user ID is found, indicating unauthorized access.
User Retrieval: Fetches the user from the database using the Clerk user ID.
User Existence Check: Throws an error if the user is not found in the database.
Events Query: Queries the database for events created by the user, ordered by creation date in descending order.
Data Inclusion: Includes a count of bookings for each event.
Return Data: Returns the list of events and the user's username.
deleteEvent(eventId)
Authentication: Retrieves the current user's ID using the auth() function.
Authorization Check: Throws an error if no user ID is found, indicating unauthorized access.
User Retrieval: Fetches the user from the database using the Clerk user ID.
User Existence Check: Throws an error if the user is not found in the database.
Event Retrieval: Fetches the event from the database by its ID.
Ownership Check: Throws an error if the event is not found or the user is not authorized to delete it.
Event Deletion: Deletes the event from the database.
Return Success: Returns a success response if the deletion is successful.
getEventDetails(username, eventId)
Event Query: Fetches an event from the database by its ID and the associated user's username.
Data Inclusion: Includes user details such as name, email, image URL, and username.
Return Data: Returns the event details.
getEventAvailability(eventId)
Event Retrieval: Fetches the event from the database by its ID, including user availability and bookings.
Availability Check: Returns an empty array if the event or user availability is not found.
Date Range Setup: Sets the start date to the current day and the end date to 30 days later.
Availability Calculation: Iterates over each day in the date range to calculate available time slots based on user availability and existing bookings.
Return Data: Returns a list of available dates and time slots.