Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1865a0be

Přidáno uživatelem Pavel Fidransky před více než 4 roky(ů)

re #58 massive code formatting

Zobrazit rozdíly:

client/src/api.js
1
// ******************** Log Out ********************
2

  
3
export const logOut = async () => {
1
import * as HttpStatus from './HttpStatus';
4 2

  
3
/**
4
 * Log Out
5
 */
6
export async function logOut() {
5 7
  let response;
6 8

  
7 9
  try {
8
    response = await fetch(
9
      `${window.config.baseUrl}/logout`, {
10
        credentials: 'include'
11
      }
12
    );    
10
    response = await fetch(`${window.config.baseUrl}/logout`, {
11
      credentials: 'include',
12
    });
13 13
  } catch (e) {
14
    throw 'Server is not available'
15
    }
14
    throw new Error('Server is not available');
15
  }
16 16

  
17 17
  if (response.ok) {
18
        window.location.replace(`/logout`)
18
    window.location.replace('/logout');
19 19
  } else {
20
      switch (response.status) {
21
        case 500:
22
          throw new Error('Internal server error.')
23
        default:
24
          throw new Error(response.statusText)
25
      }
20
    switch (response.status) {
21
      case HttpStatus.INTERNAL_SERVER_ERROR:
22
        throw new Error('Internal server error.');
23
      default:
24
        throw new Error(response.statusText);
26 25
    }
26
  }
27 27
}
28 28

  
29
// ******************** GET DATA APP getCurrentProfile ********************
30

  
31
export const getCurrentProfile = async () => {
32

  
29
/**
30
 * GET DATA APP getCurrentProfile
31
 */
32
export async function getCurrentProfile() {
33 33
  let response;
34 34

  
35 35
  try {
36
    response = await fetch(
37
      `${window.config.baseUrl}/users/current/profile`, {
38

  
39
        credentials: 'include'
40
      }
41
    );    
36
    response = await fetch(`${window.config.baseUrl}/users/current/profile`, {
37
      credentials: 'include',
38
    });
42 39
  } catch (e) {
43
    throw 'Server is not available'
44
    }
40
    throw new Error('Server is not available');
41
  }
45 42

  
46 43
  if (response.ok) {
47 44
    const data = await response.json();
......
53 50
      holiday: data.vacationCount,
54 51
      sickday: data.sickDayCount,
55 52
      photo: data.photo,
56
      takenSickday: data.takenSickDayCount
57
    }
53
      takenSickday: data.takenSickDayCount,
54
    };
58 55
  } else {
59
      switch (response.status) {
60
        case 401:
61
          window.location.replace(`/login`)
62
          break;
63
        case 403:
64
          window.location.replace(`/login`)
65
          break;
66
        case 500:
67
          throw new Error('Internal server error.')
68
        default:
69
          throw new Error(response.statusText)
70
      }
56
    switch (response.status) {
57
      case HttpStatus.UNAUTHORIZED:
58
        window.location.replace('/login');
59
        break;
60
      case HttpStatus.FORBIDDEN:
61
        window.location.replace('/login');
62
        break;
63
      case HttpStatus.INTERNAL_SERVER_ERROR:
64
        throw new Error('Internal server error.');
65
      default:
66
        throw new Error(response.statusText);
71 67
    }
68
  }
