graphicek/client/src/api/sensors.ts

27 lines
718 B
TypeScript
Raw Normal View History

2022-08-21 22:27:31 +02:00
import { request } from './request'
export type SensorInfo = {
2022-08-28 11:56:03 +02:00
id: number
name: string
authKey: string
2022-08-21 22:27:31 +02:00
}
export const getSensors = () => request<SensorInfo[]>('/api/sensors')
2022-08-28 11:56:03 +02:00
export const createSensor = (name: string) =>
request<SensorInfo>('/api/sensors', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ name }),
})
2022-08-28 12:30:37 +02:00
export const updateSensor = ({ id, ...body }: { id: number; name: string }) =>
2022-08-28 11:56:03 +02:00
request<SensorInfo>(`/api/sensors/${id}`, {
method: 'PUT',
headers: { 'content-type': 'application/json' },
2022-08-28 12:30:37 +02:00
body: JSON.stringify(body),
2022-08-28 11:56:03 +02:00
})
2022-08-28 21:47:36 +02:00
export const deleteSensor = (id: number) =>
request<SensorInfo>(`/api/sensors/${id}`, { method: 'DELETE' }, 'void')