File size: 670 Bytes
cd99321
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { reservationsApi } from '../api/client'
import { offlineDb, upsertReservations } from '../db/offlineDb'
import { onlineThenCache } from './withOfflineFallback'
import type { Reservation } from '../types'

export const reservationRepo = {
  async list(tripId: number | string): Promise<{ reservations: Reservation[] }> {
    return onlineThenCache(
      async () => {
        const result = await reservationsApi.list(tripId)
        upsertReservations(result.reservations)
        return result
      },
      async () => ({
        reservations: await offlineDb.reservations
          .where('trip_id').equals(Number(tripId)).toArray(),
      }),
    )
  },
}