feat(03-06): add deleteEvent, fetchSyncStatus client calls and delete/sync Zustand keys
- deleteEvent(uid): DELETE /api/events/:uid with credentials:include, throws on !ok - fetchSyncStatus(uid): GET /api/events/sync-status?uid= returning SyncStatus - Export SyncStatus and SyncStatusValue types - Zustand: deleteDialogOpen/deleteDialogUid/lastSyncedUid keys + setDeleteDialog/setLastSyncedUid setters
This commit is contained in:
@@ -189,6 +189,60 @@ export async function updateEvent(
|
||||
return res.json() as Promise<CreateEventResponse>
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a calendar event.
|
||||
*
|
||||
* DELETEs /api/events/:uid; the API enqueues the delete to the outbox (D-05).
|
||||
* Returns 202 Accepted (async). Throws on any non-ok response.
|
||||
*/
|
||||
export async function deleteEvent(uid: string): Promise<void> {
|
||||
const res = await fetch(`/api/events/${uid}`, {
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`DELETE /api/events/${uid} failed: ${res.status}`)
|
||||
}
|
||||
}
|
||||
|
||||
// ── /api/events/sync-status (Plan 03-06) ─────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Status values for an outbox write operation.
|
||||
* Mirrors the calendarOutbox.status enum on the server.
|
||||
*/
|
||||
export type SyncStatusValue = 'pending' | 'done' | 'failed' | 'dead'
|
||||
|
||||
/**
|
||||
* Response from GET /api/events/sync-status?uid=
|
||||
* The server returns the current outbox status for the given UID + member.
|
||||
*/
|
||||
export interface SyncStatus {
|
||||
uid: string
|
||||
status: SyncStatusValue
|
||||
/** Present on failed status — may contain '412' prefix for conflict detection. */
|
||||
error?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Poll the sync-status for a specific event UID.
|
||||
*
|
||||
* Used by SyncStateToast to track pending → done | failed | dead transitions.
|
||||
* The server filters by the current member so no cross-member leakage (T-03-19).
|
||||
*/
|
||||
export async function fetchSyncStatus(uid: string): Promise<SyncStatus> {
|
||||
const res = await fetch(`/api/events/sync-status?uid=${uid}`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`GET /api/events/sync-status failed: ${res.status}`)
|
||||
}
|
||||
|
||||
return res.json() as Promise<SyncStatus>
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the authoritative list of writable calendars for the current member.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user