You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.9 KiB

3 years ago
import { Client, Timings } from '../types'
3 years ago
import axios from 'axios'
3 years ago
import { message } from 'antd'
import { Status } from '../components/StatusChip'
3 years ago
3 years ago
const dev = process.env.NODE_ENV === 'development'
if (dev) {
3 years ago
const host = 'http://192.168.1.114:5000'
3 years ago
axios.defaults.baseURL = host
3 years ago
}
3 years ago
const mock = false
3 years ago
export const createClient = async (body: Omit<Client, 'has_photos'>) => {
3 years ago
if (mock) return 'test'
3 years ago
const res = await axios.post<{ client_id: string }>(`/api/clients`, body)
return res.data.client_id
3 years ago
}
3 years ago
3 years ago
export const getClient = async (id: string): Promise<Client> => {
3 years ago
if (mock)
return {
name: 'Test Client',
has_photos: false,
email: 'test@test.test',
phone: 1234567890,
}
3 years ago
const res = await axios.get<Client>(`/api/clients/${id}`)
3 years ago
return res.data
}
3 years ago
export const startSession = async (clientId: string, timings: Timings) => {
3 years ago
try {
3 years ago
const res = await axios.post(`/api/clients/${clientId}/session`, timings)
3 years ago
return res.data
} catch (err) {
message.error('Something went wrong, check connection with the machine')
return err
}
3 years ago
}
export const getSession = async (clientId: string) => {
const res = await axios.get<{ photos: string[] }>(
`/api/clients/${clientId}/session`,
)
3 years ago
return res.data // session data
3 years ago
}
3 years ago
export const killSession = async (clientId: string) => {
3 years ago
await axios.delete(`/api/clients/${clientId}/session`)
3 years ago
}
3 years ago
export const restartSession = async (clientId: string, timings: Timings) => {
3 years ago
await killSession(clientId)
3 years ago
await startSession(clientId, timings)
3 years ago
}
3 years ago
// TOOD: Get status
3 years ago
export const getStatus = async (): Promise<Status> => {
const res = await axios.get<{ status: Status }>('/api/status')
return res.data.status
}
3 years ago
// Someday
export const getClients = async (): Promise<Client[]> => {
const res = await axios.get<Client[]>(`/api/clients`)
return res.data
}
3 years ago
export const cleanup = () => {
// send
}