72 69
}
73 70

  
74
// ******************** LOAD DATA to CALENDAR - EMPLOYEE ********************
75
export const getUserCalendar = async (currentUser, fromDate ) => {
76

  
71
/**
72
 * LOAD DATA to CALENDAR - EMPLOYEE
73
 */
74
export async function getUserCalendar(currentUser, fromDate ) {
77 75
  let response;
78 76

  
79 77
  try {
80
    response = await fetch(
81
      `${window.config.baseUrl}/user/${currentUser.id}/calendar?from=${fromDate}&status=ACCEPTED&status=REJECTED`, {
82
        headers: {
83
          'Accept': 'application/json',
84
        },
85
        credentials: 'include',
86
        method: 'GET',
87
      }
88
    );
78
    response = await fetch(`${window.config.baseUrl}/user/${currentUser.id}/calendar?from=${fromDate}&status=ACCEPTED&status=REJECTED`, {
79
      headers: {
80
        'Accept': 'application/json',
81
      },
82
      credentials: 'include',
83
      method: 'GET',
84
    });
89 85
  } catch (e) {
90
    throw 'Server is not available'
86
    throw new Error('Server is not available');
91 87
  }
92 88

  
93 89
  if (response.ok) {
94 90
    const data = await response.json();
95
  
91

  
96 92
    return data.filter(day => {
97
      return day.status !== 'PENDING'
93
      return day.status !== 'PENDING';
98 94
    }).map(day => {
95
      const newDate = day.date.split('/').join('-');
99 96

  
100
    const newDate = day.date.split("/").join("-");
101

  
102
    return ({
103
      title: currentUser.name,
104
      start: newDate,
105
      backgroundColor: day.status === 'REJECTED' ? 'red' : 'green'
106
    })
107
  })
97
      return ({
98
        title: currentUser.name,
99
        start: newDate,
100
        backgroundColor: day.status === 'REJECTED' ? 'red' : 'green',
101
      });
102
    });
108 103
  } else {
109
      switch (response.status) {
110
        case 400:
111
          throw new Error('Bad request. Check query parameters.')
112
        case 401:
113
          window.location.replace(`/login`)
114
        case 403:
115
          window.location.replace(`/login`)
116
        case 404:
117
          throw new Error('User with given ID does not exist.')
118
        case 500:
119
          throw new Error('Internal server error.')
120
        default:
121
          throw new Error(response.statusText)
122
      }
104
    switch (response.status) {
105
      case HttpStatus.BAD_REQUEST:
106
        throw new Error('Bad request. Check query parameters.');
107
      case HttpStatus.UNAUTHORIZED:
108
        window.location.replace('/login');
109
        break;
110
      case HttpStatus.FORBIDDEN:
111
        window.location.replace('/login');
112
        break;
113
      case HttpStatus.NOT_FOUND:
114
        throw new Error('User with given ID does not exist.');
115
      case HttpStatus.INTERNAL_SERVER_ERROR:
116
        throw new Error('Internal server error.');
117
      default:
118
        throw new Error(response.statusText);
123 119
    }
120
  }
124 121
}
125 122

  
126
// ******************** LOAD DATA to CALENDAR - EMPLOYER ********************
127

  
128
export const getAdminCalendar = async () => {
129

  
123
/**
124
 * LOAD DATA to CALENDAR - EMPLOYER
125
 */
126
export async function getAdminCalendar() {
130 127
  let response;
131 128

  
132 129
  try {
133
    response = await fetch(
134
      `${window.config.baseUrl}/users/requests/vacation?status=ACCEPTED`, {
135
        headers: {
136
          'Accept': 'application/json',
137
        },
138
        credentials: 'include',
139
        method: 'GET',
140
      }
141
    );
130
    response = await fetch(`${window.config.baseUrl}/users/requests/vacation?status=ACCEPTED`, {
131
      headers: {
132
        'Accept': 'application/json',
133
      },
134
      credentials: 'include',
135
      method: 'GET',
136
    });
142 137
  } catch (e) {
143
    throw 'Server is not available'
138
    throw new Error('Server is not available');
144 139
  }
145 140

  
146 141
  if (response.ok) {
147 142
    const data = await response.json();
148
    
143

  
149 144
    return data.map(day => {
150 145

  
151
      const newDate = day.date.split("/").join("-");
146
      const newDate = day.date.split('/').join('-');
152 147

  
153
      return ( {
154
      title: day.firstName + ' ' + day.lastName,
155
      start: newDate
156
      })
157
    })
148
      return {
149
        title: day.firstName + ' ' + day.lastName,
150
        start: newDate,
151
      };
152
    });
158 153
  } else {
159
      switch (response.status) {
160
        case 400:
161
          throw new Error('Bad request. Check query parameters.')
162
        case 401:
163
          window.location.replace(`/login`)
164
        case 403:
165
          window.location.replace(`/login`)
166
        case 500:
167
          throw new Error('Internal server error.')
168
        default:
169
          throw new Error(response.statusText)
170
      }
154
    switch (response.status) {
155
      case HttpStatus.BAD_REQUEST:
156
        throw new Error('Bad request. Check query parameters.');
157
      case HttpStatus.UNAUTHORIZED:
158
        window.location.replace('/login');
159
        break;
160
      case HttpStatus.FORBIDDEN:
161
        window.location.replace('/login');
162
        break;
163
      case HttpStatus.INTERNAL_SERVER_ERROR:
164
        throw new Error('Internal server error.');
165
      default:
166
        throw new Error(response.statusText);
171 167
    }
168
  }
