diff options
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/MomentService.ts | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index a26a1abb..46b55066 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -2,24 +2,19 @@ import AsyncStorage from '@react-native-community/async-storage'; import RNFetchBlob from 'rn-fetch-blob'; import { MOMENTS_ENDPOINT, + MOMENTTAG_ENDPOINT, MOMENT_TAGS_ENDPOINT, MOMENT_THUMBNAIL_ENDPOINT, } from '../constants'; import {MomentTagType, MomentType} from '../types'; import {checkImageUploadStatus} from '../utils'; -export const postMoment: ( +export const postMoment = async ( fileName: string, uri: string, caption: string, category: string, userId: string, -) => Promise<number | undefined> = async ( - fileName, - uri, - caption, - category, - userId, ) => { try { const request = new FormData(); @@ -45,9 +40,13 @@ export const postMoment: ( body: request, }); let statusCode = response.status; - let data = await response.json(); + let data: { + moments: any; + moment_id: string; + profile_completion_stage: number; + } = await response.json(); if (statusCode === 200 && checkImageUploadStatus(data.moments)) { - return data.profile_completion_stage; + return data; } } catch (err) { console.log(err); @@ -142,3 +141,33 @@ export const loadMomentTags = async (moment_id: string) => { return []; } }; + +export const postMomentTags = async ( + moment_id: string, + tags: { + x: number; + y: number; + user_id: string; + }[], +) => { + try { + const token = await AsyncStorage.getItem('token'); + const form = new FormData(); + form.append('moment_id', moment_id); + form.append('tags', JSON.stringify(tags)); + const response = await fetch( + MOMENTTAG_ENDPOINT + `?moment_id=${moment_id}`, + { + method: 'POST', + headers: { + Authorization: 'Token ' + token, + }, + body: form, + }, + ); + return response.status === 201 || response.status === 200; + } catch (error) { + console.error(error); + return false; + } +}; |
