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.
47 lines
1.3 KiB
47 lines
1.3 KiB
import { Client } from '../types' |
|
import axios from 'axios' |
|
import { client, clients, session } from '../data' |
|
import settings from '../settings' |
|
|
|
const apiUrl = '/api' |
|
|
|
export const createClient = async (body: Client) => { |
|
await axios.post(`${apiUrl}/clients`, body) |
|
} |
|
|
|
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 getClient = async (id: string): Promise<Client> => { |
|
if (settings.env === 'jank') return client |
|
const res = await axios.post<Client>(`${apiUrl}/client/${id}`) |
|
return res.data |
|
} |
|
export const startSession = async (clientId: string) => { |
|
// |
|
const res = await axios.post(`${apiUrl}/clients/${clientId}/session`) |
|
return res.data // session data |
|
} |
|
|
|
export const getSession = async ( |
|
clientId: string, |
|
): Promise<null | string[]> => { |
|
if (settings.env === 'jank') return session |
|
const res = await axios.get(`${apiUrl}/clients/${clientId}/session`) |
|
return res.data as null | string[] |
|
} |
|
|
|
export const killSession = async (clientId: string) => { |
|
await axios.delete(`${apiUrl}/clients/${clientId}/session`) |
|
} |
|
|
|
export const restartSession = async (clientId: string) => { |
|
await killSession(clientId) |
|
await startSession(clientId) |
|
} |
|
|
|
export const cleanup = () => { |
|
// send |
|
}
|
|
|