|
6 | 6 | */
|
7 | 7 |
|
8 | 8 | import { User } from 'oidc-client';
|
9 |
| -import { backendFetch, backendFetchJson, backendFetchText, getRestBase } from '../utils/api-rest'; |
| 9 | +import { backendFetch, backendFetchJson, getRestBase } from '../utils/api-rest'; |
10 | 10 | import { extractUserSub, getToken, getUser } from '../utils/api';
|
11 | 11 | import { UUID } from 'crypto';
|
12 | 12 |
|
@@ -305,36 +305,38 @@ export type Announcement = NewAnnouncement & {
|
305 | 305 | id: UUID;
|
306 | 306 | };
|
307 | 307 |
|
308 |
| -export async function addAnnouncement(announcement: NewAnnouncement): Promise<UUID> { |
| 308 | +export async function addAnnouncement(announcement: NewAnnouncement) { |
309 | 309 | console.debug(`Creating announcement ...`);
|
310 |
| - return backendFetchText( |
| 310 | + return backendFetchJson<Announcement>( |
311 | 311 | `${USER_ADMIN_URL}/announcements?startDate=${announcement.startDate}&endDate=${announcement.endDate}&severity=${announcement.severity}`,
|
312 | 312 | {
|
313 |
| - method: 'post', |
| 313 | + method: 'put', |
314 | 314 | headers: {
|
315 | 315 | Accept: 'plain/text',
|
316 | 316 | 'Content-Type': 'plain/text',
|
317 | 317 | },
|
318 | 318 | body: sanitizeString(announcement.message),
|
319 | 319 | }
|
320 | 320 | ).catch((reason) => {
|
321 |
| - console.error(`Error while creating announcement : ${reason}`); |
| 321 | + console.error('Error while creating announcement:', reason); |
322 | 322 | throw reason;
|
323 |
| - }) as Promise<UUID>; |
| 323 | + }); |
324 | 324 | }
|
325 | 325 |
|
326 |
| -export function fetchAnnouncementList() { |
| 326 | +export async function fetchAnnouncementList() { |
327 | 327 | console.debug(`Fetching announcement ...`);
|
328 |
| - return backendFetchJson<Announcement[]>(`${USER_ADMIN_URL}/announcements`, { method: 'get' }).catch((reason) => { |
329 |
| - console.error(`Error while fetching announcement : ${reason}`); |
| 328 | + try { |
| 329 | + return await backendFetchJson<Announcement[]>(`${USER_ADMIN_URL}/announcements`, { method: 'get' }); |
| 330 | + } catch (reason) { |
| 331 | + console.error('Error while fetching announcement:', reason); |
330 | 332 | throw reason;
|
331 |
| - }); |
| 333 | + } |
332 | 334 | }
|
333 | 335 |
|
334 | 336 | export async function deleteAnnouncement(announcementId: UUID): Promise<void> {
|
335 | 337 | console.debug(`Deleting announcement ${announcementId}...`);
|
336 | 338 | await backendFetch(`${USER_ADMIN_URL}/announcements/${announcementId}`, { method: 'delete' }).catch((reason) => {
|
337 |
| - console.error(`Error while deleting announcement : ${reason}`); |
| 339 | + console.error('Error while deleting announcement:', reason); |
338 | 340 | throw reason;
|
339 | 341 | });
|
340 | 342 | }
|
0 commit comments