diff options
| author | Ashm Walia <ashmwalia@outlook.com> | 2021-02-03 17:02:01 -0800 |
|---|---|---|
| committer | Ashm Walia <ashmwalia@outlook.com> | 2021-02-03 17:02:01 -0800 |
| commit | bbeb05fcc6b1c45f9273d1a78000c8f143d62451 (patch) | |
| tree | 157e4db761452230f50cb88cf171ec35f75350b7 /src/services | |
| parent | c3cd8f95c6534fb5eb78af299ef424c50aefd85a (diff) | |
Done
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/MomentService.ts | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index 2354d18e..514ca776 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -1,7 +1,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import RNFetchBlob from 'rn-fetch-blob'; import {MOMENTS_ENDPOINT, MOMENT_THUMBNAIL_ENDPOINT} from '../constants'; -import {MomentType} from '../types'; +import {MomentType, MomentWithUserType} from '../types'; import {checkImageUploadStatus} from '../utils'; export const postMoment: ( @@ -78,6 +78,33 @@ export const loadMoments: ( return moments; }; +export const loadSingleMoment: ( + momentId: string, + token: string, +) => Promise<MomentWithUserType | undefined> = async (momentId, token) => { + let moment: MomentWithUserType; + try { + const response = await fetch(MOMENTS_ENDPOINT + `${momentId}/`, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + const status = response.status; + if (status === 200) { + const data = await response.json(); + moment = data; + } else { + console.log('Could not load moments!'); + return undefined; + } + } catch (err) { + console.log(err); + return undefined; + } + return moment; +}; + export const deleteMoment = async (momentId: string) => { try { const token = await AsyncStorage.getItem('token'); |