172 169
}
173 170

  
174
// ******************** ADD EVENT to CALENDAR - EMPLOYEE ********************
175

  
171
/**
172
 * ADD EVENT to CALENDAR - EMPLOYEE
173
 */
176 174
export async function addEventApi(dataAddEventEmployee) {
177 175
  let response;
178 176

  
......
184 182
      },
185 183
      credentials: 'include',
186 184
      method: 'POST',
187
  // object which is sent to server
188
  body: JSON.stringify(dataAddEventEmployee),
185
      // object which is sent to server
186
      body: JSON.stringify(dataAddEventEmployee),
189 187
    });
190 188
  } catch (e) {
191
    throw 'Server is not available'
189
    throw new Error('Server is not available');
192 190
  }
193 191

  
194 192
  if (!response.ok) {
195
      switch (response.status) {
196
        case 400:
197
          throw new Error('Bad request. Check request body.')
198
        case 401:
199
          window.location.replace(`/login`)
200
        case 403:
201
          window.location.replace(`/login`)
202
        case 500:
203
          throw new Error('Internal server error.')
204
        default:
205
          throw new Error(response.statusText)
206
      }    
193
    switch (response.status) {
194
      case HttpStatus.BAD_REQUEST:
195
        throw new Error('Bad request. Check request body.');
196
      case HttpStatus.UNAUTHORIZED:
197
        window.location.replace('/login');
198
        break;
199
      case HttpStatus.FORBIDDEN:
200
        window.location.replace('/login');
201
        break;
202
      case HttpStatus.INTERNAL_SERVER_ERROR:
203
        throw new Error('Internal server error.');
204
      default:
205
        throw new Error(response.statusText);
207 206
    }
207
  }
208 208
}
209
      
210
// ******************** ADD EVENT to CALENDAR - EMPLOYER ********************
211 209

  
210
/**
211
 * ADD EVENT to CALENDAR - EMPLOYER
212
 */
212 213
export async function addEventApiAdmin(dataAddEventAdmin) {
213 214
  let response;
214 215

  
215 216
  try {
216
  // send accepted request to server
217
    // send accepted request to server
217 218
    response = await fetch(`${window.config.baseUrl}/user/calendar/create`, {
218 219
      headers: {
219 220
        'Content-Type': 'application/json',
220
    },
221
    credentials: 'include',
221
      },
222
      credentials: 'include',
222 223
      method: 'POST',
223
    // object which is sent to server
224
      // object which is sent to server
224 225
      body: JSON.stringify(dataAddEventAdmin),
225 226
    });
226 227
  } catch (e) {
227
    throw 'Server is not available'
228
    throw new Error('Server is not available');
228 229
  }
