async function list()

in bookshelf/books/firestore.js [25:51]


async function list(limit, token) {
  const snapshot = await db
    .collection(collection)
    .orderBy('title')
    .startAfter(token || '')
    .limit(limit)
    .get();

  if (snapshot.empty) {
    return {
      books: [],
      nextPageToken: false,
    };
  }
  const books = [];
  snapshot.forEach((doc) => {
    let book = doc.data();
    book.id = doc.id;
    books.push(book);
  });
  const q = await snapshot.query.offset(limit).get();

  return {
    books,
    nextPageToken: q.empty ? false : books[books.length - 1].title,
  };
}