diff options
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/ExploreServices.ts | 34 | ||||
| -rw-r--r-- | src/services/MomentCategoryService.ts | 53 | ||||
| -rw-r--r-- | src/services/MomentServices.ts | 52 | ||||
| -rw-r--r-- | src/services/UserProfileService.ts | 2 | ||||
| -rw-r--r-- | src/services/WaitlistUserService.tsx | 45 | ||||
| -rw-r--r-- | src/services/index.ts | 1 |
6 files changed, 144 insertions, 43 deletions
diff --git a/src/services/ExploreServices.ts b/src/services/ExploreServices.ts index 2181ea7d..ca4f1b69 100644 --- a/src/services/ExploreServices.ts +++ b/src/services/ExploreServices.ts @@ -1,4 +1,8 @@ -import {ALL_USERS_ENDPOINT} from '../constants'; +import AsyncStorage from '@react-native-community/async-storage'; +import {getDeviceToken} from 'react-native-device-info'; +import {ALL_USERS_ENDPOINT, DISCOVER_ENDPOINT} from '../constants'; +import {EMPTY_EXPLORE_SECTIONS} from '../store/initialStates'; +import {ExploreSectionType, ProfilePreviewType} from '../types'; export const getAllTaggUsers = async (token: string) => { try { @@ -26,3 +30,31 @@ export const getAllTaggUsers = async (token: string) => { ); } }; + +export const getAllExploreSections = async () => { + try { + const token = await AsyncStorage.getItem('token'); + const response = await fetch(DISCOVER_ENDPOINT, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + if (response.status !== 200) { + return EMPTY_EXPLORE_SECTIONS; + } + const data = await response.json(); + const exploreSections: Record<ExploreSectionType, ProfilePreviewType[]> = { + 'New to Tagg': data.categories.new_to_tagg, + 'People You May Know': data.categories.people_you_may_know, + 'Trending on Tagg': data.categories.trending_on_tagg, + "Brown '21": data.categories.brown_21, + "Brown '22": data.categories.brown_22, + "Brown '23": data.categories.brown_23, + }; + + return exploreSections; + } catch (error) { + console.log('Unable to fetch explore data'); + } +}; diff --git a/src/services/MomentCategoryService.ts b/src/services/MomentCategoryService.ts index 8bdb70d2..57e64830 100644 --- a/src/services/MomentCategoryService.ts +++ b/src/services/MomentCategoryService.ts @@ -1,12 +1,11 @@ import {Alert} from 'react-native'; -import {MomentCategoryType} from './../types/types'; import {MOMENT_CATEGORY_ENDPOINT} from '../constants'; export const loadMomentCategories: ( userId: string, token: string, -) => Promise<MomentCategoryType[]> = async (userId, token) => { - let categories: MomentCategoryType[] = []; +) => Promise<string[]> = async (userId, token) => { + let categories: string[] = []; try { const response = await fetch(MOMENT_CATEGORY_ENDPOINT + `${userId}/`, { method: 'GET', @@ -17,7 +16,7 @@ export const loadMomentCategories: ( const status = response.status; if (status === 200) { const data = await response.json(); - categories = data['categories']; + categories = data.categories; } else { console.log('Could not load categories!'); return []; @@ -30,10 +29,9 @@ export const loadMomentCategories: ( }; export const postMomentCategories: ( - categories: Array<MomentCategoryType>, + categories: string[], token: string, -) => Promise<boolean> = async (categories, token) => { - let success = false; +) => Promise<number | undefined> = async (categories, token) => { try { const response = await fetch(MOMENT_CATEGORY_ENDPOINT, { method: 'POST', @@ -44,45 +42,16 @@ export const postMomentCategories: ( body: JSON.stringify({categories}), }); const status = response.status; + const data = await response.json(); if (status === 200) { - success = true; + return data['profile_completion_stage']; } else { - Alert.alert('There was a problem creating categories!'); - console.log('Could not post categories!'); + Alert.alert('There was a problem updating categories!'); + console.log('Unable to update categories'); } } catch (err) { console.log(err); - return success; + return undefined; } - return success; -}; - -export const deleteMomentCategories: ( - categories: Array<MomentCategoryType>, - userId: string, - token: string, -) => Promise<boolean> = async (categories, userId, token) => { - let success = false; - try { - const response = await fetch(MOMENT_CATEGORY_ENDPOINT + `${userId}/`, { - method: 'DELETE', - headers: { - 'Content-Type': 'application/json', - Authorization: 'Token ' + token, - }, - body: JSON.stringify({categories}), - }); - const status = response.status; - if (status === 200) { - Alert.alert(`The category was successfully deleted!`); - success = true; - } else { - Alert.alert('There was a problem while deleteing category!'); - console.log('Could not delete category!'); - } - } catch (err) { - console.log(err); - return success; - } - return success; + return undefined; }; diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts index 96643bc3..91ecf712 100644 --- a/src/services/MomentServices.ts +++ b/src/services/MomentServices.ts @@ -2,6 +2,7 @@ import AsyncStorage from '@react-native-community/async-storage'; import {Alert} from 'react-native'; import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants'; import {MomentType} from '../types'; +import {checkImageUploadStatus} from '../utils'; //Get all comments for a moment export const getMomentComments = async ( @@ -97,6 +98,57 @@ export const getMomentCommentsCount = async ( } }; +export const postMoment: ( + fileName: string, + uri: string, + caption: string, + category: string, + userId: string, +) => Promise<number | undefined> = async ( + fileName, + uri, + caption, + category, + userId, +) => { + try { + const request = new FormData(); + //Manipulating filename to end with .jpg instead of .heic + if (fileName.endsWith('.heic') || fileName.endsWith('.HEIC')) { + fileName = fileName.split('.')[0] + '.jpg'; + } + request.append('image', { + uri: uri, + name: fileName, + type: 'image/jpg', + }); + request.append('moment', category); + request.append('user_id', userId); + request.append('captions', JSON.stringify({image: caption})); + const token = await AsyncStorage.getItem('token'); + let response = await fetch(MOMENTS_ENDPOINT, { + method: 'POST', + headers: { + 'Content-Type': 'multipart/form-data', + Authorization: 'Token ' + token, + }, + body: request, + }); + let statusCode = response.status; + let data = await response.json(); + if (statusCode === 200 && checkImageUploadStatus(data['moments'])) { + Alert.alert('The picture was uploaded successfully!'); + return data['profile_completion_stage']; + } else { + Alert.alert('An error occured while uploading. Please try again!'); + } + } catch (err) { + console.log(err); + Alert.alert('An error occured during authenticaion. Please login again!'); + } + return undefined; +}; + export const loadMoments: ( userId: string, token: string, diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 75042830..793ee44d 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -38,6 +38,7 @@ export const loadProfileInfo = async (token: string, userId: string) => { snapchat, tiktok, university_class, + profile_completion_stage, } = info; birthday = birthday && moment(birthday).format('YYYY-MM-DD'); return { @@ -49,6 +50,7 @@ export const loadProfileInfo = async (token: string, userId: string) => { snapchat, tiktok, university_class, + profile_completion_stage, }; } else { throw 'Unable to load profile data'; diff --git a/src/services/WaitlistUserService.tsx b/src/services/WaitlistUserService.tsx new file mode 100644 index 00000000..516affe3 --- /dev/null +++ b/src/services/WaitlistUserService.tsx @@ -0,0 +1,45 @@ +import {Alert} from 'react-native'; +import {WAITLIST_USER_ENDPOINT} from '../constants'; + +export const adduserToWaitlist: ( + phone_number: string, + first_name: string, + last_name: string, +) => Promise<boolean> = async (phone_number, first_name, last_name) => { + try { + console.log(phone_number, first_name, last_name); + const response = await fetch(WAITLIST_USER_ENDPOINT, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + phone_number, + first_name, + last_name, + }), + }); + const status = response.status; + const message = await response.json(); + if (status === 200) { + return true; + } else { + if (status === 409) { + Alert.alert('You are already on our waitlist / on our app'); + } else if (status === 400) { + Alert.alert('Some information needed was missing / ill-formatted'); + } else if (status === 500) { + Alert.alert( + 'Something went wrong. Sorry unable to add you to the waitlist 😔', + ); + } + console.log(message); + } + } catch (err) { + Alert.alert( + 'Something went wrong. Sorry unable to add you to the waitlist 😔', + ); + console.log(err); + } + return false; +}; diff --git a/src/services/index.ts b/src/services/index.ts index 7ea5bf5d..56cefddd 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -8,3 +8,4 @@ export * from './BlockUserService'; export * from './MomentCategoryService'; export * from './NotificationService'; export * from './FCMService'; +export * from './WaitlistUserService'; |