229 230

  
230 231
  if (!response.ok) {
231 232
    switch (response.status) {
232
      case 400:
233
        throw new Error('Bad request. Check request body.')
234
      case 401:
235
        window.location.replace(`/login`)
236
      case 403:
237
        window.location.replace(`/login`)
238
      case 500:
239
        throw new Error('Internal server error.')
233
      case HttpStatus.BAD_REQUEST:
234
        throw new Error('Bad request. Check request body.');
235
      case HttpStatus.UNAUTHORIZED:
236
        window.location.replace('/login');
237
        break;
238
      case HttpStatus.FORBIDDEN:
239
        window.location.replace('/login');
240
        break;
241
      case HttpStatus.INTERNAL_SERVER_ERROR:
242
        throw new Error('Internal server error.');
240 243
      default:
241
        throw new Error(response.statusText)
242
    }    
244
        throw new Error(response.statusText);
245
    }
243 246
  }
244 247
}
245 248

  
246
// ******************** GET DATA to OVERVIEW - EMPLOYER ********************
247

  
248
export const getUsersOverview = async () => {
249
/**
250
 * GET DATA to OVERVIEW - EMPLOYER
251
 */
252
export async function getUsersOverview() {
249 253
  let response;
250 254

  
251 255
  try {
252
  response = await fetch (
253
    `${window.config.baseUrl}/users`, {
256
    response = await fetch (`${window.config.baseUrl}/users`, {
254 257
      credentials: 'include',
255
    }
256
  );
258
    });
257 259
  } catch (e) {
258
    throw 'Server is not available'
260
    throw new Error('Server is not available');
259 261
  }
260
  
261
  if (response.ok) {
262 262

  
263
  if (response.ok) {
263 264
    const data = await response.json();
264 265
    return data.map(user => {
265

  
266
     return ({
267
           name: user.firstName + ' ' + user.lastName,
268
           id: user.id,
269
           sickday: user.sickDayCount,
270
           holiday: user.vacationCount,
271
           takenSickday: user.takenSickDayCount,
272
           role: user.role
273
        })
274
    })
266
      return {
267
        name: user.firstName + ' ' + user.lastName,
268
        id: user.id,
269
        sickday: user.sickDayCount,
270
        holiday: user.vacationCount,
271
        takenSickday: user.takenSickDayCount,
272
        role: user.role,
273
      };
274
    });
275 275
  } else {
276 276
    switch (response.status) {
277
      case 400:
278
        throw new Error('Bad request. Check query parameters.')
279
      case 401:
280
        window.location.replace(`/login`)
281
      case 403:
282
        window.location.replace(`/login`)
283
      case 500:
284
        throw new Error('Internal server error.')
277
      case HttpStatus.BAD_REQUEST:
278
        throw new Error('Bad request. Check query parameters.');
279
      case HttpStatus.UNAUTHORIZED:
280
        window.location.replace('/login');
281
        break;
282
      case HttpStatus.FORBIDDEN:
283
        window.location.replace('/login');
284
        break;
285
      case HttpStatus.INTERNAL_SERVER_ERROR:
286
        throw new Error('Internal server error.');
285 287
      default:
286
        throw new Error(response.statusText)
287
    }    
288
        throw new Error(response.statusText);
289
    }
288 290
  }
289 291
}
290 292

  
291
// ******************** SAVE DATA to OVERVIEW - EMPLOYER ********************
292

  
293
/**
294
 * SAVE DATA to OVERVIEW - EMPLOYER
295
 */
