All files / src/services share.ts

100% Statements 17/17
100% Branches 0/0
100% Functions 16/16
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37      3x   1x       1x       1x       1x       1x       1x       1x       1x      
import api from './api'
import type { ShoppingList, ShareTokenResponse, SyncTokenResponse, SyncPreviewResponse, SyncApplyResponse, ParticipantResponse } from '../types'
 
export const shareService = {
  generateToken(listId: string): Promise<ShareTokenResponse> {
    return api.post<ShareTokenResponse>(`/lists/${listId}/share`).then(r => r.data)
  },
 
  revokeToken(listId: string): Promise<void> {
    return api.delete(`/lists/${listId}/share`).then(() => undefined)
  },
 
  previewToken(token: string): Promise<ShoppingList> {
    return api.get<ShoppingList>(`/share/${token}`).then(r => r.data)
  },
 
  joinViaToken(token: string): Promise<ShoppingList> {
    return api.post<ShoppingList>(`/share/${token}/join`).then(r => r.data)
  },
 
  createSyncToken(theme: string): Promise<SyncTokenResponse> {
    return api.post<SyncTokenResponse>('/sync', { theme }).then(r => r.data)
  },
 
  previewSyncToken(token: string): Promise<SyncPreviewResponse> {
    return api.get<SyncPreviewResponse>(`/sync/${token}`).then(r => r.data)
  },
 
  applySyncToken(token: string): Promise<SyncApplyResponse> {
    return api.post<SyncApplyResponse>(`/sync/${token}/apply`).then(r => r.data)
  },
 
  getParticipants(listId: string): Promise<ParticipantResponse[]> {
    return api.get<ParticipantResponse[]>(`/lists/${listId}/participants`).then(r => r.data)
  },
}