50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { Client } from '../types'
|
|
import axios from 'axios'
|
|
import settings from '../settings'
|
|
|
|
if (settings.env === 'jank') {
|
|
const host = 'http://192.168.1.107:5000'
|
|
axios.defaults.baseURL = host
|
|
}
|
|
|
|
export const createClient = async (body: Omit<Client, 'has_photos'>) => {
|
|
const res = await axios.post<{ client_id: string }>(`/api/clients`, body)
|
|
return res.data.client_id
|
|
}
|
|
|
|
export const getClient = async (id: string): Promise<Client> => {
|
|
const res = await axios.get<Client>(`/api/clients/${id}`)
|
|
return res.data
|
|
}
|
|
export const startSession = async (clientId: string) => {
|
|
const res = await axios.post(`/api/clients/${clientId}/session`)
|
|
return res.data // session data
|
|
}
|
|
|
|
export const getSession = async (clientId: string) => {
|
|
const res = await axios.get<{ photos: string[] }>(
|
|
`/api/clients/${clientId}/session`,
|
|
)
|
|
return res.data // session data
|
|
}
|
|
|
|
export const killSession = async (clientId: string) => {
|
|
await axios.delete(`/api/clients/${clientId}/session`)
|
|
}
|
|
|
|
export const restartSession = async (clientId: string) => {
|
|
await killSession(clientId)
|
|
await startSession(clientId)
|
|
}
|
|
|
|
// Someday
|
|
|
|
export const getClients = async (): Promise<Client[]> => {
|
|
const res = await axios.get<Client[]>(`/api/clients`)
|
|
return res.data
|
|
}
|
|
|
|
export const cleanup = () => {
|
|
// send
|
|
}
|