293 296
export async function saveDataOverview(dataOverviewObject) {
294 297
  let response;
295 298

  
296 299
  try {
297 300
    // send accepted request to server
298
        response = await fetch(`${window.config.baseUrl}/user/settings`, {
299
          headers: {
300
            'Content-Type': 'application/json',
301
          },
302
          credentials: 'include',
303
          method: 'PUT',
304
 
305
    // object which is sent to server
306
          body: JSON.stringify(dataOverviewObject),        
307
        });
301
    response = await fetch(`${window.config.baseUrl}/user/settings`, {
302
      headers: {
303
        'Content-Type': 'application/json',
304
      },
305
      credentials: 'include',
306
      method: 'PUT',
307
      // object which is sent to server
308
      body: JSON.stringify(dataOverviewObject),
309
    });
308 310
  } catch (e) {
309
    throw 'Server is not available'
311
    throw new Error('Server is not available');
310 312
  }
311 313

  
312 314
  if (!response.ok) {
313 315
    switch (response.status) {
314
      case 400:
315
        throw new Error('Bad request. Check query parameters.')
316
      case 401:
317
        window.location.replace(`/login`)
318
      case 403:
319
        window.location.replace(`/login`)
320
      case 500:
321
        throw new Error('Internal server error.')
316
      case HttpStatus.BAD_REQUEST:
317
        throw new Error('Bad request. Check query parameters.');
318
      case HttpStatus.UNAUTHORIZED:
319
        window.location.replace('/login');
320
        break;
321
      case HttpStatus.FORBIDDEN:
322
        window.location.replace('/login');
323
        break;
324
      case HttpStatus.INTERNAL_SERVER_ERROR:
325
        throw new Error('Internal server error.');
322 326
      default:
323
        throw new Error(response.statusText)
327
        throw new Error(response.statusText);
324 328
    }
325
  }    
329
  }
326 330
}
327 331

  
328
// ******************** LOAD DATA to SETTING - EMPLOYER ********************
329
export const getSettingData = async () =>  {
332
/**
333
 * LOAD DATA to SETTING - EMPLOYER
334
 */
335
export async function getSettingData() {
330 336
  let response;
331 337

  
332 338
  try {
333
    response = await fetch(
334
      `${window.config.baseUrl}/settings`, {
335
        credentials: 'include',
336
      }
337
    );
338

  
339
    response = await fetch(`${window.config.baseUrl}/settings`, {
340
      credentials: 'include',
341
    });
339 342
  } catch (e) {
340
    throw 'Server is not available'
341
    }
343
    throw new Error('Server is not available');
344
  }
342 345

  
343 346
  if (response.ok) {
344 347
    const data = await response.json();
345 348
    return {
346 349
      sickday: data.sickDayCount,
347
    }
350
    };
348 351
  } else {
349 352
    switch (response.status) {
350
      case 500:
351
        throw new Error('Internal server error.')
353
      case HttpStatus.INTERNAL_SERVER_ERROR:
354
        throw new Error('Internal server error.');
352 355
      default:
353
        throw new Error(response.statusText)
354
      }            
356
        throw new Error(response.statusText);
355 357
    }
356

  
358
  }
357 359
}
358 360

  
359
// ******************** SAVE DATA to SETTING - EMPLOYER ********************
361
/**
362
 * SAVE DATA to SETTING - EMPLOYER
363
 */
360 364
export async function saveDataSetting(dataSettingObject) {
361 365
  let response;
362 366

  
363 367
  try {
364 368
    response = await fetch(`${window.config.baseUrl}/settings`, {
365 369
      headers: {
366
        'Content-Type': 'application/json'
370
        'Content-Type': 'application/json',
367 371
      },
368 372
      credentials: 'include',
369 373
      method: 'POST',
370 374
      body: JSON.stringify(dataSettingObject),
371 375
    });
372 376
  } catch (e) {
373
    throw 'Server is not available'
377
    throw new Error('Server is not available');
374 378
  }
375 379

  
376 380
  if (!response.ok) {
377 381
    switch (response.status) {
378
      case 401:
379
        window.location.replace(`/login`)
380
      case 403:
381
        window.location.replace(`/login`)
382
      case 500:
383
        throw new Error('Internal server error.')
382
      case HttpStatus.UNAUTHORIZED:
383
        window.location.replace('/login');
384
        break;
385
      case HttpStatus.FORBIDDEN:
386
        window.location.replace('/login');
387
        break;
388
      case HttpStatus.INTERNAL_SERVER_ERROR:
389
        throw new Error('Internal server error.');
384 390
      default:
385
        throw new Error(response.statusText)
386
    }    
391
        throw new Error(response.statusText);
392
    }
387 393
  }
