The updated author instance with approveStatus set to true.
Approves an author by setting their approveStatus to true. This method is used in the moderation process where admins can approve authors that are pending. The method first checks if the author with the given ID exists in the database. If the author is found, it updates their approveStatus field to true, effectively approving them. If the author does not exist, a NotFoundException is thrown to indicate that the specified author cannot be found.
this is a picture file that we need here for author avatar if you dont provide one we fill it with a default avatar.
the data transfer object containing author details to create
the created author entity
The ID of the author to disapprove.
The updated author instance with approveStatus set to false.
Disapproves an author by setting their approveStatus to false. This method is used in the moderation process where admins can disapprove authors that are pending or revoke approval from previously approved authors. The method first checks if the author with the given ID exists in the database. If the author is found, it updates their approveStatus field to false, effectively disapproving them. If the author does not exist, a NotFoundException is thrown to indicate that the specified author cannot be found.
the pagination and filtering options
a boolean indicating if the request is from an admin (to filter by approval status)
the ID of the currently logged-in user
a paginated list of authors with metadata
Retrieves a paginated list of authors from the database. Supports filtering by approval status, search term, and sorting by various fields including name, creation date, number of favorites, and average rating.
This is the Author Id.
This is the ID of the current user. It is used to determine if the author is favorited by the current user, which allows the frontend to display the correct state for favoriting (e.g., filled heart icon if favorited).
An instance of an author.
This method retrieves a single author from the database using their unique ID. It includes related data such as the count of users who have favorited the author, whether the current user has favorited them, and their books with associated statistics and genres. If no author is found with the provided ID, a NotFoundException is thrown to indicate that the requested resource does not exist.
This is the ID of the author for whom we want to find similar authors based on shared genres.
The minimum number of common genres required for an author to be considered similar.
An array of authors similar to the specified author, each with a count of common genres.
This method is used to find authors that are similar to a specified author based on the genres associated with their books. It first retrieves the target author using their ID. Then, it queries the database for the genres of the target author's books and extracts unique genre IDs. Next, it finds other authors who have books in these genres. The results are processed to count how many genres they have in common with the target author, and only those with a minimum number of shared genres (default is 2) are included in the final result. The similar authors are then sorted by the count of common genres in descending order, and the top 10 results are returned.
This is the ID of the author for whom we want to find similar authors based on shared subjects.
The minimum number of common subjects required for an author to be considered similar.
An array of authors similar to the specified author, each with a count of common subjects.
This method is used to find authors that are similar to a specified author based on the subjects associated with them. It first retrieves the target author using their ID and extracts their subjects into an array. Then, it queries the database for other authors who have any overlapping subjects with the target author. The results are processed to count how many subjects they have in common with the target author, and only those with a minimum number of shared subjects (default is 2) are included in the final result. The similar authors are then sorted by the count of common subjects in descending order, and the top 10 results are returned.
A promise resolving to an object containing the list of authors and the name of the genre.
This method retrieves authors for a genre spotlight feature by first selecting a random genre from a predefined list. It then defines specific keyword filters for each genre to identify relevant books. The method queries the database to find authors who have an approved status and have books that match the genre filters based on the defined keywords. The results include the authors that fit the criteria and the name of the genre, which can be used to display a spotlight section on the frontend, allowing users to explore authors associated with different genres.
The ID of the user for whom to retrieve personalized recommendations.
A promise resolving to an array of objects containing the discover authors content.
This method retrieves content for the "Discover Authors" section by combining a genre spotlight and personalized recommendations. It first calls the getAuthorByGenreSpotlight method to fetch authors related to a randomly selected genre, which provides a dynamic and engaging way for users to discover authors based on different genres. Then, it calls the getRecommendedAuthors method, passing the user's ID, to fetch personalized recommendations based on the user's favorite authors. The results from both methods are structured into an array of objects, each containing a title, subtitle, and the corresponding list of authors. This structured content is intended to be displayed in the "Discover Authors" section, offering users both genre-based discovery and personalized recommendations.
An array of objects, each representing a section of authors for the main page, including the title, subtitle, and the list of authors in that section.
This method is used to gather authors for the main page display. It categorizes authors into three sections: "Newly Added" for the most recently added authors, "Modern Visionaries" for influential contemporary authors (born after 1970), and "Masterminds Behind the Hits" for authors of highly-rated books (average rating of 4 or higher). Each section includes a title, a subtitle describing the category, and a list of authors that meet the criteria. The method returns an array of these sections to be rendered on the main page.
An object containing moderation statistics, data quality metrics, and the top 5 most popular authors.
This method is used to gather statistics for authors that are pending moderation. It retrieves the count of authors awaiting moderation (approveStatus: false), the count of approved authors (approveStatus: true), data quality metrics such as how many authors have a biography and how many have a unique profile picture, and also identifies the top 5 most popular authors based on the number of times they have been favorited by users. The results are returned in a structured format that includes moderation stats, data quality metrics, and the list of top authors.
A promise resolving to an array of influential contemporary authors.
This method is responsible for fetching influential contemporary authors who were born after January 1, 1970, and have been approved for display. It queries the database for authors with approveStatus set to true and a birthDate that is greater than or equal to January 1, 1970. The results are sorted by their createdAt timestamp in descending order to prioritize newer authors, and the output is limited to 15 authors. The method also omits the smallerProfilePicKey and biggerProfilePicKey fields from the returned author data to ensure that sensitive information related to image storage is not exposed.
The ID of the user for whom to retrieve the collection of favorited authors.
A list of authors that the user has added to their collection.
This method is used to get the list of authors that a user has in their collection, which is determined by the authors they have favorited. It performs a database query to find all authors where there is a relation in the favoritedBy table that matches the provided user ID. The result is a list of authors that the user has added to their collection.
A promise resolving to an array of the most recently added and approved authors.
This method is responsible for fetching the most recently added authors that have been approved for display. It queries the database for authors with approveStatus set to true, sorts them by their createdAt timestamp in descending order to get the newest authors first, and limits the results to 15 authors. The method also omits the smallerProfilePicKey and biggerProfilePicKey fields from the returned author data to prevent exposure of sensitive information related to image storage.
The number of authors to retrieve. Defaults to 15 if not specified.
A promise resolving to an array of randomly selected approved authors.
This method retrieves a random selection of authors that have been approved. It begins by counting the total number of authors with approveStatus set to true. If there are no approved authors, it returns an empty array. Otherwise, it generates a random index to skip a random number of records and retrieves a specified number of authors (default is 15) starting from that index. The method also omits the smallerProfilePicKey and biggerProfilePicKey fields from the returned author data to ensure that sensitive information related to image storage is not exposed.
The ID of the user for whom to retrieve personalized author recommendations.
The number of recommended authors to return.
A promise resolving to an object containing the list of recommended authors and information about the author that served as the basis for the recommendations.
This method retrieves personalized author recommendations for a user by first fetching the user's favorite authors from the database. If the user has favorite authors, it randomly selects one of them; if not, it randomly selects any approved author. It then identifies the genres associated with the selected author by querying the book genres linked to that author. Using the identified genres, the method queries the database to find other approved authors who have books in those genres. The results include a list of recommended authors and information about the author that served as the basis for the recommendations, such as their name and profile picture, which can be used to display personalized recommendations on the frontend.
A promise resolving to an array of objects containing the search page content. Each object includes a title, subtitle, and a list of randomly selected approved authors.
This method retrieves content for the author search page by fetching a random selection of approved authors. It utilizes the getRandomAuthors method to obtain a list of random authors and then structures the content into an array of objects, each containing a title, subtitle, and the list of authors. This structured content is intended to be displayed on the author search page, providing users with an engaging way to discover new authors. The method returns this content in a format that can be easily rendered on the frontend.
A promise resolving to an array of top books authors.
This method is responsible for fetching authors whose books have received high ratings (average rating of 4 or higher) and have been approved for display. It queries the database for authors with approveStatus set to true and a related condition that checks if they have at least one book with a statistics record where averageRating is greater than or equal to 4. The results are limited to 15 authors, and the smallerProfilePicKey and biggerProfilePicKey fields are omitted from the returned data to prevent exposure of sensitive information related to image storage.
The Open Library ID of the author to be deleted.
The deleted author instance.
Deletes an author by their Open Library ID. The method first attempts to find the author using the provided Open Library ID. If the author is found, it proceeds to delete any associated profile images from S3. After handling the images, it attempts to delete the author record from the database. If the author has books assigned to them, a ConflictException is thrown to prevent deletion.
the author name (we search with it in external APIs such as Google Book API or Open Library)
Authors matching the name from external APIs. We use this for auto-fill and to avoid duplicates when creating new authors.
This is an ID of an author what you want to update.
This is for uploading a new profile picture for the author. If null is provided, the existing picture will remain unchanged.
This contains the updated author data.
The updated author instance.
Updates an existing author's details. It first checks if the author exists, then if the Open Library ID is being changed, it validates that the new ID is unique. It also performs a soft duplicate check if the name, birth date, or nationality are being changed. If a new profile picture is provided, it uploads the new image to S3 and deletes the old one. Finally, it updates the author record in the database with the new details and image URLs.
The ID of the author to approve.