FEAT-2: typed CRUD API clients for enclosures + contacts
This commit is contained in:
34
gerbil-manager-web/src/api/contacts.ts
Normal file
34
gerbil-manager-web/src/api/contacts.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
/** Typed API functions for the Kontakte (Contact) resource. (FEAT-2) */
|
||||
import { api, resources } from './client'
|
||||
import { toQueryString, type GridifyQuery } from './gridify'
|
||||
import type { Contact, Paged } from './types'
|
||||
|
||||
/** Payload for POST /contacts. */
|
||||
export interface CreateContact {
|
||||
name: string
|
||||
contactInfo?: string | null
|
||||
notes?: string | null
|
||||
}
|
||||
|
||||
/** Payload for PUT /contacts/{id}. */
|
||||
export type UpdateContact = Partial<CreateContact>
|
||||
|
||||
export function listContactsPaged(query: GridifyQuery): Promise<Paged<Contact>> {
|
||||
return api.get<Paged<Contact>>(`${resources.contacts}${toQueryString(query)}`)
|
||||
}
|
||||
|
||||
export function getContact(id: string): Promise<Contact> {
|
||||
return api.get<Contact>(`${resources.contacts}/${id}`)
|
||||
}
|
||||
|
||||
export function createContact(body: CreateContact): Promise<Contact> {
|
||||
return api.post<Contact>(resources.contacts, body)
|
||||
}
|
||||
|
||||
export function updateContact(id: string, body: UpdateContact): Promise<Contact> {
|
||||
return api.put<Contact>(`${resources.contacts}/${id}`, body)
|
||||
}
|
||||
|
||||
export function deleteContact(id: string): Promise<void> {
|
||||
return api.delete(`${resources.contacts}/${id}`)
|
||||
}
|
||||
Reference in New Issue
Block a user