diff options
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/NotificationService.ts | 32 | ||||
| -rw-r--r-- | src/services/UserProfileService.ts | 13 | ||||
| -rw-r--r-- | src/services/index.ts | 1 |
3 files changed, 43 insertions, 3 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 []; + } +}; diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index c67174f9..8c88f0ab 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -1,3 +1,4 @@ +import {transformFromAstAsync} from '@babel/core'; import AsyncStorage from '@react-native-community/async-storage'; import moment from 'moment'; import {Alert} from 'react-native'; @@ -14,6 +15,7 @@ import { TAGG_CUSTOMER_SUPPORT, VERIFY_OTP_ENDPOINT, SEND_OTP_ENDPOINT, + PROFILE_PHOTO_THUMBNAIL_ENDPOINT, } from '../constants'; export const loadProfileInfo = async (token: string, userId: string) => { @@ -41,12 +43,16 @@ export const loadProfileInfo = async (token: string, userId: string) => { } }; -export const loadAvatar = async (token: string, userId: string) => { +export const loadAvatar = async (userId: string, thumbnail: boolean) => { try { + const token = await AsyncStorage.getItem('token'); + const url = thumbnail + ? PROFILE_PHOTO_THUMBNAIL_ENDPOINT + : PROFILE_PHOTO_ENDPOINT; const response = await RNFetchBlob.config({ fileCache: true, appendExt: 'jpg', - }).fetch('GET', PROFILE_PHOTO_ENDPOINT + `${userId}/`, { + }).fetch('GET', url + `${userId}/`, { Authorization: 'Token ' + token, }); const status = response.info().status; @@ -57,6 +63,7 @@ export const loadAvatar = async (token: string, userId: string) => { } } catch (error) { console.log(error); + return ''; } }; @@ -209,7 +216,7 @@ export const handlePasswordCodeVerification = async ( export const handlePasswordReset = async (value: string, password: string) => { try { const token = await AsyncStorage.getItem('token'); - const response = await fetch(PASSWORD_RESET_ENDPOINT + `reset/`, { + const response = await fetch(PASSWORD_RESET_ENDPOINT + 'reset/', { method: 'POST', headers: { Authorization: 'Token ' + token, diff --git a/src/services/index.ts b/src/services/index.ts index 81a09b92..7e6b836a 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -6,4 +6,5 @@ export * from './UserFollowServices'; export * from './ReportingService'; export * from './BlockUserService'; export * from './MomentCategoryService'; +export * from './NotificationService'; export * from './FCMService'; |
