This commit is contained in:
E
2021-03-07 21:46:40 -07:00
parent b0aec2cfd1
commit 0760c93ce4
7 changed files with 107 additions and 48 deletions

View File

@@ -1,31 +1,35 @@
import { Client } from '../types'
import axios from 'axios'
import { client, clients } from '../data'
import settings from '../settings'
const apiUrl = '/api'
export const createClient = async (body: Omit<Client, 'photos'>) => {
await axios.post(`${apiUrl}/clients`, body)
if (settings.env === 'jank') {
const host = 'http://192.168.1.107:5000'
axios.defaults.baseURL = host
}
export const getClients = async (): Promise<Client[]> => {
if (settings.env === 'jank') return clients
const res = await axios.post<Client[]>(`${apiUrl}/clients`)
return res.data
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> => {
if (settings.env === 'jank') return client
const res = await axios.post<Client>(`${apiUrl}/client/${id}`)
const res = await axios.get<Client>(`/api/clients/${id}`)
return res.data
}
export const startSession = async (clientId: string) => {
const res = await axios.post(`${apiUrl}/clients/${clientId}`)
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(`${apiUrl}/clients/${clientId}`)
await axios.delete(`/api/clients/${clientId}/session`)
}
export const restartSession = async (clientId: string) => {
@@ -33,6 +37,13 @@ export const restartSession = async (clientId: string) => {
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
}