From bbeb05fcc6b1c45f9273d1a78000c8f143d62451 Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Wed, 3 Feb 2021 17:02:01 -0800 Subject: Done --- src/services/MomentService.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/services') 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 = 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'); -- cgit v1.2.3-70-g09d2