backend
    Preparing search index...
    Index

    Constructors

    Methods

    • Parameters

      • id: string

        The unique identifier of the book to be approved. This ID is used to locate the specific book record in the database that needs to be updated.

      Returns Promise<
          {
              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;
          },
      >

      The updated book record with approveStatus set to true if the operation is successful. If the book is not found, it returns a NotFoundException. If any other error occurs, it returns an InternalServerErrorException.

      This method is used to approve a book entry in the database by updating its approveStatus field to true. It first attempts to find and update the book record based on the provided ID. If the book is not found, it catches the specific error code (P2025) thrown by Prisma and responds with a NotFoundException indicating that the book does not exist. For any other errors that may occur during the update process, it logs the error and throws a generic InternalServerErrorException to indicate that an error occurred while approving the book.

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

    • Parameters

      • file: UploadedFile | null

        An optional uploaded file for the book cover image. If not provided, default images will be used.

      • createBookDto: CreateBookDto

        A DTO containing the details of the book to be created, including title, description, identifiers (ISBNs, Google Book ID, Open Library ID), author information, publication details, and genre names.

      Returns Promise<
          {
              author: | {
                  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;
              }
              | null;
              genres: (
                  { genre: { id: string; name: string } } & {
                      bookId: string;
                      genreId: string;
                  }
              )[];
              isbns: { bookId: string; id: string; isbnNumber: 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;
          },
      >

      The created book record, including associated genres and ISBNs.

      ConflictException if a book with the same ISBN, Google Book ID, or Open Library ID already exists.

      InternalServerErrorException if there is an error during S3 upload or database operations.

      The method performs a duplicate check to prevent multiple entries of the same book based on key identifiers. It also ensures that any uploaded images are rolled back (deleted from S3) if the database operation fails, maintaining data integrity between S3 and the database.

    • Parameters

      • id: string

        The unique identifier of the book to be disapproved.

      Returns Promise<
          {
              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;
          },
      >

      The updated book record with approveStatus set to false if the operation is successful.

      This method is used to disapprove a book entry in the database by updating its approveStatus field to false. Similar to the approve method, it attempts to find and update the book record based on the provided ID. If the book is not found, it catches the specific error code (P2025) thrown by Prisma and responds with a NotFoundException indicating that the book does not exist. For any other errors that may occur during the update process, it logs the error and throws a generic InternalServerErrorException to indicate that an error occurred while disapproving the book.

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

    • Parameters

      • isbn: string

        The ISBN number of the book to be fetched from the Google Books API. The method will clean the ISBN by removing any hyphens or spaces before making the API request.

      Returns Promise<ExternalBookResponse | null>

      A structured object containing the book data retrieved from the Google Books API, including title, authors, description, genres, page count, publisher, publication year, language, and all associated ISBNs. If the book is not found or an error occurs during the fetch process, it returns null.

      This method takes an ISBN number as input, cleans it by removing any hyphens or spaces, and constructs a query URL to fetch book data from the Google Books API. It uses the HttpService to make a GET request to the API and retrieves the book information. If the API returns no items or an error occurs during the fetch process, it logs the error and returns null. The method extracts relevant information from the API response, such as title, authors, description, genres, page count, publisher, publication year, language, and all associated ISBNs, and returns it in a structured format as an ExternalBookResponse object.

      The method includes error handling to log any issues that arise during the API call, ensuring that the application can gracefully handle scenarios where the Google Books API is unavailable or returns unexpected data. It also ensures that the returned data is normalized and structured for consistent use within the application.

    • Parameters

      • query: PaginationDto

        An object containing pagination and sorting parameters, including page number, limit of items per page, search term for filtering by name, sorting field, and sorting order (ascending or descending).

      • admin: boolean
      • userId: string

      Returns Promise<
          {
              data: {
                  approveStatus: boolean;
                  author: { id: string; name: string }
                  | null;
                  authorId: string | null;
                  biggerCoverPic: string;
                  biggerCoverPicKey: string | null;
                  commentCount: number;
                  createdAt: Date;
                  description: string;
                  favoriteCount: number;
                  genres: { genre: { name: string } }[];
                  googleBookId: string | null;
                  id: string;
                  isFavorited: boolean;
                  latestPublicationYear: number | null;
                  openLibraryId: string | null;
                  originalPublicationYear: number | null;
                  originalPublisher: string | null;
                  pageNumber: number | null;
                  smallerCoverPic: string;
                  smallerCoverPicKey: string | null;
                  statistics: { averageRating: number; ratingCount: number } | null;
                  title: string;
                  updatedAt: Date;
              }[];
              meta: {
                  hasNextPage: boolean;
                  hasPreviousPage: boolean;
                  lastPage: number;
                  page: number;
                  total: number;
              };
          },
      >

      A promise resolving to an object containing the list of genres and pagination metadata. The genres are returned based on the applied search and sorting criteria, and the metadata provides information about the total number of genres, current page, last page, and navigation availability for next and previous pages.

      This method fetches genres from the database based on the provided pagination and sorting parameters. It supports searching genres by name using a case-insensitive partial match. The sorting can be done by genre name, number of favorites, number of books, creation date, or average rating. When sorting by average rating, it performs a more complex query to calculate the average rating for each genre. The response includes the list of genres along with metadata about the total number of genres, current page, last page, and whether there are next or previous pages available.

      The method includes error handling to catch and log any issues that arise during the database query process, ensuring that the application can gracefully handle errors and provide informative feedback to the client.

    • Parameters

      • whereCondition: any

        An object representing the filtering conditions to apply when retrieving books. This can include various criteria such as approval status, author ID, genre ID, or any other relevant fields that can be used to filter the book records in the database.

      • skip: number

        The number of records to skip for pagination purposes. This is calculated based on the current page and the limit of items per page.

      • limit: number

        The maximum number of book records to return in the response for the current page.

      • sortOrder: "asc" | "desc"

        The order in which to sort the books based on their average rating. It can be either 'asc' for ascending order or 'desc' for descending order.

      • userId: string

      Returns Promise<
          {
              data: {
                  approveStatus: boolean;
                  author: { id: string; name: string }
                  | null;
                  authorId: string | null;
                  biggerCoverPic: string;
                  biggerCoverPicKey: string | null;
                  commentCount: number;
                  createdAt: Date;
                  description: string;
                  favoriteCount: number;
                  genres: (
                      { genre: { name: string } } & { bookId: string; genreId: string }
                  )[];
                  googleBookId: string | null;
                  id: string;
                  isFavorited: boolean;
                  latestPublicationYear: number | null;
                  openLibraryId: string | null;
                  originalPublicationYear: number | null;
                  originalPublisher: string | null;
                  pageNumber: number | null;
                  smallerCoverPic: string;
                  smallerCoverPicKey: string | null;
                  statistics: { averageRating: number; ratingCount: number } | null;
                  title: string;
                  updatedAt: Date;
              }[];
              meta: {
                  hasNextPage: boolean;
                  hasPreviousPage: boolean;
                  lastPage: number;
                  page: number;
                  total: number;
              };
          },
      >

      A promise resolving to the paginated list of books sorted by rating along with pagination metadata.

      This method fetches books from the database based on the provided filtering conditions, pagination parameters, and sorting order. It includes related data such as the author's name, genre names, and rating statistics (average rating and rating count). The books are sorted by their average rating in either ascending or descending order as specified. The response includes metadata about the total number of books matching the conditions, current page, and last page to facilitate client-side pagination.

    • Parameters

      • id: string

        The ID of the book to retrieve.

      • userId: string

      Returns Promise<
          {
              foundBook: {
                  _count: { favoritedBy: number };
                  approveStatus: boolean;
                  author:
                      | {
                          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;
                      }
                      | null;
                  authorId: string
                  | null;
                  biggerCoverPic: string;
                  biggerCoverPicKey: string | null;
                  comments: {
                      _count: { votes: number };
                      bookId: string;
                      createdAt: Date;
                      id: string;
                      isLikedByMe: boolean;
                      likeCount: number;
                      text: string;
                      user: {
                          biggerProfilePic: string | null;
                          biggerProfilePicKey: string | null;
                          createdAt: Date;
                          email: string;
                          id: string;
                          nickname: string | null;
                          smallerProfilePic: string | null;
                          smallerProfilePicKey: string | null;
                          updatedAt: Date;
                          username: string;
                      };
                      userId: string;
                      votes: { commentId: string; userId: string }[];
                  }[];
                  createdAt: Date;
                  description: string;
                  favoritedBy: { bookId: string; userId: string }[];
                  genres: (
                      { genre: { id: string; name: string } } & {
                          bookId: string;
                          genreId: string;
                      }
                  )[];
                  googleBookId: string
                  | null;
                  id: string;
                  isbns: { bookId: string; id: string; isbnNumber: string }[];
                  isLikedByMe: boolean;
                  latestPublicationYear: number | null;
                  openLibraryId: string | null;
                  originalPublicationYear: number | null;
                  originalPublisher: string | null;
                  pageNumber: number | null;
                  ratings: {
                      bookId: string;
                      createdAt: Date;
                      score: number;
                      userId: string;
                  }[];
                  smallerCoverPic: string;
                  smallerCoverPicKey: string
                  | null;
                  statistics:
                      | {
                          averageRating: number;
                          bookId: string;
                          id: string;
                          ratingCount: number;
                          readersCount: number;
                          reviewCount: number;
                          wantToReadCount: number;
                      }
                      | null;
                  title: string;
                  updatedAt: Date;
              };
              similarBooks: (
                  {
                      author: | {
                          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;
                      }
                      | null;
                      genres: (
                          { genre: { id: string; name: string } } & {
                              bookId: string;
                              genreId: string;
                          }
                      )[];
                      isbns: { bookId: string; id: string; isbnNumber: 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;
                  }
              )[];
          },
      >

      A promise resolving to the book details or an error if the book is not found.

      This method fetches a book from the database based on the provided ID. It includes related data such as the author's name, genre names, and rating statistics.

      The method handles errors gracefully by checking for specific error codes to determine if the book was not found and responding with appropriate exceptions. If the book is successfully retrieved, it returns the complete details of the book along with its related data.

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

      InternalServerErrorException if an error occurs while fetching the book details.

    • Parameters

      • isbn: string

        The ISBN number of the book to retrieve. The method will clean the ISBN by removing any hyphens or spaces before processing.

      Returns Promise<
          {
              book: {
                  author: { name: string }
                  | null;
                  genres: (
                      { genre: { id: string; name: string } } & {
                          bookId: string;
                          genreId: string;
                      }
                  )[];
                  isbns: { bookId: string; id: string; isbnNumber: 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;
              };
          } & { bookId: string; id: string; isbnNumber: string },
      >

      A promise resolving to the book details or an error if the book is not found.

      This method is designed to fetch a book's details based on its ISBN number. It queries the database for a unique record matching the provided ISBN and includes related information such as the author's name, genre names, and rating statistics. The method handles errors gracefully by checking for specific error codes to determine if the book was not found and responding with appropriate exceptions. If the book is successfully retrieved, it returns the complete details of the book along with its related data.

      NotFoundException if the book with the given ISBN does not exist in the database.

      InternalServerErrorException if an error occurs while fetching the book details.

    • Returns Promise<
          | {
              author: | {
                  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;
              }
              | null;
              genres: (
                  { genre: { id: string; name: string } } & {
                      bookId: string;
                      genreId: string;
                  }
              )[];
              isbns: { bookId: string; id: string; isbnNumber: 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;
          }
          | null,
      >

      A promise resolving to the randomly selected book. The book includes its statistics, comments, genres, and ISBNs.

      This method is designed to provide users with a random book recommendation. It first counts the total number of books in the database that have been approved for display, then generates a random index within that count. Using this index, it retrieves a single book from the database, ensuring that the book is approved and includes related information such as statistics (e.g., average rating, rating count), comments from users, associated genres with their names, and ISBNs. The method handles any potential errors that may occur during the database query process, ensuring that appropriate exceptions are thrown if issues arise while fetching the random book.

      InternalServerErrorException if an error occurs while fetching the random book from the database. The method includes error handling to ensure that any issues encountered during the query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client if there are issues while retrieving the random book.

    • Parameters

      • genre: GenreType

        The genre for which to retrieve books. The genre is used to determine the relevant keywords for filtering the books in the database query.

      • take: number = 15

        The number of books to retrieve.

      Returns Promise<
          (
              {
                  author: { name: string }
                  | null;
                  comments: {
                      bookId: string;
                      createdAt: Date;
                      id: string;
                      text: string;
                      userId: string;
                  }[];
                  genres: (
                      { genre: { name: string } } & { bookId: string; genreId: string }
                  )[];
                  isbns: { bookId: string; id: string; isbnNumber: 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;
              }
          )[],
      >

      A list of books that fit the genre criteria, along with related information. Each book includes its statistics, comments, genres, and ISBNs.

      This method defines a set of keyword filters for each genre and constructs a query to retrieve books that match the criteria for the specified genre. It includes conditions to ensure that only approved books are fetched and allows for the inclusion of books that contain certain keywords in their genres while excluding others if specified. The method returns a list of books that fit the genre criteria, along with related information such as statistics (e.g., average rating, rating count), comments from users, associated genres with their names, and ISBNs.

      InternalServerErrorException if an error occurs while fetching the books for the specified genre. The method includes error handling to ensure that any issues encountered during the database query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client.

    • Parameters

      • section: "top-rated" | "hidden-gems" | "essentials"

        The section for which to retrieve books (e.g., 'top-rated', 'hidden-gems', 'essentials').

      • take: number = 15

        The number of books to retrieve.

      • where: any

        The query conditions for filtering books.

      Returns Promise<
          | (
              {
                  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;
              }
          )[]
          | undefined,
      >

      A list of books that fit the criteria for the specified section. Each book includes its statistics.

      This method defines a set of keyword filters for each genre and constructs a query to retrieve books that match the criteria for the specified genre. It organizes the retrieved books into different sections based on their ratings and popularity, such as Top Rated (books with the highest average ratings), Hidden Gems (underrated books that may not have high ratings but are considered valuable), and Essentials (must-read books for enthusiasts of the genre). Each book in these sections includes related information such as statistics (e.g., average rating, rating count), comments from users, associated genres with their names, and ISBNs. The method ensures that only approved books are retrieved and that the results are organized to highlight different aspects of the genre for users to explore.

      The method includes error handling to ensure that any issues encountered during the database query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client if there are issues while fetching the books for the specified genre sections.

      InternalServerErrorException if an error occurs while fetching the books for the specified genre section. The method includes error handling to ensure that any issues encountered during the database query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client.

    • Parameters

      • genre: GenreType

        The genre for which to retrieve books.

      • take: number = 15

        The number of books to retrieve.

      Returns Promise<
          {
              data: | (
                  {
                      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;
                  }
              )[]
              | undefined;
              subtitle: string;
              title: string;
          }[],
      >

      A list of books that fit the genre criteria, along with related information. Each book includes its statistics, comments, genres, and ISBNs.

      This method defines a set of keyword filters for each genre and constructs a query to retrieve books that match the criteria for the specified genre. It includes conditions to ensure that only approved books are fetched and allows for the inclusion of books that contain certain keywords in their genres while excluding others if specified. The method returns a list of books that fit the genre criteria, along with related information such as statistics (e.g., average rating, rating count), comments from users, associated genres with their names, and ISBNs. This method is specifically designed to support the genre spotlight section on the main page, providing handpicked essential books for lovers of the selected genre.

      The method includes error handling to ensure that any issues encountered during the database query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client if there are issues while fetching the books for the specified genre.

      InternalServerErrorException if an error occurs while fetching the books for the specified genre. The method includes error handling to ensure that any issues encountered during the database query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client.

    • Parameters

      • take: number = 15

        The number of books to retrieve. The method will return up to this number of entries, ordered by their average rating in descending order to ensure that the most popular titles are displayed first.

      Returns Promise<
          (
              {
                  author: { name: string }
                  | null;
                  comments: {
                      bookId: string;
                      createdAt: Date;
                      id: string;
                      text: string;
                      userId: string;
                  }[];
                  genres: (
                      { genre: { name: string } } & { bookId: string; genreId: string }
                  )[];
                  isbns: { bookId: string; id: string; isbnNumber: string }[];
                  statistics:
                      | {
                          averageRating: number;
                          bookId: string;
                          id: string;
                          ratingCount: number;
                          readersCount: number;
                          reviewCount: number;
                          wantToReadCount: number;
                      }
                      | null;
              } & {
                  approveStatus: boolean;
                  authorId: string
                  | null;
                  biggerCoverPic: string;
                  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;
                  title: string;
                  updatedAt: Date;
              }
          )[],
      >

      A promise resolving to an array of the top 15 crowd favorite books, each including its statistics, comments, and genres. The method ensures that only approved books are retrieved and that the results are ordered by average rating in descending order.

      This method fetches the books that are considered crowd favorites by ordering them based on their average rating in descending order. It limits the results to the top 15 entries and includes related information such as statistics (e.g., average rating, rating count), comments from users, and associated genres with their names. The method ensures that only approved books are retrieved and that the results are sorted to highlight the most popular titles according to user ratings.

    • Parameters

      • userId: string

        The ID of the user for whom to retrieve the discover page content. The method uses this ID to fetch personalized recommendations based on the user's favorite authors, loved books, and other interactions with the platform.

      Returns Promise<
          (
              | {
                  data: (
                      {
                          comments: {
                              bookId: string;
                              createdAt: Date;
                              id: string;
                              text: string;
                              userId: string;
                          }[];
                          genres: (
                              { genre: { name: ... } } & { bookId: string; genreId: string }
                          )[];
                          isbns: { bookId: string; id: string; isbnNumber: 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;
                      }
                  )[];
                  image?: undefined;
                  profilePic: string
                  | null;
                  subtitle: string;
                  title: string;
              }
              | {
                  data: (
                      {
                          author: { name: string }
                          | null;
                          genres: (
                              { genre: { id: ...; name: ... } } & {
                                  bookId: string;
                                  genreId: 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;
                      }
                  )[];
                  image: null;
                  profilePic?: undefined;
                  subtitle: string;
                  title: string;
              }
              | {
                  data: (
                      {
                          author: { name: string }
                          | null;
                          comments: {
                              bookId: string;
                              createdAt: Date;
                              id: string;
                              text: string;
                              userId: string;
                          }[];
                          genres: (
                              { genre: { name: ... } } & { bookId: string; genreId: string }
                          )[];
                          isbns: { bookId: string; id: string; isbnNumber: 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;
                      }
                  )[];
                  image: null;
                  profilePic?: undefined;
                  subtitle: string;
                  title: string;
              }
              | {
                  data: (
                      {
                          author: { name: string }
                          | null;
                          genres: (
                              { genre: { id: ...; name: ... } } & {
                                  bookId: string;
                                  genreId: 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;
                      }
                  )[];
                  image: string
                  | undefined;
                  profilePic?: undefined;
                  subtitle: string | undefined;
                  title: string;
              }
          )[],
      >

      A promise resolving to an array of objects containing the discover page content. Each object includes a title, subtitle, and a list of books that fit the criteria for that category.

      This method fetches various types of book recommendations for the discover page based on the user's preferences and interactions.

      The method includes sections such as "For the Fans of" which highlights books from the user's favorite authors, "Following the Echoes of" which features books similar to those the user has loved, and "More [Genre], Just For You" which offers a selection of books from a randomly selected genre. Each section is structured with a title, subtitle, and a list of books that fit the criteria for that category. The method ensures that the content is personalized and relevant to the user's interests while also providing a diverse range of recommendations to encourage exploration.

    • Parameters

      • take: number = 15

        The number of books to retrieve.

      Returns Promise<
          {
              data: (
                  {
                      author: { name: string }
                      | null;
                      comments: {
                          bookId: string;
                          createdAt: Date;
                          id: string;
                          text: string;
                          userId: string;
                      }[];
                      genres: (
                          { genre: { name: string } } & { bookId: string; genreId: string }
                      )[];
                      isbns: { bookId: string; id: string; isbnNumber: 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;
                  }
              )[];
              subtitle: string;
              title: string;
          },
      >

      A promise resolving to an object containing the title, subtitle, and a list of books for the genre spotlight section. The books included in this section are handpicked essentials for lovers of the randomly selected genre, and each book includes its statistics, comments, and genres.

      This method creates a spotlight section for a randomly selected genre by first choosing a genre from a predefined list of genres. It then constructs a title and subtitle for the spotlight section based on the selected genre. The method fetches books that are relevant to the chosen genre using specific criteria defined in the getBooksByASpecificGenre helper method. Each book in the spotlight section includes related information such as statistics (e.g., average rating, rating count), comments from users, and associated genres with their names. The method ensures that only approved books are retrieved and that the results are tailored to highlight essential reads for fans of the selected genre.

    • Parameters

      • take: number = 15

        The maximum number of latest added books to retrieve. The method will return up to this number of entries, ordered by their creation date in descending order.

      Returns Promise<
          (
              {
                  author: { name: string }
                  | null;
                  comments: {
                      bookId: string;
                      createdAt: Date;
                      id: string;
                      text: string;
                      userId: string;
                  }[];
                  genres: (
                      { genre: { name: string } } & { bookId: string; genreId: string }
                  )[];
                  isbns: { bookId: string; id: string; isbnNumber: 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;
              }
          )[],
      >

      A promise resolving to an array of the latest added books, each including its statistics, comments, and genres. The method ensures that only approved books are retrieved and that the results are limited to the specified number of entries.

      This method fetches the most recently added books from the database that have been approved for display. It limits the results to the specified number of entries and includes related information such as statistics (e.g., average rating, rating count), comments from users, and associated genres with their names. The books are ordered by their creation date in descending order to ensure that the newest additions are displayed first.

      The method includes error handling to catch and log any issues that arise during the database query process, ensuring that the application can gracefully handle errors and provide informative feedback to the client if there are issues while fetching the latest added books.

    • Parameters

      • take: number = 15

        The maximum number of similar books to retrieve. The method will return up to this number of entries based on the shared genres with the latest approved book.

      Returns Promise<
          {
              coverImage: string;
              data: (
                  {
                      author: { name: string }
                      | null;
                      genres: (
                          { genre: { id: string; name: string } } & {
                              bookId: string;
                              genreId: 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;
                  }
              )[];
              title: string;
          },
      >

      A promise resolving to an object containing the title, cover image, and similar books data.

      This method provides users with book recommendations based on the latest approved book in the database. It first identifies the latest approved book by ordering books by their creation date in descending order and selecting the first entry. Then, it retrieves books that share at least one genre with the latest book, ensuring that the latest book itself is excluded from the results. Each similar book includes related information such as statistics (e.g., average rating, rating count), comments from users, and associated genres with their names. The method handles any potential errors that may arise during the database queries, ensuring that appropriate exceptions are thrown if there are problems while fetching similar books based on shared genres with the latest approved book.

    • Parameters

      • take: number = 15

        The maximum number of similar books to retrieve. The method will return up to this number of entries based on the shared genres with the randomly selected loved book or random book if the user has no loved books.

      • userId: string

        The ID of the user for whom to retrieve similar books.

      Returns Promise<
          {
              coverImage: string;
              data: (
                  {
                      author: { name: string }
                      | null;
                      genres: (
                          { genre: { id: string; name: string } } & {
                              bookId: string;
                              genreId: 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;
                  }
              )[];
              title: string;
          },
      >

      A promise resolving to an object containing the title, cover image, and similar books data. If the user has no loved books, the method returns similar books based on a random book from the database instead.

      This method provides users with book recommendations based on their loved books. It first retrieves a random book from the user's list of loved books. If the user has no loved books, it retrieves a random approved book from the database. Then, it fetches books that share at least one genre with the selected book, ensuring that the selected book itself is excluded from the results. Each similar book includes related information such as statistics (e.g., average rating, rating count), comments from users, and associated genres with their names. The method handles any potential errors that may arise during the database queries, ensuring that appropriate exceptions are thrown if there are problems while fetching similar books based on shared genres with the randomly selected loved book or random book if the user has no loved books.

      InternalServerErrorException if an error occurs while retrieving similar books from the database. The method includes error handling to ensure that any issues encountered during the query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client if there are issues while fetching similar books based on shared genres with the randomly selected loved book or random book if the user has no loved books.

    • Returns Promise<
          {
              data: (
                  {
                      author: { name: string }
                      | null;
                      comments: {
                          bookId: string;
                          createdAt: Date;
                          id: string;
                          text: string;
                          userId: string;
                      }[];
                      genres: (
                          { genre: { name: string } } & { bookId: string; genreId: string }
                      )[];
                      isbns: { bookId: string; id: string; isbnNumber: string }[];
                      statistics:
                          | {
                              averageRating: number;
                              bookId: string;
                              id: string;
                              ratingCount: number;
                              readersCount: number;
                              reviewCount: number;
                              wantToReadCount: number;
                          }
                          | null;
                  } & {
                      approveStatus: boolean;
                      authorId: string
                      | null;
                      biggerCoverPic: string;
                      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;
                      title: string;
                      updatedAt: Date;
                  }
              )[];
              subtitle: string;
              title: string;
          }[],
      >

      A promise resolving to an array of curated book sections. Each section contains a title, subtitle, and a list of books that fit the specific criteria for that category. The sections include Latest Added, Crowd Favorites, Short & Sweet, Weekend Reads, Genre Spotlights, Multi-Edition Hits, and Oldies but Goldies.

      This method compiles various sections of books to be displayed on the main page of the application. It fetches different sets of books based on specific criteria, such as the most recently added books, the highest-rated books according to user ratings, shorter books that can be read quickly, books suitable for weekend reading, a spotlight on a random genre with handpicked essentials, books that have multiple editions indicating their popularity and longevity, and classic books that have stood the test of time. Each section is structured with a title, a subtitle that provides context for the category, and the corresponding list of books that meet the criteria for that section.

      The method includes error handling to ensure that any issues encountered while fetching the different sets of books are properly logged and handled, allowing the application to gracefully manage errors and provide a consistent user experience on the main page. It also utilizes helper methods to fetch books for each specific category, ensuring that the logic for retrieving books is organized and maintainable.

      InternalServerErrorException if an error occurs while fetching any of the book sections for the main page. Each helper method responsible for fetching a specific category of books includes its own error handling to ensure that issues are properly logged and managed.

    • Parameters

      • take: number = 15

        The number of books to retrieve.

      Returns Promise<
          (
              {
                  author: { name: string }
                  | null;
                  comments: {
                      bookId: string;
                      createdAt: Date;
                      id: string;
                      text: string;
                      userId: string;
                  }[];
                  genres: (
                      { genre: { name: string } } & { bookId: string; genreId: string }
                  )[];
                  isbns: { bookId: string; id: string; isbnNumber: 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;
              }
          )[],
      >

      A list of books that have multiple editions, along with related information. Each book includes its statistics, comments, genres, and ISBNs.

      This method identifies books that have multiple editions by counting the number of associated ISBNs for each book. It retrieves approved books from the database and orders them based on the count of their ISBNs in descending order, which serves as an indicator of their popularity and longevity. The method limits the results to the top 15 entries and includes related information such as statistics (e.g., average rating, rating count), comments from users, associated genres with their names, and ISBNs for each book. This allows users to discover books that have been reprinted or have multiple editions, suggesting that they are well-loved and have stood the test of time.

    • Parameters

      • userId: string

        The ID of the user whose collections content is to be retrieved.

      Returns Promise<
          (
              {
                  genres: (
                      { genre: { id: string; name: string } } & {
                          bookId: string;
                          genreId: 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;
              }
          )[],
      >

      A list of books that are part of the user's collections.

      This method is designed to fetch the content of a user's collections by leveraging the relationship between books and users in the database. It uses the Prisma ORM to query the book records that are associated with the given user ID through the favoritedBy relation. The method handles any potential errors that may arise during the database query and ensures that a meaningful error message is returned if there is an issue fetching the collections content.

      InternalServerErrorException if there is an error fetching the user's collections content from the database.

    • Parameters

      • take: number = 15

        The number of books to retrieve.

      Returns Promise<
          (
              {
                  author: { name: string }
                  | null;
                  comments: {
                      bookId: string;
                      createdAt: Date;
                      id: string;
                      text: string;
                      userId: string;
                  }[];
                  genres: (
                      { genre: { name: string } } & { bookId: string; genreId: string }
                  )[];
                  isbns: { bookId: string; id: string; isbnNumber: 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;
              }
          )[],
      >

      A list of classic books that have stood the test of time, along with related information. Each book includes its statistics, comments, genres, and ISBNs.

      This method identifies "Oldies but Goldies" by filtering books based on their original publication year, specifically those that were published before the year 2000. It retrieves approved books from the database that meet this criterion and limits the results to the top 15 entries. Each book in this category includes related information such as statistics (e.g., average rating, rating count), comments from users, associated genres with their names, and ISBNs. This allows users to discover classic books that have been cherished over time and have made a lasting impact on readers.

    • Parameters

      • isbn: string

        The ISBN number of the book to be retrieved. The method will clean the ISBN by removing any hyphens or spaces before processing.

      Returns Promise<
          | {
              book?: undefined;
              existingBooksFromAuthor?: undefined;
              externalBook?: undefined;
              status: string;
          }
          | {
              book: | {
                  author: | {
                      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;
                  }
                  | null;
                  genres: (
                      { genre: { id: string; name: string } } & {
                          bookId: string;
                          genreId: string;
                      }
                  )[];
                  isbns: { bookId: string; id: string; isbnNumber: string }[];
              } & {
                  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;
              }
              | null;
              existingBooksFromAuthor?: undefined;
              externalBook?: undefined;
              status: string;
          }
          | {
              book?: undefined;
              existingBooksFromAuthor: (
                  { isbns: { bookId: string; id: string; isbnNumber: string }[] } & {
                      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;
                  }
              )[];
              externalBook: ExternalBookResponse;
              status: string;
          }
          | {
              book: ExternalBookResponse;
              existingBooksFromAuthor?: undefined;
              externalBook?: undefined;
              status: string;
          },
      >

      An object containing the status of the retrieval process and the book data if found. The status can indicate whether the book already exists in the local database, was found through external APIs, linked to an existing entry, or if it is a possible translation based on author information.

      This method is designed to efficiently retrieve book information using an ISBN. It performs a local database check to prevent unnecessary external API calls. If the book is not found locally, it fetches data from both Open Library and Google Books APIs simultaneously to minimize latency. The fetched data is then merged, and the method checks for potential matches in the local database based on Google Book ID, Open Library ID, and author information to determine if the book can be linked to an existing entry or if it is a new discovery. The method returns a structured response indicating the status of the retrieval process and the relevant book data.

      The method uses a structured approach to handle multiple scenarios, including duplicate prevention, data merging from multiple sources, and intelligent matching based on identifiers and author information. It also includes logging for debugging purposes, especially when fetching data from external APIs.

    • Parameters

      • take: number = 15

        The number of random books to retrieve. The method will return up to this number of entries based on the randomly generated index.

      Returns Promise<
          (
              {
                  author: | {
                      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;
                  }
                  | null;
                  genres: (
                      { genre: { id: string; name: string } } & {
                          bookId: string;
                          genreId: string;
                      }
                  )[];
                  isbns: { bookId: string; id: string; isbnNumber: 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;
              }
          )[],
      >

      A promise resolving to an array of randomly selected books. Each book includes its statistics, comments, genres, and ISBNs.

      This method provides users with a selection of random book recommendations. It first counts the total number of books in the database that have been approved for display, then generates a random index within that count. Using this index, it retrieves a set of books from the database, ensuring that the books are approved and include related information such as statistics (e.g., average rating, rating count), comments from users, associated genres with their names, and ISBNs. The method handles any potential errors that may occur during the database query process, ensuring that appropriate exceptions are thrown if issues arise while fetching the random books.

      InternalServerErrorException if an error occurs while fetching the random books from the database. The method includes error handling to ensure that any issues encountered during the query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client if there are issues while retrieving the random books.

    • Parameters

      • userId: string

        The ID of the user for whom to retrieve a random favorite author. The method uses this ID to check the user's list of favorite authors and determine whether to return a random author from that list or to fetch a random approved author from the database if the user has no favorites.

      Returns Promise<{ id: string; name: string; smallerProfilePic: string | null }>

      A random favorite author or a random approved author if the user has no favorites. Each author includes their ID and any other relevant information as needed.

      This method first checks the user's list of favorite authors and retrieves a random author from that list. If the user has no favorite authors, it counts the total number of approved authors in the database, generates a random index, and retrieves a single approved author based on that index. The method includes error handling to manage any issues that may arise during the database queries, ensuring that appropriate exceptions are thrown if there are problems while fetching the random author.

      InternalServerErrorException if an error occurs while retrieving the random author from the database. The method includes error handling to ensure that any issues encountered during the query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client if there are issues while fetching the random author.

    • Parameters

      • userId: string

        The ID of the user for whom to retrieve favorite genre.

      Returns Promise<string | undefined>

      The name of a random favorite genre or a random genre from the database. Each genre includes its name and any other relevant information as needed.

      This method first checks the user's list of favorite genres by querying the favoriteBook table and retrieving the associated genres for the books that the user has favorited. If the user has no favorite genres, it retrieves a random genre from the database. The method includes error handling to manage any issues that may arise during the database queries, ensuring that appropriate exceptions are thrown if there are problems while fetching the random genre name.

      InternalServerErrorException if an error occurs while retrieving the random genre name from the database. The method includes error handling to ensure that any issues encountered during the query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client if there are issues while fetching the random genre name.

    • Returns Promise<
          {
              data: (
                  {
                      author: | {
                          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;
                      }
                      | null;
                      genres: (
                          { genre: { id: string; name: string } } & {
                              bookId: string;
                              genreId: string;
                          }
                      )[];
                      isbns: { bookId: string; id: string; isbnNumber: 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;
                  }
              )[];
              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 books.

      This method provides curated content for the search page by fetching a set of random books and structuring them into a format suitable for display. It is designed to enhance the user experience by offering a dynamic selection of books that align with their interests.

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

    • Parameters

      • take: number = 15

        The number of books to retrieve.

      Returns Promise<
          (
              {
                  author: { name: string }
                  | null;
                  comments: {
                      bookId: string;
                      createdAt: Date;
                      id: string;
                      text: string;
                      userId: string;
                  }[];
                  genres: (
                      { genre: { name: string } } & { bookId: string; genreId: string }
                  )[];
                  isbns: { bookId: string; id: string; isbnNumber: string }[];
                  statistics:
                      | {
                          averageRating: number;
                          bookId: string;
                          id: string;
                          ratingCount: number;
                          readersCount: number;
                          reviewCount: number;
                          wantToReadCount: number;
                      }
                      | null;
              } & {
                  approveStatus: boolean;
                  authorId: string
                  | null;
                  biggerCoverPic: string;
                  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;
                  title: string;
                  updatedAt: Date;
              }
          )[],
      >

      A promise resolving to an array of "Short & Sweet" books, each including its statistics, comments, and genres.

      This method fetches books that are categorized as "Short & Sweet" by filtering them based on their page number, specifically those that have 100 pages or fewer. It limits the results to entries that meet this criterion and includes related information such as statistics (e.g., average rating, rating count), comments from users, and associated genres with their names. The method ensures that only approved books are retrieved and that the results are filtered to highlight shorter reads that can be enjoyed quickly.

    • Parameters

      • bookId: string

        The ID of the book for which to find similar books.

      • take: number = 15

        The maximum number of similar books to retrieve.

      Returns Promise<
          (
              {
                  author: { name: string }
                  | null;
                  genres: (
                      { genre: { id: string; name: string } } & {
                          bookId: string;
                          genreId: 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;
              }
          )[],
      >

      A list of books that are similar to the given book based on shared genres. Each book includes its statistics, comments, and genres. If the base book is not found, the method throws a NotFoundException.

      NotFoundException if the book with the given ID is not found in the database. The method checks for the existence of the base book before attempting to find similar books, ensuring that it provides appropriate feedback if the specified book does not exist.

      InternalServerErrorException if an error occurs while retrieving similar books from the database. The method includes error handling to ensure that any issues encountered during the query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client if there are issues while fetching similar books based on shared genres.

    • Parameters

      • take: number = 15

        The maximum number of similar books to retrieve. The method will return up to this number of entries based on the shared genres with the top-rated book.

      Returns Promise<
          {
              coverImage: string
              | undefined;
              data: (
                  {
                      author: { name: string }
                      | null;
                      genres: (
                          { genre: { id: string; name: string } } & {
                              bookId: string;
                              genreId: 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;
                  }
              )[];
              title: string
              | undefined;
          },
      >

      A promise resolving to an object containing the title, cover image, and similar books data.

      This method provides users with book recommendations based on the top-rated book in the database. It first identifies the top-rated book by ordering approved books by their average rating in descending order and selecting the first entry. Then, it retrieves books that share at least one genre with the top-rated book, ensuring that the top-rated book itself is excluded from the results. Each similar book includes related information such as statistics (e.g., average rating, rating count), comments from users, and associated genres with their names. The method handles any potential errors that may arise during the database queries, ensuring that appropriate exceptions are thrown if there are problems while fetching similar books based on shared genres with the top-rated book.

    • Parameters

      • userId: string

        The ID of the user for whom to retrieve favorite author books.

      Returns Promise<
          {
              authorImage: string
              | null;
              authorName: string;
              books: (
                  {
                      comments: {
                          bookId: string;
                          createdAt: Date;
                          id: string;
                          text: string;
                          userId: string;
                      }[];
                      genres: (
                          { genre: { name: string } } & { bookId: string; genreId: string }
                      )[];
                      isbns: { bookId: string; id: string; isbnNumber: 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;
                  }
              )[];
          },
      >

      A list of books written by the user's favorite author. Each book includes its statistics, comments, genres, and ISBNs. If the user has no favorite authors, the method returns books from a random approved author instead.

      This method provides users with book recommendations based on their favorite authors. It first retrieves a random author from the user's list of favorite authors. If the user has no favorite authors, it retrieves a random approved author from the database. Then, it fetches books written by that author that have been approved for display, including related information such as statistics (e.g., average rating, rating count), comments from users, associated genres with their names, and ISBNs for each book. The method includes error handling to manage any issues that may arise during the database queries, ensuring that appropriate exceptions are thrown if there are problems while fetching the books from the user's favorite author.

      InternalServerErrorException if an error occurs while retrieving the books from the user's favorite author. The method includes error handling to ensure that any issues encountered during the query process are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client if there are issues while fetching the books from the user's favorite author.

    • Parameters

      • take: number = 15

        The number of books to retrieve.

      Returns Promise<
          (
              {
                  author: { name: string }
                  | null;
                  comments: {
                      bookId: string;
                      createdAt: Date;
                      id: string;
                      text: string;
                      userId: string;
                  }[];
                  genres: (
                      { genre: { name: string } } & { bookId: string; genreId: string }
                  )[];
                  isbns: { bookId: string; id: string; isbnNumber: string }[];
                  statistics:
                      | {
                          averageRating: number;
                          bookId: string;
                          id: string;
                          ratingCount: number;
                          readersCount: number;
                          reviewCount: number;
                          wantToReadCount: number;
                      }
                      | null;
              } & {
                  approveStatus: boolean;
                  authorId: string
                  | null;
                  biggerCoverPic: string;
                  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;
                  title: string;
                  updatedAt: Date;
              }
          )[],
      >

      A promise resolving to an array of "Weekend Reads" books, each including its statistics, comments, and genres.

      This method fetches books that are categorized as "Weekend Reads" by filtering them based on their page number, specifically those that have 250 pages or fewer. It limits the results to entries that meet this criterion and includes related information such as statistics (e.g., average rating, rating count), comments from users, and associated genres with their names. The method ensures that only approved books are retrieved and that the results are filtered to highlight reads that can be comfortably enjoyed over a weekend.

    • Parameters

      • olData: ExternalBookResponse | null

        The book data retrieved from the Open Library API, which may contain fields such as title, description, genres, page count, publisher, publication year, authors, and ISBNs.

      • googleData: ExternalBookResponse | null

        The book data retrieved from the Google Books API, which may contain similar fields as the Open Library data. This data is used to enhance or fill in missing information from the Open Library data when merging.

      Returns ExternalBookResponse | null

      The merged book data object containing information from both sources. If both sources are null, it returns null. The resulting object will have the most complete and detailed information available from either source, with combined genres and ISBNs where applicable.

      This method takes two book data objects, one from Open Library and one from Google Books, and merges them into a single object. It checks each field (title, description, genres, page count, publisher, publication year, authors, and ISBNs) and prioritizes the more complete or non-empty data. For genres and ISBNs, it combines the lists from both sources while removing duplicates. The method also ensures that if one source lacks certain information (e.g., description or publisher), it fills in those gaps with data from the other source if available.

    • Parameters

      • tags: string[]

        An array of strings representing tags that may contain multiple sub-tags separated by common delimiters. For example, a tag like "Science Fiction / Fantasy" would be split into "Science Fiction" and "Fantasy".

      Returns string[]

      An array of normalized strings representing the unique, cleaned tags.

      The method takes an array of strings (tags) and processes each tag by splitting it on common delimiters such as slashes, hyphens, colons, and commas. It then trims any leading or trailing whitespace from the resulting sub-tags and filters out any empty strings. Finally, it removes duplicate tags to return a clean, normalized array of unique tags.

    • Parameters

      • id: string

        The unique identifier of the book to be deleted. This ID is used to locate the specific book record in the database and retrieve its associated image keys for deletion from S3.

      Returns Promise<
          {
              deletedBook: {
                  biggerCoverPicKey: string
                  | null;
                  smallerCoverPicKey: string | null;
              };
              message: string;
          },
      >

      A promise resolving to an object containing a success message and the deleted book's information.

      This method is responsible for removing a book from the database and its associated cover images from S3. It first retrieves the book's smaller and bigger cover image keys to ensure that it has the necessary information to delete the images after the book record is removed. It then attempts to delete the book record from the database, handling any potential errors that may occur during this process, such as the book not existing. After successfully deleting the book record, it proceeds to delete the associated images from S3 using the retrieved keys. If any errors occur during the S3 deletion process, it logs the error and throws an InternalServerErrorException to indicate that there was an issue while deleting the images.

      ConflictException if the book with the given ID does not exist in the database.

      InternalServerErrorException if an error occurs while deleting the book record from the database or while deleting the images from S3.

    • Parameters

      • query: string

        The search query string.

      • take: number = 10

        The number of results to return.

      • userId: string

        The ID of the user performing the search, used to determine if the user has favorited any of the matching books.

      Returns Promise<
          {
              authors: (
                  { favoritedBy: { authorId: string; userId: string }[] } & {
                      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;
                  }
              )[];
              books: (
                  {
                      author: { name: string }
                      | null;
                      favoritedBy: { bookId: string; userId: string }[];
                  } & {
                      approveStatus: boolean;
                      authorId: string
                      | null;
                      biggerCoverPic: string;
                      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;
                      title: string;
                      updatedAt: Date;
                  }
              )[];
              genres: { id: string; name: string }[];
          },
      >

      A structured response containing the matching books, authors, and genres. Each book includes its statistics, comments, and associated genres, while each author includes their name and associated books, and each genre includes its name and associated books.

      This method allows users to search for books, authors, and genres using a query string. It performs a case-insensitive search across multiple fields, including book titles and descriptions, author names, and genre names. The method retrieves matching books along with their statistics, comments, and associated genres, as well as matching authors with their names and associated books, and matching genres with their names and associated books. The results are structured in a way that provides comprehensive information about the search results while ensuring that any errors encountered during the search process are properly handled and logged.

      The method includes error handling to catch and log any issues that arise during the search process, ensuring that the application can gracefully handle errors and provide informative feedback to the client if there are issues while performing the search. It also ensures that the search results are relevant and comprehensive by including related information for each matching book, author, and genre.

      InternalServerErrorException if an error occurs during the search process. The method includes error handling to ensure that any issues encountered while querying the database are properly logged and managed, allowing the application to gracefully handle errors and provide informative feedback to the client if there are issues during the search.

    • Parameters

      • id: string

        The ID of the book to update.

      • file: UploadedFile | null

        The uploaded cover image file, if applicable.

      • updateBookDto: UpdateBookDto

        The data transfer object containing the updated book details.

      Returns Promise<
          {
              author: | {
                  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;
              }
              | null;
              genres: (
                  { genre: { id: string; name: string } } & {
                      bookId: string;
                      genreId: string;
                  }
              )[];
              isbns: { bookId: string; id: string; isbnNumber: string }[];
          } & {
              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;
          },
      >

      A promise resolving to the updated book information or an error if the update fails.

      This method allows updating various aspects of a book, such as its title, description, identifiers (Google Book ID, Open Library ID), author, publication details, genres, and ISBNs. It first checks if the book exists in the database and throws a NotFoundException if it does not. It then checks for potential conflicts with the provided identifiers to ensure they are not already associated with another book. If a new cover image is provided, it handles the deletion of the old images from S3 and uploads the new image, updating the corresponding fields in the database. Finally, it updates the book record with the new details and returns the updated book information.

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

      ConflictException if the provided identifiers (ISBN, Google ID, or Open Library ID) are already associated with another book.

      InternalServerErrorException if an error occurs while updating the book details or managing images in S3.