27 lines
718 B
TypeScript
27 lines
718 B
TypeScript
import { request } from './request'
|
|
|
|
export type SensorInfo = {
|
|
id: number
|
|
name: string
|
|
authKey: string
|
|
}
|
|
|
|
export const getSensors = () => request<SensorInfo[]>('/api/sensors')
|
|
|
|
export const createSensor = (name: string) =>
|
|
request<SensorInfo>('/api/sensors', {
|
|
method: 'POST',
|
|
headers: { 'content-type': 'application/json' },
|
|
body: JSON.stringify({ name }),
|
|
})
|
|
|
|
export const updateSensor = ({ id, ...body }: { id: number; name: string }) =>
|
|
request<SensorInfo>(`/api/sensors/${id}`, {
|
|
method: 'PUT',
|
|
headers: { 'content-type': 'application/json' },
|
|
body: JSON.stringify(body),
|
|
})
|
|
|
|
export const deleteSensor = (id: number) =>
|
|
request<SensorInfo>(`/api/sensors/${id}`, { method: 'DELETE' }, 'void')
|