📊
Pollz
  • Introduction
  • Quickstart
  • Guides
    • Initializing your app
    • Create a Poll
    • Vote for a Poll
    • Retrieve a Poll
    • Manage Poll Options
    • Listen to update
    • Anonymous Poll
  • Components
    • React
    • React Native
    • Embedded
  • API Reference
    • init()
    • pollOptions()
      • addOption()
      • deleteOption()
      • renameOption()
    • anonymous
      • createAnonymousToken()
      • getAnonymousPoll()
      • voteAnonymously()
    • polls
      • create()
      • get()
      • getAll()
      • vote()
      • rename()
      • deleteOne()
      • listen()
    • pollTypes
      • getAll()
  • Tooling
    • Typescript
    • React
      • usePoll()
      • usePolls()
      • usePollz()
      • usePollTypes()
      • useAnonymousPoll()
Powered by GitBook
On this page
  1. API Reference
  2. polls

getAll()

getAll(page?: number, itemsPerPage?: number, orderBy = OrderBy.Desc): Promise<{ items: Poll[]; meta: PaginationMeta }>

Get a list of all polls with pagination support.

Parameters:

  • page (number, optional): The page number to retrieve. Default is undefined, which retrieves the first page.

  • itemsPerPage (number, optional): The number of items to retrieve per page. Default is undefined, which retrieves the default number of items per page.

  • orderBy (OrderBy, optional): The order in which to retrieve polls. Default is OrderBy.Desc (descending).

Returns:

  • A Promise resolving to an object with two properties:

    • items (Poll[]): An array of poll objects (Poll).

    • meta (PaginationMeta): An object containing metadata about the retrieved polls, including the total count, current page, items per page, and the total number of pages.

Example:

try {
  const pollsList = await pollz.polls.getAll(1, 10, OrderBy.Desc);
  console.log('Polls List:', pollsList);
} catch (error) {
  console.error('Failed to retrieve polls:', error.message);
}

The getAll method allows you to retrieve a paginated list of all polls. You can specify the page number (page), the number of items to retrieve per page (itemsPerPage), and the order in which to retrieve polls (orderBy).

The method returns a Promise resolving to an object with an array of poll objects (Poll) and metadata (PaginationMeta) providing information about the total count, current page, items per page, and total number of pages.

Previousget()Nextvote()

Last updated 1 year ago