388 394
}
389 395

  
390
// ****************** LOAD DATA to YOUR REQUESTS - EMPLOYEE ******************
391

  
396
/**
397
 * LOAD DATA to YOUR REQUESTS - EMPLOYEE
398
 */
392 399
export async function loadYourRequests(currentUser) {
393 400
  let response;
394
  
401

  
395 402
  try {
396
    response = await fetch(
397
      `${window.config.baseUrl}/user/${currentUser.id}/calendar?from=2020/06/24&status=PENDING`, {
398
        credentials: 'include',
399
      }
400
    );
403
    response = await fetch(`${window.config.baseUrl}/user/${currentUser.id}/calendar?from=2020/06/24&status=PENDING`, {
404
      credentials: 'include',
405
    });
401 406
  } catch (e) {
402
    throw 'Server is not available'
407
    throw new Error('Server is not available');
403 408
  }
404 409

  
405 410
  if (response.ok) {
406 411
    const data = await response.json();
407 412
    return data;
408 413
  } else {
409
      switch (response.status) {
410
        case 400:
411
          throw new Error('Bad request. Check query parameters.')
412
        case 401:
413
          window.location.replace(`/login`)
414
        case 403:
415
          window.location.replace(`/login`)
416
        case 500:
417
          throw new Error('Internal server error.')
418
        default:
419
          throw new Error(response.statusText)
420
      }    
414
    switch (response.status) {
415
      case HttpStatus.BAD_REQUEST:
416
        throw new Error('Bad request. Check query parameters.');
417
      case HttpStatus.UNAUTHORIZED:
418
        window.location.replace('/login');
419
        break;
420
      case HttpStatus.FORBIDDEN:
421
        window.location.replace('/login');
422
        break;
423
      case HttpStatus.INTERNAL_SERVER_ERROR:
424
        throw new Error('Internal server error.');
425
      default:
426
        throw new Error(response.statusText);
421 427
    }
428
  }
422 429
}
423 430

  
424
// ****************** LOAD DATA - UPCOMING REQUESTS - EMPLOYER ****************** //tady
431
/**
432
 * LOAD DATA - UPCOMING REQUESTS - EMPLOYER
433
 */
425 434
export async function loadAdminRequests() {
426 435
  let response;
427 436

  
428 437
  try {
429
    response = await fetch(
430
      `${window.config.baseUrl}/users/requests/vacation?status=PENDING`, {
431
        credentials: 'include',
432
      },
433
    );
438
    response = await fetch(`${window.config.baseUrl}/users/requests/vacation?status=PENDING`, {
439
      credentials: 'include',
440
    });
434 441
  } catch (e) {
435
    throw 'Server is not available'
436
    } 
437
  
442
    throw new Error('Server is not available');
443
  }
444

  
438 445
  if (response.ok) {
439
    const data = await response.json();
440
      return data;
446
    return response.json();
441 447
  } else {
442
      switch (response.status) {
443
        case 400:
444
          throw new Error('Bad request. Check query parameters.')
445
        case 401:
446
          window.location.replace(`/login`)
447
        case 403:
448
          window.location.replace(`/login`)
449
        case 500:
450
          throw new Error('Internal server error.')
451
        default:
452
          throw new Error(response.statusText)
453
      }   
448
    switch (response.status) {
449
      case HttpStatus.BAD_REQUEST:
450
        throw new Error('Bad request. Check query parameters.');
451
      case HttpStatus.UNAUTHORIZED:
452
        window.location.replace('/login');
453
        break;
454
      case HttpStatus.FORBIDDEN:
455
        window.location.replace('/login');
456
        break;
457
      case HttpStatus.INTERNAL_SERVER_ERROR:
458
        throw new Error('Internal server error.');
459
      default:
460
        throw new Error(response.statusText);
454 461
    }
462
  }
