backend
    Preparing search index...
    Index

    Constructors

    Methods

    • Parameters

      • createGenreDto: CreateGenreDto

        The DTO containing the genre name to be created.

      Returns Promise<{ id: string; name: string }>

      The created genre object.

      This method takes a DTO containing the name of the genre to be created. It normalizes the genre name and attempts to create a new genre in the database. If a genre with the same name already exists, it throws a ConflictException. If there is any other error during the creation process, it throws an InternalServerErrorException. This method is typically used by admin users to add new genres to the system.

      ConflictException If a genre with the same name already exists.

      InternalServerErrorException If there was an error while creating the genre.

    • Parameters

      Returns Promise<{ id: string; name: string }[]>

      A list of genres matching the criteria.

      This method takes a PaginationDto object as input and retrieves a paginated list of genres from the database. It supports filtering by search term, sorting by name or book count, and ordering in ascending or descending order. The results are limited to a maximum number of items per page.

      InternalServerErrorException If there was an error while retrieving the genres.

    • Parameters

      • id: string

        The unique identifier of the genre to retrieve.

      Returns Promise<{ id: string; name: string }>

      The genre with the specified ID.

      This method takes a genre ID as input and attempts to retrieve the corresponding genre from the database. If the genre is found, it is returned. If no genre with the specified ID exists, a NotFoundException is thrown. This method is typically used to display detailed information about a specific genre.

      NotFoundException If no genre exists with the specified ID.

    • Parameters

      • where: any

        The where condition for filtering genres.

      • skip: number

        The number of genres to skip.

      • take: number

        The number of genres to take.

      • order: "asc" | "desc"

        The order in which to sort the genres.

      Returns Promise<{ _count: { books: number }; id: string; name: string }[]>

      A list of genres matching the criteria.

      This method takes a genre ID as input and attempts to retrieve the corresponding genre from the database. If the genre is found, it is returned. If no genre with the specified ID exists, a NotFoundException is thrown. This method is typically used to display detailed information about a specific genre.

      InternalServerErrorException If there was an error while retrieving the genre.

    • Parameters

      • names: string[]

        The list of genre names to process.

      Returns Promise<{ id: string; name: string }[]>

      The list of genres that were either created or already existed.

      This method takes a list of genre names, normalizes them, and checks which ones already exist in the database. It then creates any new genres that do not already exist and returns the complete list of genres corresponding to the provided names. This is useful for efficiently handling bulk operations when associating genres with books or other entities.

      InternalServerErrorException If there was an error processing the genres in bulk.

    • Returns Promise<
          {
              _count: { books: number };
              books: {
                  book: {
                      biggerCoverPic: string;
                      id: string;
                      smallerCoverPic: string;
                      statistics: { averageRating: number; ratingCount: number } | null;
                      title: string;
                  };
              }[];
              id: string;
              name: string;
          }[],
      >

      A list of top genres with their popular books.

      This method retrieves the top 30 genres from the database based on the number of approved books associated with each genre. For each of these top genres, it also retrieves up to 2 of their most popular approved books, sorted by average rating in descending order. This method is useful for displaying popular genres and their top books to users.

      InternalServerErrorException If there was an error while retrieving the top genres and their popular books.

    • Parameters

      • id: string

        The unique identifier of the genre to remove.

      Returns Promise<{ id: string; name: string }>

      The deleted genre.

      This method takes a genre ID as input and attempts to delete the corresponding genre from the database. If the genre is not found, a NotFoundException is thrown. If the genre is linked to existing books, a ConflictException is thrown. Otherwise, the genre is deleted and returned.

      NotFoundException If no genre exists with the specified ID.

      ConflictException If the genre is linked to existing books.

      InternalServerErrorException If there was an error while deleting the genre.

    • Parameters

      • query: string

        The query string to search for in genre names.

      Returns Promise<{ name: string }[]>

      A list of genres that match the search criteria.

      This method takes a query string as input and searches for genres in the database that contain the query string in their name, ignoring case. It returns a list of matching genres, limited to a maximum of 10 results. This is useful for implementing search functionality when users are looking for specific genres.

      InternalServerErrorException If there was an error while searching for genres.