Skip to content

Commit

Permalink
create paginated endpoint to fetch all booking history (#739)
Browse files Browse the repository at this point in the history
* create endpoint for fetching the booking history events

* add required files
  • Loading branch information
choden-dev authored Aug 4, 2024
1 parent 8b8854b commit d29dde6
Show file tree
Hide file tree
Showing 8 changed files with 558 additions and 3 deletions.
116 changes: 116 additions & 0 deletions client/src/models/__generated__/schema.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions server/src/data-layer/services/BookingHistoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
} from "data-layer/models/firebase"
import { Timestamp } from "firebase-admin/firestore"

const DEFAULT_PAGINATION_AMOUNT = 100 as const

class BookingHistoryService {
/**
* Stores a manual deletion of a booking (by admin) into the booking history collection
Expand Down Expand Up @@ -69,13 +71,13 @@ class BookingHistoryService {
/**
* Fetches the **latest** page of booking history events.
*
* @param limit how many history events to fetch, defaults to `100`
* @param limit how many history events to fetch, defaults to {@link DEFAULT_PAGINATION_AMOUNT}
* @param startAfter the firebase document snapshot to paginate from
* @returns the page of booking history items and a cursor pointing to the
* last `id` to use for pagination
*/
public async getLatestHistory(
limit: number = 100,
limit: number = DEFAULT_PAGINATION_AMOUNT,
startAfter?: FirebaseFirestore.DocumentSnapshot<
BookingHistoryEvent,
FirebaseFirestore.DocumentData
Expand All @@ -99,6 +101,10 @@ class BookingHistoryService {
nextCursor: res.docs[res.docs.length - 1]?.id || undefined
}
}

public async getBookingHistoryEventSnapshot(id: string) {
return await db.bookingHistory.doc(id).get()
}
}

export default BookingHistoryService
92 changes: 92 additions & 0 deletions server/src/middleware/__generated__/routes.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d29dde6

Please sign in to comment.