-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.ts
97 lines (86 loc) · 2.01 KB
/
api.ts
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import axios from 'axios';
const API = axios.create({
baseURL: 'http://localhost:5000',
timeout: 1000,
headers: {'Authorization': 'Bearer ' + localStorage.getItem('token')}
});
export const createUser = async (userData) => {
try {
const response = await API.post('/users', userData);
return response.data;
} catch (error) {
console.error(error);
}
};
export const getUsers = async () => {
try {
const response = await API.get('/users');
return response.data;
} catch (error) {
console.error(error);
}
};
export const createCourse = async (courseData) => {
try {
const response = await API.post('/courses', courseData);
return response.data;
} catch (error) {
console.error(error);
}
};
export const getCourses = async () => {
try {
const response = await API.get('/courses');
return response.data;
} catch (error) {
console.error(error);
}
};
export const createAssignment = async (assignmentData) => {
try {
const response = await API.post('/assignments', assignmentData);
return response.data;
} catch (error) {
console.error(error);
}
};
export const getAssignments = async () => {
try {
const response = await API.get('/assignments');
return response.data;
} catch (error) {
console.error(error);
}
};
export const createTest = async (testData) => {
try {
const response = await API.post('/tests', testData);
return response.data;
} catch (error) {
console.error(error);
}
};
export const getTests = async () => {
try {
const response = await API.get('/tests');
return response.data;
} catch (error) {
console.error(error);
}
};
export const createChat = async (chatData) => {
try {
const response = await API.post('/chats', chatData);
return response.data;
} catch (error) {
console.error(error);
}
};
export const getChats = async () => {
try {
const response = await API.get('/chats');
return response.data;
} catch (error) {
console.error(error);
}
};