diff options
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/MomentServices.ts | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts index 46ca1351..ed868582 100644 --- a/src/services/MomentServices.ts +++ b/src/services/MomentServices.ts @@ -1,6 +1,6 @@ -//Common moments api abstracted out here -import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants'; +import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; +import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants'; import {MomentType} from '../types'; //Get all comments for a moment @@ -123,3 +123,21 @@ export const loadMoments: ( } return moments; }; + +export const deleteMoment = async (momentId: string) => { + try { + const token = await AsyncStorage.getItem('token'); + + const response = await fetch(MOMENTS_ENDPOINT + `${momentId}/`, { + method: 'DELETE', + headers: { + Authorization: 'Token ' + token, + }, + }); + return response.status === 200; + } catch (error) { + console.log(error); + console.log('Unable to delete moment', momentId); + return false; + } +}; |
