- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- Slot Initialization: Initializes an empty array to store available time slots.
- Time Parsing: Parses the start and end times with the given date.
- Current Time Adjustment: Adjusts the start time if the current date matches today's date.
- Slot Generation: Iterates over the time range to generate slots, checking for conflicts with existing bookings.
- Slot Availability Check: Adds a slot to the list if it does not conflict with any existing booking.
- Return Slots: Returns the list of available time slots.
- Event Retrieval: Fetches the event from the database by its ID, including user details.
- Event Existence Check: Throws an error if the event is not found.
- Google Calendar Integration: Retrieves the event creator's Google OAuth token to generate a meeting link.
- Token Check: Throws an error if the event creator has not connected to Google Calendar.
- OAuth Client Setup: Sets up a Google OAuth client with the retrieved token.
- Meeting Creation: Uses the Google Calendar API to create a meeting, generating a Google Meet link.
- Database Insertion: Inserts the booking details into the database, including the Google Meet link and event ID.
- Return Success: Returns a success response with the booking details and meeting link.