forked from HackYourFuture/dojo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.ts
More file actions
47 lines (43 loc) · 1.5 KB
/
api.ts
File metadata and controls
47 lines (43 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import axios from 'axios';
import { Interaction } from '../Interactions';
export const getInteractions = async (traineeId: string) => {
try {
const { data } = await axios.get(`/api/trainees/${traineeId}/interactions`);
return data as Interaction[];
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error(error.response?.data?.error || 'Failed to get interactions');
}
throw new Error('Failed to get interactions');
}
};
export const addInteraction = async (traineeId: string, interaction: Partial<Interaction>) => {
try {
await axios.post(`/api/trainees/${traineeId}/interactions`, interaction);
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error(error.response?.data?.error || 'Failed to add interaction');
}
throw error;
}
};
export const deleteInteraction = async (traineeId: string, interactionId: string) => {
try {
await axios.delete(`/api/trainees/${traineeId}/interactions/${interactionId}`);
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error(error.response?.data?.error || 'Failed to delete interaction');
}
throw error;
}
};
export const editInteraction = async (traineeId: string, interaction: Interaction) => {
try {
await axios.put(`/api/trainees/${traineeId}/interactions/${interaction.id}`, interaction);
} catch (error) {
if (axios.isAxiosError(error)) {
throw new Error(error.response?.data?.error || 'Failed to edit interaction');
}
throw error;
}
};