diff options
Diffstat (limited to 'src/services/NotificationService.ts')
-rw-r--r-- | src/services/NotificationService.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/services/NotificationService.ts b/src/services/NotificationService.ts new file mode 100644 index 00000000..a62b0df9 --- /dev/null +++ b/src/services/NotificationService.ts @@ -0,0 +1,32 @@ +import AsyncStorage from '@react-native-community/async-storage'; +import {NOTIFICATIONS_ENDPOINT} from '../constants'; +import {NotificationType} from '../types'; + +export const getNotificationsData: () => Promise< + NotificationType[] +> = async () => { + try { + const token = await AsyncStorage.getItem('token'); + const response = await fetch(NOTIFICATIONS_ENDPOINT, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + if (response.status === 200) { + const data: any[] = await response.json(); + let typedData: NotificationType[] = []; + for (const o of data) { + typedData.push({ + ...o.notification, + unread: false, + }); + } + return typedData; + } + return []; + } catch (error) { + console.log('Unable to fetch notifications'); + return []; + } +}; |