-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminSideApi.js
118 lines (107 loc) · 2.47 KB
/
adminSideApi.js
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// const requestHeader = {
// headers: {
// Accept: "application/json",
// "Content-Type": "application/json",
// authorization: `Bearer ${token}`,
// },
// };
// Menu related API
export const getItemList = async (token) => {
try {
const response = await fetch(`/api/admin/menu`, {
headers: {
authorization: `Bearer ${token}`,
},
});
return await response.json();
} catch (error) {
console.log(error);
return error;
}
};
export const addItem = async (newItem, token) => {
const requestOptions = {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
authorization: `Bearer ${token}`,
},
method: "POST",
body: JSON.stringify(newItem),
};
try {
const response = await fetch(`/api/admin/menu`, requestOptions);
return response.json();
} catch (error) {
console.log(error);
return error;
}
};
export const updateStatus = async (id, token) => {
const requestOptions = {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
authorization: `Bearer ${token}`,
},
method: "PUT",
};
try {
const response = await fetch(
`/api/admin/menu/${id}/status`,
requestOptions
);
return response.json();
} catch (error) {
console.log(error);
return error;
}
};
export const updateItemApi = async (id, content, token) => {
const requestOptions = {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
authorization: `Bearer ${token}`,
},
body: JSON.stringify(content),
method: "PUT",
};
try {
const response = await fetch(`/api/admin/menu/${id}`, requestOptions);
return response.json();
} catch (error) {
console.log(error);
return error;
}
};
// Message related API
// Get Message API
export const getMessages = async (token) => {
try {
const response = await fetch(`/api/admin/message`, {
headers: {
authorization: `Bearer ${token}`,
},
});
return await response.json();
} catch (error) {
console.log(error);
return error;
}
};
// Delete Message API
export const deleteMessages = async (id, token) => {
try {
const response = await fetch(`/api/admin/message/${id}`, {
headers: {
authorization: `Bearer ${token}`,
},
method: "DELETE",
});
return response.json();
} catch (error) {
console.log(error);
return error;
}
};