455 463
}
456 464

  
457
// ************** SEND ACCEPTED DATA - UPCOMING REQUESTS - EMPLOYER **************
458

  
465
/**
466
 * SEND ACCEPTED DATA - UPCOMING REQUESTS - EMPLOYER
467
 */
459 468
export async function sendAcceptedRequest(acceptedRequests) {
460 469
  let response;
461 470

  
......
469 478
      body: JSON.stringify(acceptedRequests),
470 479
    });
471 480
  } catch (e) {
472
    throw 'Server is not available'
473
    }
481
    throw new Error('Server is not available');
482
  }
474 483

  
475 484
  if (!response.ok) {
476 485
    switch (response.status) {
477
      case 400:
478
        throw new Error('Bad request. Check query parameters and request body.')
479
      case 401:
480
        window.location.replace(`/login`)
481
      case 403:
482
        window.location.replace(`/login`)
483
      case 404:
484
        throw new Error('Neither vacation nor authorization request with given ID exists.')
485
      case 500:
486
        throw new Error('Internal server error.')
486
      case HttpStatus.BAD_REQUEST:
487
        throw new Error('Bad request. Check query parameters and request body.');
488
      case HttpStatus.UNAUTHORIZED:
489
        window.location.replace('/login');
490
        break;
491
      case HttpStatus.FORBIDDEN:
492
        window.location.replace('/login');
493
        break;
494
      case HttpStatus.NOT_FOUND:
495
        throw new Error('Neither vacation nor authorization request with given ID exists.');
496
      case HttpStatus.INTERNAL_SERVER_ERROR:
497
        throw new Error('Internal server error.');
487 498
      default:
488
        throw new Error(response.statusText)
489
    }   
499
        throw new Error(response.statusText);
500
    }
490 501
  }
491 502
}
492 503

  
493
// ************** SEND REJECTED DATA - UPCOMING REQUESTS - EMPLOYER **************
494

  
504
/**
505
 * SEND REJECTED DATA - UPCOMING REQUESTS - EMPLOYER
506
 */
495 507
export async function sendRejectedRequest(rejectedRequest) {
496 508
  let response;
497
  
509

  
498 510
  try {
499 511
    response = await fetch(`${window.config.baseUrl}/user/requests?type=VACATION`, {
500 512
      headers: {
......
505 517
      body: JSON.stringify(rejectedRequest),
506 518
    });
507 519
  } catch (e) {
508
    throw 'Server is not available'
509
    }
510
  
520
    throw new Error('Server is not available');
521
  }
522

  
511 523
  if (!response.ok) {
512 524
    switch (response.status) {
513
      case 400:
514
        throw new Error('Bad request. Check query parameters and request body.')
515
      case 401:
516
        window.location.replace(`/login`)
517
      case 403:
518
        window.location.replace(`/login`)
519
      case 404:
520
        throw new Error('Neither vacation nor authorization request with given ID exists.')
521
      case 500:
522
        throw new Error('Internal server error.')
525
      case HttpStatus.BAD_REQUEST:
526
        throw new Error('Bad request. Check query parameters and request body.');
527
      case HttpStatus.UNAUTHORIZED:
528
        window.location.replace('/login');
529
        break;
530
      case HttpStatus.FORBIDDEN:
531
        window.location.replace('/login');
532
        break;
533
      case HttpStatus.NOT_FOUND:
534
        throw new Error('Neither vacation nor authorization request with given ID exists.');
535
      case HttpStatus.INTERNAL_SERVER_ERROR:
536
        throw new Error('Internal server error.');
523 537
      default:
524
        throw new Error(response.statusText)
525
    }    
538
        throw new Error(response.statusText);
539
    }
526 540
  }
527 541
}

Také k dispozici: Unified diff