Class: UserRepository

UserRepository(database, quizRepository, notificationRepository, flashcardRepository, eventRepository)

UserRepository - Manages user-related data interactions with the database.

Constructor

new UserRepository(database, quizRepository, notificationRepository, flashcardRepository, eventRepository)

Parameters:
Name Type Description
database Object The database connection used for accessing user data.
quizRepository QuizRepository Repository for handling quiz data.
notificationRepository NotificationRepository Repository for handling notification data.
flashcardRepository FlashcardRepository Repository for handling flashcard data.
eventRepository EventRepository Repository for handling event data.
Source:

Methods

(static) addEvent(userId, eventId) → {Promise.<void>}

Adds an event to the events list of a user.
Parameters:
Name Type Description
userId string The ID of the user.
eventId string The ID of the event to add.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) addFollower(userId, followerId) → {Promise.<void>}

Adds a follower to the followers list of a user.
Parameters:
Name Type Description
userId string The ID of the user.
followerId string The ID of the follower to add.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) addFollowing(userId, followingId) → {Promise.<boolean>}

Adds a user to the following list of another user.
Parameters:
Name Type Description
userId string The ID of the user who is following.
followingId string The ID of the user being followed.
Source:
Returns:
A promise that resolves to true if the operation is successful.
Type
Promise.<boolean>

(static) addNotification(userId, notificationId) → {Promise.<void>}

Adds a notification to the notifications list of a user.
Parameters:
Name Type Description
userId string The ID of the user.
notificationId string The ID of the notification to add.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) addOwnedFlashcard(userId, flashcardId) → {Promise.<void>}

Adds a flashcard to the owned flashcards list of a user.
Parameters:
Name Type Description
userId string The ID of the user.
flashcardId string The ID of the flashcard to add.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) addOwnedQuiz(userId, quizId) → {Promise.<void>}

Adds a quiz to the owned quizzes list of a user.
Parameters:
Name Type Description
userId string The ID of the user.
quizId string The ID of the quiz to add.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) addSharedFlashcard(userId, flashcardId) → {Promise.<void>}

Adds a flashcard to the shared flashcards list of a user.
Parameters:
Name Type Description
userId string The ID of the user.
flashcardId string The ID of the flashcard to share.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) addSharedQuiz(userId, quizId) → {Promise.<void>}

Adds a quiz to the shared quizzes list of a user.
Parameters:
Name Type Description
userId string The ID of the user.
quizId string The ID of the quiz to share.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) addSubject(userId, subjectId) → {Promise.<void>}

Adds a subject to the subjects list of a user.
Parameters:
Name Type Description
userId string The ID of the user.
subjectId string The ID of the subject to add.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) addUpcomingEvent(userId, eventDetails) → {Promise.<boolean>}

Adds an upcoming event to a user's event list.
Parameters:
Name Type Description
userId string The ID of the user.
eventDetails Object The details of the upcoming event.
Source:
Returns:
A promise that resolves to true if the operation is successful.
Type
Promise.<boolean>

(static) addUpcomingEventNotification(userId, upcomingEvent) → {Promise.<boolean>}

Adds a notification for an upcoming event to a user's notification list.
Parameters:
Name Type Description
userId string The ID of the user.
upcomingEvent UpcomingEvent The upcoming event for which the notification is created.
Source:
Returns:
A promise that resolves to true if the operation is successful.
Type
Promise.<boolean>

(static) addUser(email, username, firstName, lastName, uuid)

Adds a new user to the database.
Parameters:
Name Type Description
email string User's email.
username string User's username.
firstName string User's first name.
lastName string User's last name.
uuid string User's unique identifier.
Source:

(static) convertTo12HourFormat(timeString) → {string}

Converts a time string from 24-hour format to 12-hour format.
Parameters:
Name Type Description
timeString string The time string in 24-hour format.
Source:
Returns:
The time string in 12-hour format.
Type
string

(static) deleteUser(id) → {Promise.<void>}

Deletes a user by their ID.
Parameters:
Name Type Description
id string The ID of the user to delete.
Source:
Returns:
Type
Promise.<void>

(static) getAllUpcomingEvents(userId) → {Promise.<Array.<UpcomingEvent>>}

Retrieves all upcoming events for a user.
Parameters:
Name Type Description
userId string The ID of the user.
Source:
Returns:
A promise that resolves to an array of UpcomingEvent objects.
Type
Promise.<Array.<UpcomingEvent>>

(static) getAllUsers() → {Promise.<Array>}

Retrieves all users from the database.
Source:
Returns:
A promise that resolves to an array of user objects.
Type
Promise.<Array>

(static) getDayOfWeekShort(dateString) → {string}

Returns a short form of the day of the week for a given date.
Parameters:
Name Type Description
dateString string The date string.
Source:
Returns:
A short form of the day of the week.
Type
string

