backend
    Preparing search index...
    Index

    Constructors

    Methods

    • Parameters

      • id: string

        The ID of the author to approve.

      Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              biggerProfilePicKey: string | null;
              bio: string | null;
              birthDate: Date | null;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              smallerProfilePicKey: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          },
      >

      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.

      NotFoundException if the author with the given ID does not exist in the database.

      InternalServerErrorException if there is an error during the database update operation.

    • Parameters

      • file: UploadedFile | null

        this is a picture file that we need here for author avatar if you dont provide one we fill it with a default avatar.

      • createAuthorDto: CreateAuthorDto

        the data transfer object containing author details to create

      Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              biggerProfilePicKey: string | null;
              bio: string | null;
              birthDate: Date | null;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              smallerProfilePicKey: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          },
      >

      the created author entity

      Creates a new author in the database. It checks for duplicates based on Open Library ID and a soft match of name

      ConflictException if an author with the same Open Library ID already exists or if a soft match duplicate is found based on name, birth date, and nationality

      InternalServerErrorException if there is an error during image upload or database save, with rollback of uploaded images if the database save fails

    • Parameters

      • id: string

        The ID of the author to disapprove.

      Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              biggerProfilePicKey: string | null;
              bio: string | null;
              birthDate: Date | null;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              smallerProfilePicKey: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          },
      >

      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.

      NotFoundException if the author with the given ID does not exist in the database.

      InternalServerErrorException if there is an error during the database update operation.

    • Parameters

      • query: PaginationDto

        the pagination and filtering options

      • admin: boolean

        a boolean indicating if the request is from an admin (to filter by approval status)

      • currentUserId: string

        the ID of the currently logged-in user

      Returns Promise<{ data: any; meta: { lastPage: number; page: number; total: number } }>

      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.

      Sorting by average rating is implemented in-memory after fetching the relevant authors and their books, due to limitations in Prisma's ability to sort by related model aggregates that calculate averages.

      InternalServerErrorException if there is a database error during retrieval

    • Parameters

      • id: string

        This is the Author Id.

      • userId: string

        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).

      Returns Promise<
          {
              _count: { favoritedBy: number };
              approveStatus: boolean;
              biggerProfilePic: string | null;
              biggerProfilePicKey: string | null;
              bio: string | null;
              birthDate: Date | null;
              books: (
                  {
                      genres: { genre: { name: string } }[];
                      statistics:
                          | {
                              averageRating: number;
                              bookId: string;
                              id: string;
                              ratingCount: number;
                              readersCount: number;
                              reviewCount: number;
                              wantToReadCount: number;
                          }
                          | null;
                  } & {
                      approveStatus: boolean;
                      authorId: string
                      | null;
                      biggerCoverPic: string;
                      biggerCoverPicKey: string | null;
                      createdAt: Date;
                      description: string;
                      googleBookId: string | null;
                      id: string;
                      latestPublicationYear: number | null;
                      openLibraryId: string | null;
                      originalPublicationYear: number | null;
                      originalPublisher: string | null;
                      pageNumber: number | null;
                      smallerCoverPic: string;
                      smallerCoverPicKey: string | null;
                      title: string;
                      updatedAt: Date;
                  }
              )[];
              createdAt: Date;
              id: string;
              isFavoritedbyCurrentUser: boolean;
              name: string;
              nationality: string
              | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              smallerProfilePicKey: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          },
      >

      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.

      The method also checks if the current user has favorited the author and includes this information in the response, allowing the frontend to display the appropriate UI state for favoriting.

      NotFoundException if the author with the given ID does not exist in the database.

    • Parameters

      • authorId: string

        This is the ID of the author for whom we want to find similar authors based on shared genres.

      • minCommonGenres: number = 2

        The minimum number of common genres required for an author to be considered similar.

      Returns Promise<
          {
              _count: { books: number };
              approveStatus: boolean;
              biggerProfilePic: string | null;
              biggerProfilePicKey: string | null;
              bio: string | null;
              birthDate: Date | null;
              commonCount: number;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              smallerProfilePicKey: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          }[],
      >

      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.

      NotFoundException if the author with the given ID does not exist in the database.

      InternalServerErrorException if there is an error during the database queries to retrieve the authors and their genres.

    • Parameters

      • authorId: string

        This is the ID of the author for whom we want to find similar authors based on shared subjects.

      • minCommon: number = 2

        The minimum number of common subjects required for an author to be considered similar.

      Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              biggerProfilePicKey: string | null;
              bio: string | null;
              birthDate: Date | null;
              commonCount: number;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              smallerProfilePicKey: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          }[],
      >

      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.

      NotFoundException if the author with the given ID does not exist in the database.

      InternalServerErrorException if there is an error during the database queries to retrieve the authors and their subjects.

    • Returns Promise<
          {
              data: {
                  approveStatus: boolean;
                  biggerProfilePic: string
                  | null;
                  biggerProfilePicKey: string | null;
                  bio: string | null;
                  birthDate: Date | null;
                  createdAt: Date;
                  id: string;
                  name: string;
                  nationality: string | null;
                  openLibraryId: string | null;
                  smallerProfilePic: string | null;
                  smallerProfilePicKey: string | null;
                  subjects: string | null;
                  topWorks: string | null;
                  updatedAt: Date;
              }[];
              genre: string;
          },
      >

      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.

    • Parameters

      • userId: string

        The ID of the user for whom to retrieve personalized recommendations.

      Returns Promise<
          (
              | {
                  data: {
                      approveStatus: boolean;
                      biggerProfilePic: string
                      | null;
                      biggerProfilePicKey: string | null;
                      bio: string | null;
                      birthDate: Date | null;
                      createdAt: Date;
                      id: string;
                      name: string;
                      nationality: string | null;
                      openLibraryId: string | null;
                      smallerProfilePic: string | null;
                      smallerProfilePicKey: string | null;
                      subjects: string | null;
                      topWorks: string | null;
                      updatedAt: Date;
                  }[];
                  profilePic?: undefined;
                  subtitle: string;
                  title: string;
              }
              | {
                  data: | never[]
                  | {
                      biggerProfilePic: string
                      | null;
                      id: string;
                      name: string;
                      nationality: string | null;
                      smallerProfilePic: string | null;
                      topWorks: string | null;
                  }[];
                  profilePic: string
                  | null
                  | undefined;
                  subtitle: string;
                  title: string;
              }
          )[],
      >

      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.

    • Returns Promise<
          {
              data: {
                  approveStatus: boolean;
                  biggerProfilePic: string
                  | null;
                  bio: string | null;
                  birthDate: Date | null;
                  createdAt: Date;
                  id: string;
                  name: string;
                  nationality: string | null;
                  openLibraryId: string | null;
                  smallerProfilePic: string | null;
                  subjects: string | null;
                  topWorks: string | null;
                  updatedAt: Date;
              }[];
              subtitle: string;
              title: string;
          }[],
      >

      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.

      InternalServerErrorException if there is an error during the database queries to retrieve the authors for any of the sections.

    • Returns Promise<
          {
              dataQuality: { totalWithBio: number; totalWithPic: number };
              moderation: { approved: number; pending: number };
              topAuthors: { _count: { favoritedBy: number }; name: string }[];
          },
      >

      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.

      InternalServerErrorException if there is an error during the database queries to retrieve the statistics.

    • Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              bio: string | null;
              birthDate: Date | null;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          }[],
      >

      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.

    • Parameters

      • userId: string

        The ID of the user for whom to retrieve the collection of favorited authors.

      Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              biggerProfilePicKey: string | null;
              bio: string | null;
              birthDate: Date | null;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              smallerProfilePicKey: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          }[],
      >

      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.

      InternalServerErrorException if there is an error during the database query to retrieve the authors.

    • Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              bio: string | null;
              birthDate: Date | null;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          }[],
      >

      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.

    • Parameters

      • take: number = 15

        The number of authors to retrieve. Defaults to 15 if not specified.

      Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              bio: string | null;
              birthDate: Date | null;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          }[],
      >

      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.

      InternalServerErrorException if there is an error during the database queries to count the authors or retrieve the random selection.

    • Parameters

      • userId: string

        The ID of the user for whom to retrieve personalized author recommendations.

      • take: number = 15

        The number of recommended authors to return.

      Returns Promise<
          | {
              basedOn?: undefined;
              data: never[];
              subtitle: string;
              title: string;
          }
          | {
              basedOn: { name: string; smallerProfilePic: string | null }
              | null;
              data: {
                  biggerProfilePic: string | null;
                  id: string;
                  name: string;
                  nationality: string | null;
                  smallerProfilePic: string | null;
                  topWorks: string | null;
              }[];
              subtitle?: undefined;
              title?: undefined;
          },
      >

      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.

    • Returns Promise<
          {
              data: {
                  approveStatus: boolean;
                  biggerProfilePic: string
                  | null;
                  bio: string | null;
                  birthDate: Date | null;
                  createdAt: Date;
                  id: string;
                  name: string;
                  nationality: string | null;
                  openLibraryId: string | null;
                  smallerProfilePic: string | null;
                  subjects: string | null;
                  topWorks: string | null;
                  updatedAt: Date;
              }[];
              subtitle: string;
              title: string;
          }[],
      >

      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.

      InternalServerErrorException if there is an error during the retrieval of random authors for the search page content.

    • Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              bio: string | null;
              birthDate: Date | null;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          }[],
      >

      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.

    • Parameters

      • id: string

      Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              biggerProfilePicKey: string | null;
              bio: string | null;
              birthDate: Date | null;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              smallerProfilePicKey: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          },
      >

    • Parameters

      • olId: string

        The Open Library ID of the author to be deleted.

      Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              biggerProfilePicKey: string | null;
              bio: string | null;
              birthDate: Date | null;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              smallerProfilePicKey: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          },
      >

      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.

      NotFoundException if there is no author with the given Open Library ID.

      ConflictException if the author cannot be deleted because there are books assigned to them.

    • Parameters

      • name: string

        the author name (we search with it in external APIs such as Google Book API or Open Library)

      Returns Promise<any[]>

      Authors matching the name from external APIs. We use this for auto-fill and to avoid duplicates when creating new authors.

      Searches for authors in external APIs (currently Open Library) based on the provided name. This is used to help auto-fill author details and prevent duplicates when creating new authors.

    • Parameters

      • id: string

        This is an ID of an author what you want to update.

      • file: UploadedFile | null

        This is for uploading a new profile picture for the author. If null is provided, the existing picture will remain unchanged.

      • updateAuthorDto: UpdateAuthorDto

        This contains the updated author data.

      Returns Promise<
          {
              approveStatus: boolean;
              biggerProfilePic: string
              | null;
              biggerProfilePicKey: string | null;
              bio: string | null;
              birthDate: Date | null;
              createdAt: Date;
              id: string;
              name: string;
              nationality: string | null;
              openLibraryId: string | null;
              smallerProfilePic: string | null;
              smallerProfilePicKey: string | null;
              subjects: string | null;
              topWorks: string | null;
              updatedAt: Date;
          },
      >

      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.

      NotFoundException if the author with the given ID does not exist in the database.

      ConflictException if the new Open Library ID (if provided) already exists for another author, or if a soft match duplicate is found based on name, birth date