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) {
console.log(deleteModalData)
return {
type: SHOW_DELETE_DEGREECOURSE_MODAL,
deleteDegreeCourseModalData: deleteModalData
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
}
}
export function getHideDeleteDegreeCourseModalAction() {
return {
type: HIDE_DELETE_DEGREECOURSE_MODAL
}
}
export function getCreateNewDegreeCourseSuccessAction(degreeCourseData) {
console.log("GetCreateNewDegreeCourseSuccessAction")
return {
type: CREATE_NEW_DEGREECOURSE_SUCCESS,
newDegreeCourseData: degreeCourseData
}
}
export function getCreateNewDegreeCourseErrorAction(error) {
console.log("getCreateNewDegreeCourseErrorAction")
return {
type: CREATE_NEW_DEGREECOURSE_ERROR,
error: error
}
}
export function createNewDegreeCourse(degreeCourseData, token) {
console.log("create new degreeCourse")
console.log(degreeCourseData)
const requestOptions = {
method: 'POST',
headers: {
'Authorization': token,
'Content-Type': 'application/json'
},
body: JSON.stringify(degreeCourseData)
}
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
119
120
121
122
123
124
125
.then(response => {
return response.json().then(body => {
if (response.status === 201) {
console.log(body)
return body
}
})
})
}
export function passNewDegreeCourse(degreeCourseData, token) {
console.log("passing new degreeCourse")
return dispatch => {
dispatch(getCreateNewDegreeCourseSuccessAction());
createNewDegreeCourse(degreeCourseData, token)
.then(newDegreeCourse => {
console.log(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) {
console.log("GetAllCourses Action")
return {
type: SHOW_ALL_DEGREECOURSES,
degreeCourseList: courses
}
}
export function getAllDegreeCoursesErrorAction(error) {
console.log("Error Action")
return {
type: SHOW_ALL_DEGREECOURSES_ERROR,
error: error
}
}
export function getAllDegreeCourses(token) {
console.log("get all courses")
console.log(token)
const requestOptions = {
method: 'GET',
headers: { 'Authorization': token }
};
return fetch(URL + '/degreeCourses', requestOptions)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
.then(response => {
return response.json().then(body => {
if (response.status === 200) {
console.log(body)
return body
}
})
})
}
export function displayDegreeCourses(token) {
console.log("displaying degreeCourse")
return dispatch => {
dispatch(getAllDegreeCoursesAction());
getAllDegreeCourses(token)
.then(courses => {
console.log(courses)
const action = getAllDegreeCoursesAction(courses)
dispatch(action);
},
error => {
dispatch(getAllDegreeCoursesErrorAction(error));
}
)
.catch(error => {
dispatch(getAllDegreeCoursesErrorAction(error))
})
}
}
export function getEditDegreeCourseSuccessAction() {
console.log("getEditDegreeCourseSuccessAction")
return {
type: EDIT_DEGREECOURSE_SUCCESS
}
}
export function getEditDegreeCourseErrorAction() {
console.log("getEditDegreeCourseErrorAction")
return {
type: EDIT_DEGREECOURSE_ERROR
}
}
export function updateDegreeCourse(updateData, degreeCourseID, token) {
console.log("updating degreeCourse with id: " + degreeCourseID)
console.log(degreeCourseID)
console.log(updateData)
const requestOptions = {
method: 'PUT',
headers: {
'Authorization': token,
'Content-Type': 'application/json'
},
body: JSON.stringify(updateData)
}
return fetch(URL + `/degreeCourses/${degreeCourseID}`, requestOptions)
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
220
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
.then(response => {
console.log(response)
return response.json().then(body => {
if (response.status === 200) {
console.log(body)
return body
}
})
})
}
export function editDegreeCourseWithID(updateData, degreeCourseID, token) {
console.log("editing degreeCourse")
return dispatch => {
dispatch(getEditDegreeCourseSuccessAction());
updateDegreeCourse(updateData, degreeCourseID, token)
.then(degreeCourse => {
console.log(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) {
console.log("delete degreeCourse")
console.log(degreeCourseID)
const requestOptions = {
method: 'DELETE',
headers: {
'Authorization': token
}
}
return fetch(URL + '/degreeCourses/' + degreeCourseID, requestOptions)
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
.then(response => {
console.log(response)
if (response.status === 204) {
return response.status
}
})
}
export function deleteDegreeCourseWithID(degreeCourseID, token) {
console.log("deleting degreeCourse")
return dispatch => {
dispatch(getDeleteDegreeCourseSuccessAction(degreeCourseID));
deleteDegreeCourse(degreeCourseID, token)
.then(deleteDegreeCourse => {
console.log(deleteDegreeCourse)
const action = getDeleteDegreeCourseSuccessAction(deleteDegreeCourse)
dispatch(action);
getAllDegreeCourses(token)
.then(degreeCourses => {
const action = getAllDegreeCoursesAction(degreeCourses)
dispatch(action)
})
},
error => {
console.log(error)
dispatch(getDeleteDegreeCourseErrorAction(error));
}
)
.catch(error => {
dispatch(getDeleteDegreeCourseErrorAction(error))
})
}
}