aboutsummaryrefslogtreecommitdiff
path: root/src/services/MomentService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/MomentService.ts')
-rw-r--r--src/services/MomentService.ts53
1 files changed, 38 insertions, 15 deletions
diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts
index af602dc7..b837585a 100644
--- a/src/services/MomentService.ts
+++ b/src/services/MomentService.ts
@@ -6,7 +6,7 @@ import {
MOMENT_TAGS_ENDPOINT,
MOMENT_THUMBNAIL_ENDPOINT,
} from '../constants';
-import {MomentTagType, MomentType} from '../types';
+import {MomentPostType, MomentTagType} from '../types';
import {checkImageUploadStatus} from '../utils';
export const postMoment = async (
@@ -54,11 +54,39 @@ export const postMoment = async (
return undefined;
};
-export const loadMoments: (
- userId: string,
- token: string,
-) => Promise<MomentType[]> = async (userId, token) => {
- let moments: MomentType[] = [];
+export const patchMoment = async (
+ momentId: string,
+ caption: string,
+ tags: {
+ x: number;
+ y: number;
+ z: number;
+ user_id: string;
+ }[],
+) => {
+ try {
+ const request = new FormData();
+ request.append('moment_id', momentId);
+ request.append('captions', JSON.stringify({[momentId]: caption}));
+ request.append('tags', JSON.stringify(tags));
+ const token = await AsyncStorage.getItem('token');
+ let response = await fetch(MOMENTS_ENDPOINT, {
+ method: 'PATCH',
+ headers: {
+ 'Content-Type': 'multipart/form-data',
+ Authorization: 'Token ' + token,
+ },
+ body: request,
+ });
+ let statusCode = response.status;
+ return statusCode === 200 || statusCode === 201;
+ } catch (err) {
+ console.log(err);
+ }
+ return false;
+};
+
+export const loadMoments = async (userId: string, token: string) => {
try {
const response = await fetch(MOMENTS_ENDPOINT + '?user_id=' + userId, {
method: 'GET',
@@ -66,19 +94,14 @@ export const loadMoments: (
Authorization: 'Token ' + token,
},
});
- const status = response.status;
- if (status === 200) {
- const data = await response.json();
- moments = data;
- } else {
- console.log('Could not load moments!');
- return [];
+ if (response.status === 200) {
+ const typedData: MomentPostType[] = await response.json();
+ return typedData;
}
} catch (err) {
console.log(err);
- return [];
}
- return moments;
+ return [];
};
export const deleteMoment = async (momentId: string) => {