Newer
Older
export const SHOW_ALL_DEGREECOURSES = 'SHOW_ALL_DEGREECOURSES';
export const SHOW_ALL_DEGREECOURSES_ERROR = 'SHOW_ALL_DEGREECOURSES_ERROR';
export const CREATE_NEW_DEGREECOURSE_SUCCESS = 'CREATE_NEW_DEGREECOURSE_SUCCESS';
export const CREATE_NEW_DEGREECOURSE_ERROR = 'CREATE_NEW_DEGREECOURSE_ERROR';
export const EDIT_DEGREECOURSE_SUCCESS = 'EDIT_DEGREECOURSE_SUCCESS';
export const EDIT_DEGREECOURSE_ERROR = 'EDIT_DEGREECOURSE_ERROR';
export const DELETE_DEGREECOURSE_SUCCESS = 'DELETE_DEGREECOURSE_SUCCESS';
export const DELETE_DEGREECOURSE_ERROR = 'DELETE_DEGREECOURSE_ERROR'
export const SHOW_DELETE_DEGREECOURSE_MODAL = 'SHOW_DELETE_DEGREECOURSE_MODAL'
export const HIDE_DELETE_DEGREECOURSE_MODAL = 'HIDE_DELETE_DEGREECOURSE_MODAL'
export const PRESS_EDIT_BUTTON = 'PRESS_EDIT_BUTTON';
export function getShowDeleteDegreeCourseModalAction(deleteModalData) {
return {
type: SHOW_DELETE_DEGREECOURSE_MODAL,
deleteDegreeCourseModalData: deleteModalData
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
}
}
export function getHideDeleteDegreeCourseModalAction() {
return {
type: HIDE_DELETE_DEGREECOURSE_MODAL
}
}
export function getCreateNewDegreeCourseSuccessAction(degreeCourseData) {
return {
type: CREATE_NEW_DEGREECOURSE_SUCCESS,
newDegreeCourseData: degreeCourseData
}
}
export function getCreateNewDegreeCourseErrorAction(error) {
return {
type: CREATE_NEW_DEGREECOURSE_ERROR,
error: error
}
}
export function createNewDegreeCourse(degreeCourseData, token) {
const requestOptions = {
method: 'POST',
headers: {
'Authorization': token,
'Content-Type': 'application/json'
},
body: JSON.stringify(degreeCourseData)
}
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
.then(response => {
return response.json().then(body => {
if (response.status === 201) {
return body
}
})
})
}
export function passNewDegreeCourse(degreeCourseData, token) {
return dispatch => {
dispatch(getCreateNewDegreeCourseSuccessAction());
createNewDegreeCourse(degreeCourseData, token)
.then(newDegreeCourse => {
const action = getCreateNewDegreeCourseSuccessAction(newDegreeCourse)
dispatch(action);
getAllDegreeCourses(token)
.then(degreeCourses => {
const action = getAllDegreeCoursesAction(degreeCourses)
dispatch(action)
})
},
error => {
dispatch(getCreateNewDegreeCourseErrorAction(error));
}
)
.catch(error => {
dispatch(getCreateNewDegreeCourseErrorAction(error))
})
}
}
export function getAllDegreeCoursesAction(courses) {
return {
type: SHOW_ALL_DEGREECOURSES,
degreeCourseList: courses
}
}
export function getAllDegreeCoursesErrorAction(error) {
return {
type: SHOW_ALL_DEGREECOURSES_ERROR,
error: error
}
}
export function getAllDegreeCourses(token) {
const requestOptions = {
method: 'GET',
headers: { 'Authorization': token }
};
return fetch(URL + '/degreeCourses', requestOptions)
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
.then(response => {
return response.json().then(body => {
if (response.status === 200) {
return body
}
})
})
}
export function displayDegreeCourses(token) {
return dispatch => {
dispatch(getAllDegreeCoursesAction());
getAllDegreeCourses(token)
.then(courses => {
const action = getAllDegreeCoursesAction(courses)
dispatch(action);
},
error => {
dispatch(getAllDegreeCoursesErrorAction(error));
}
)
.catch(error => {
dispatch(getAllDegreeCoursesErrorAction(error))
})
}
}
export function getEditDegreeCourseSuccessAction() {
return {
type: EDIT_DEGREECOURSE_SUCCESS
}
}
export function getEditDegreeCourseErrorAction() {
return {
type: EDIT_DEGREECOURSE_ERROR
}
}
export function updateDegreeCourse(updateData, degreeCourseID, token) {
const requestOptions = {
method: 'PUT',
headers: {
'Authorization': token,
'Content-Type': 'application/json'
},
body: JSON.stringify(updateData)
}
return fetch(URL + `/degreeCourses/${degreeCourseID}`, requestOptions)
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
.then(response => {
return response.json().then(body => {
if (response.status === 200) {
return body
}
})
})
}
export function editDegreeCourseWithID(updateData, degreeCourseID, token) {
return dispatch => {
dispatch(getEditDegreeCourseSuccessAction());
updateDegreeCourse(updateData, degreeCourseID, token)
.then(degreeCourse => {
const action = getEditDegreeCourseSuccessAction(degreeCourse)
dispatch(action);
getAllDegreeCourses(token)
.then(degreeCourses => {
const action = getAllDegreeCoursesAction(degreeCourses)
dispatch(action)
})
},
error => {
dispatch(getEditDegreeCourseErrorAction(error));
}
)
.catch(error => {
dispatch(getEditDegreeCourseErrorAction(error))
})
}
}
export function getDeleteDegreeCourseSuccessAction() {
return {
type: DELETE_DEGREECOURSE_SUCCESS
}
}
export function getDeleteDegreeCourseErrorAction(error) {
return {
type: DELETE_DEGREECOURSE_ERROR,
error: error
}
}
export function deleteDegreeCourse(degreeCourseID, token) {
const requestOptions = {
method: 'DELETE',
headers: {
'Authorization': token
}
}
return fetch(URL + '/degreeCourses/' + degreeCourseID, requestOptions)
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
.then(response => {
if (response.status === 204) {
return response.status
}
})
}
export function deleteDegreeCourseWithID(degreeCourseID, token) {
return dispatch => {
dispatch(getDeleteDegreeCourseSuccessAction(degreeCourseID));
deleteDegreeCourse(degreeCourseID, token)
.then(deleteDegreeCourse => {
const action = getDeleteDegreeCourseSuccessAction(deleteDegreeCourse)
dispatch(action);
getAllDegreeCourses(token)
.then(degreeCourses => {
const action = getAllDegreeCoursesAction(degreeCourses)
dispatch(action)
})
},
error => {
dispatch(getDeleteDegreeCourseErrorAction(error));
}
)
.catch(error => {
dispatch(getDeleteDegreeCourseErrorAction(error))
})
}
}