(static) getEvents(id) → {Promise.<Array>}

Retrieves all events associated with a specific user.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of event objects.
Type
Promise.<Array>

(static) getFollowers(id) → {Promise.<Array>}

Retrieves all followers of a specific user.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of follower user objects.
Type
Promise.<Array>

(static) getFollowersIds(id) → {Promise.<Array>}

Retrieves the IDs of all followers of a specific user.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of follower user IDs.
Type
Promise.<Array>

(static) getFollowing(id) → {Promise.<Array>}

Retrieves all users that a specific user is following.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of following user objects.
Type
Promise.<Array>

(static) getFollowingIds(id) → {Promise.<Array>}

Retrieves the IDs of all users that a specific user is following.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of following user IDs.
Type
Promise.<Array>

(static) getFriends(id) → {Promise.<Array>}

Retrieves all friends (mutual followers) of a specific user.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of friend user objects.
Type
Promise.<Array>

(static) getMonthAbbreviation(dateString) → {string}

Returns the abbreviated form of the month for a given date.
Parameters:
Name Type Description
dateString string The date string.
Source:
Returns:
The abbreviated month name.
Type
string

(static) getMonthIndex(monthName) → {number}

Retrieves the index of a month given its name.
Parameters:
Name Type Description
monthName string The name of the month.
Source:
Returns:
The index of the month.
Type
number

(static) getNotificationCount(userId) → {Promise.<number>}

Retrieves the current count of new notifications for a user.
Parameters:
Name Type Description
userId string The ID of the user.
Source:
Returns:
A promise that resolves to the number of new notifications.
Type
Promise.<number>

(static) getNotificationIds(id) → {Promise.<Array>}

Retrieves the IDs of all notifications for a specific user.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of notification IDs.
Type
Promise.<Array>

(static) getNotifications(id) → {Promise.<Array>}

Retrieves all notifications for a specific user.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of notification objects.
Type
Promise.<Array>

(static) getOwnedFlashcards(userId) → {Promise.<Array>}

Retrieves all flashcards owned by a specific user.
Parameters:
Name Type Description
userId string The ID of the user.
Source:
Returns:
A promise that resolves to an array of flashcard objects.
Type
Promise.<Array>

(static) getOwnedFlashcardsIds(id) → {Promise.<Array>}

Retrieves IDs of all flashcards owned by a specific user.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of flashcard IDs.
Type
Promise.<Array>

(static) getOwnedQuizzes(userId) → {Promise.<Array>}

Retrieves all quizzes owned by a specific user.
Parameters:
Name Type Description
userId string The ID of the user.
Source:
Returns:
A promise that resolves to an array of quiz objects.
Type
Promise.<Array>

(static) getOwnedQuizzesIds(id) → {Promise.<Array>}

Retrieves IDs of all quizzes owned by a specific user.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of quiz IDs.
Type
Promise.<Array>

(static) getPastEvents(userId) → {Promise.<Array.<UpcomingEvent>>}

Retrieves past events for a user.
Parameters:
Name Type Description
userId string The ID of the user.
Source:
Returns:
A promise that resolves to an array of past UpcomingEvent objects.
Type
Promise.<Array.<UpcomingEvent>>

(static) getProfile(userId) → {Promise.<Object>}

Retrieves the profile of a specific user, including personal details and owned/shared content.
Parameters:
Name Type Description
userId string The ID of the user.
Source:
Returns:
A promise that resolves to an object containing the user's profile information.
Type
Promise.<Object>

(static) getSharedFlashcardIds(id) → {Promise.<Array>}

Retrieves the IDs of all flashcards shared by a specific user.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of shared flashcard IDs.
Type
Promise.<Array>

(static) getSharedFlashcards(userId) → {Promise.<Array>}

Retrieves all flashcards shared by a specific user.
Parameters:
Name Type Description
userId string The ID of the user.
Source:
Returns:
A promise that resolves to an array of shared flashcard objects.
Type
Promise.<Array>

(static) getSharedQuizzes(userId) → {Promise.<Array>}

Retrieves all quizzes shared by a specific user.
Parameters:
Name Type Description
userId string The ID of the user.
Source:
Returns:
A promise that resolves to an array of shared quiz objects.
Type
Promise.<Array>

(static) getSharedQuizzesIds(id) → {Promise.<Array>}

Retrieves IDs of all quizzes shared by a specific user.
Parameters:
Name Type Description
id string The ID of the user.
Source:
Returns:
A promise that resolves to an array of shared quiz IDs.
Type
Promise.<Array>

(static) getUpcomingEventIds(userId) → {Promise.<Array.<string>>}

Retrieves IDs of all upcoming events for a user.
Parameters:
Name Type Description
userId string The ID of the user.
Source:
Returns:
A promise that resolves to an array of upcoming event IDs.
Type
Promise.<Array.<string>>

(static) getUpcomingEvents(userId) → {Promise.<Array.<UpcomingEvent>>}

Retrieves upcoming events for a user that are scheduled for the future.
Parameters:
Name Type Description
userId string The ID of the user.
Source:
Returns:
A promise that resolves to an array of future UpcomingEvent objects.
Type
Promise.<Array.<UpcomingEvent>>

(static) getUserById(id) → {Promise.<Object>}

Retrieves a user by their ID.
Parameters:
Name Type Description
id string The ID of the user to retrieve.
Source:
Returns:
A promise that resolves to the user object.
Type
Promise.<Object>

(static) getUsers(userIds) → {Promise.<Array.<User>>}

Retrieves user objects based on a list of user IDs.
Parameters:
Name Type Description
userIds Array.<string> An array of user IDs.
Source:
Returns:
A promise that resolves to an array of User objects.
Type
Promise.<Array.<User>>

(static) incrementNewNotifications(userId) → {Promise.<void>}

Increments the count of new notifications for a user.
Parameters:
Name Type Description
userId string The ID of the user whose notification count is to be incremented.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) isTimestampInFuture(timestamp) → {boolean}

Checks whether a given timestamp is in the future.
Parameters:
Name Type Description
timestamp number The timestamp to be checked.
Source:
Returns:
Returns true if the timestamp is in the future.
Type
boolean

(static) removeFollower(userId, followerId) → {Promise.<void>}

Removes a follower from the followers list of a user.
Parameters:
Name Type Description
userId string The ID of the user whose follower is being removed.
followerId string The ID of the follower to remove.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) removeFollowing(userId, followingId) → {Promise.<void>}

Removes a user from the following list of another user.
Parameters:
Name Type Description
userId string The ID of the user who is unfollowing.
followingId string The ID of the user being unfollowed.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) removeNotificationById(userId, notificationId) → {Promise.<void>}

Removes a notification from a user's notification list.
Parameters:
Name Type Description
userId string The ID of the user.
notificationId string The ID of the notification to remove.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) removeUpcomingEvent(userId, eventId) → {Promise.<boolean>}

Removes an upcoming event from a user's event list.
Parameters:
Name Type Description
userId string The ID of the user.
eventId string The ID of the event to be removed.
Source:
Returns:
A promise that resolves to true if the operation is successful.
Type
Promise.<boolean>

(static) saveUserProfile(userId, updatedProfile) → {Promise.<void>}

Saves updated profile information for a user.
Parameters:
Name Type Description
userId string The ID of the user.
updatedProfile Object The object containing the updated profile fields.
Source:
Returns:
A promise that resolves when the profile update is complete.
Type
Promise.<void>

(static) setNotificationCountToZero(userId) → {Promise.<number>}

Resets the new notifications count to zero for a user.
Parameters:
Name Type Description
userId string The ID of the user.
Source:
Returns:
A promise that resolves to zero, indicating no new notifications.
Type
Promise.<number>

(static) shareFlashcard(userId, sharedWithId, flashcardId) → {Promise.<boolean>}

Shares a flashcard with another user and creates the necessary notifications and events.
Parameters:
Name Type Description
userId string The ID of the user sharing the flashcard.
sharedWithId string The ID of the user with whom the flashcard is shared.
flashcardId string The ID of the flashcard being shared.
Source:
Returns:
A promise that resolves to true if the sharing is successful.
Type
Promise.<boolean>

(static) shareQuiz(userId, sharedWithId, quizId) → {Promise.<boolean>}

Shares a quiz with another user and generates the associated notifications and events.
Parameters:
Name Type Description
userId string The ID of the user sharing the quiz.
sharedWithId string The ID of the user with whom the quiz is shared.
quizId string The ID of the quiz being shared.
Source:
Returns:
A promise that resolves to true if the sharing is successful.
Type
Promise.<boolean>

(static) startFollowing(userId, followingId) → {Promise.<void>}

Initiates the process of one user starting to follow another user.
Parameters:
Name Type Description
userId string The ID of the user who starts following.
followingId string The ID of the user being followed.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) stopFollowing(userId, followingId) → {Promise.<void>}

Stops one user from following another and updates the database accordingly.
Parameters:
Name Type Description
userId string The ID of the user who stops following.
followingId string The ID of the user being unfollowed.
Source:
Returns:
A promise that resolves when the operation is complete.
Type
Promise.<void>

(static) updateArrayUserFields(id, toUpdate)

Updates array fields of a user document.
Parameters:
Name Type Description
id string The ID of the user to update.
toUpdate Object Object containing the array fields to update.
Source:

(static) updateNonArrayUserFields(id, toUpdate)

Updates non-array fields of a user document.
Parameters:
Name Type Description
id string The ID of the user to update.
toUpdate Object Object containing the fields to update.
Source: