aboutsummaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorAshm Walia <40498934+ashmgarv@users.noreply.github.com>2021-01-16 09:51:36 -0800
committerGitHub <noreply@github.com>2021-01-16 09:51:36 -0800
commit9711093bfa5810868e3cd17008bb7b3ddc7b9034 (patch)
tree6a8bb4341b1623cfc2da86af4b3b28c1fd3f8a44 /src/services
parentd85eaeb878cbbeedda860ee5809b81100c910af2 (diff)
parent30391867438bb28cbcba9fc9ee2ff6d00027fd86 (diff)
Merge branch 'master' into tma538-friend-requests
Diffstat (limited to 'src/services')
-rw-r--r--src/services/BlockUserService.ts23
-rw-r--r--src/services/MomentCategoryService.ts7
-rw-r--r--src/services/MomentServices.ts59
-rw-r--r--src/services/ReportingService.ts10
-rw-r--r--src/services/SocialLinkingService.ts12
-rw-r--r--src/services/UserFriendsServices.ts11
-rw-r--r--src/services/UserProfileService.ts68
7 files changed, 94 insertions, 96 deletions
diff --git a/src/services/BlockUserService.ts b/src/services/BlockUserService.ts
index 21e259b6..12ea0184 100644
--- a/src/services/BlockUserService.ts
+++ b/src/services/BlockUserService.ts
@@ -2,6 +2,7 @@
import {Alert} from 'react-native';
import {BLOCK_USER_ENDPOINT} from '../constants';
+import {ERROR_SOMETHING_WENT_WRONG_REFRESH} from '../constants/strings';
export const loadBlockedUsers = async (userId: string, token: string) => {
try {
@@ -44,18 +45,12 @@ export const blockOrUnblockUser = async (
return true;
} else {
console.log(await response.json());
- Alert.alert(
- 'Something went wrong! 😭',
- "Would you believe me if I told you that I don't know what happened?",
- );
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH);
return false;
}
} catch (error) {
console.log(error);
- Alert.alert(
- 'Something went wrong! 😭',
- "Would you believe me if I told you that I don't know what happened?",
- );
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH);
return false;
}
};
@@ -77,18 +72,12 @@ export const isUserBlocked = async (
if (Math.floor(response.status / 100) === 2) {
const data = await response.json();
- return data['is_blocked'];
+ return data.is_blocked;
} else {
console.log(await response.json());
- Alert.alert(
- 'Something went wrong! 😭',
- "Would you believe me if I told you that I don't know what happened?",
- );
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH);
}
} catch (error) {
- Alert.alert(
- 'Something went wrong! 😭',
- "Would you believe me if I told you that I don't know what happened?",
- );
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH);
}
};
diff --git a/src/services/MomentCategoryService.ts b/src/services/MomentCategoryService.ts
index 57e64830..bb2c5542 100644
--- a/src/services/MomentCategoryService.ts
+++ b/src/services/MomentCategoryService.ts
@@ -1,5 +1,6 @@
import {Alert} from 'react-native';
import {MOMENT_CATEGORY_ENDPOINT} from '../constants';
+import {ERROR_CATEGORY_CREATION} from '../constants/strings';
export const loadMomentCategories: (
userId: string,
@@ -44,10 +45,10 @@ export const postMomentCategories: (
const status = response.status;
const data = await response.json();
if (status === 200) {
- return data['profile_completion_stage'];
+ return data.profile_completion_stage;
} else {
- Alert.alert('There was a problem updating categories!');
- console.log('Unable to update categories');
+ Alert.alert(ERROR_CATEGORY_CREATION);
+ console.log('Could not post categories!');
}
} catch (err) {
console.log(err);
diff --git a/src/services/MomentServices.ts b/src/services/MomentServices.ts
index 91ecf712..514b674c 100644
--- a/src/services/MomentServices.ts
+++ b/src/services/MomentServices.ts
@@ -1,6 +1,16 @@
import AsyncStorage from '@react-native-community/async-storage';
import {Alert} from 'react-native';
-import {COMMENTS_ENDPOINT, MOMENTS_ENDPOINT} from '../constants';
+import RNFetchBlob from 'rn-fetch-blob';
+import {
+ COMMENTS_ENDPOINT,
+ MOMENTS_ENDPOINT,
+ MOMENT_THUMBNAIL_ENDPOINT,
+} from '../constants';
+import {
+ ERROR_FAILED_TO_COMMENT,
+ ERROR_UPLOAD,
+ SUCCESS_PIC_UPLOAD,
+} from '../constants/strings';
import {MomentType} from '../types';
import {checkImageUploadStatus} from '../utils';
@@ -48,20 +58,12 @@ export const postMomentComment = async (
},
body: request,
});
- const status = response.status;
- if (status === 200) {
- const response_data = await response.json();
- return response_data;
- } else {
- Alert.alert('Something went wrong! 😭', 'Not able to post a comment');
- return {};
+ if (response.status !== 200) {
+ throw 'server error';
}
+ return await response.json();
} catch (error) {
- Alert.alert(
- 'Something went wrong! 😭',
- 'Not able to post a comment',
- error,
- );
+ Alert.alert(ERROR_FAILED_TO_COMMENT);
return {};
}
};
@@ -136,15 +138,15 @@ export const postMoment: (
});
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'];
+ if (statusCode === 200 && checkImageUploadStatus(data.moments)) {
+ Alert.alert(SUCCESS_PIC_UPLOAD);
+ return data.profile_completion_stage;
} else {
- Alert.alert('An error occured while uploading. Please try again!');
+ Alert.alert(ERROR_UPLOAD);
}
} catch (err) {
console.log(err);
- Alert.alert('An error occured during authenticaion. Please login again!');
+ Alert.alert(ERROR_UPLOAD);
}
return undefined;
};
@@ -193,3 +195,24 @@ export const deleteMoment = async (momentId: string) => {
return false;
}
};
+
+export const loadMomentThumbnail = async (momentId: string) => {
+ try {
+ const token = await AsyncStorage.getItem('token');
+ const response = await RNFetchBlob.config({
+ fileCache: true,
+ appendExt: 'jpg',
+ }).fetch('GET', MOMENT_THUMBNAIL_ENDPOINT + `${momentId}/`, {
+ Authorization: 'Token ' + token,
+ });
+ const status = response.info().status;
+ if (status === 200) {
+ return response.path();
+ } else {
+ return undefined;
+ }
+ } catch (error) {
+ console.log(error);
+ return undefined;
+ }
+};
diff --git a/src/services/ReportingService.ts b/src/services/ReportingService.ts
index 1563d086..8c0a4bfb 100644
--- a/src/services/ReportingService.ts
+++ b/src/services/ReportingService.ts
@@ -3,6 +3,10 @@
import {REPORT_ISSUE_ENDPOINT} from '../constants';
import {Alert} from 'react-native';
import AsyncStorage from '@react-native-community/async-storage';
+import {
+ ERROR_SOMETHING_WENT_WRONG,
+ MARKED_AS_MSG,
+} from '../constants/strings';
export const sendReport = async (
moment_id: string,
@@ -25,15 +29,15 @@ export const sendReport = async (
let statusCode = response.status;
if (statusCode === 200) {
- Alert.alert('Marked as ' + message.split(' ')[2]);
+ Alert.alert(MARKED_AS_MSG(message.split(' ')[2]));
} else {
- Alert.alert('Something went wrong!', 'Please try again.');
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG);
}
if (callback) {
callback();
}
} catch (error) {
- Alert.alert('Something went wrong!', 'Please try again.');
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG);
console.log(
'Something went wrong! 😭',
'Unable able to retrieve data',
diff --git a/src/services/SocialLinkingService.ts b/src/services/SocialLinkingService.ts
index 4a01ee50..1423c8c0 100644
--- a/src/services/SocialLinkingService.ts
+++ b/src/services/SocialLinkingService.ts
@@ -12,6 +12,8 @@ import {
LINK_TWITTER_ENDPOINT,
LINK_TWITTER_OAUTH,
} from '../constants';
+import {COMING_SOON_MSG, ERROR_LINK, SUCCESS_LINK} from '../constants/strings';
+import {CategorySelection} from '../screens';
// A list of endpoint strings for all the integrated socials
export const integratedEndpoints: {[social: string]: [string, string]} = {
@@ -124,7 +126,7 @@ export const handlePressForAuthBrowser: (
) => Promise<boolean> = async (socialType: string) => {
try {
if (!(socialType in integratedEndpoints)) {
- Alert.alert('Coming soon!');
+ Alert.alert(COMING_SOON_MSG);
return false;
}
@@ -168,7 +170,7 @@ export const handlePressForAuthBrowser: (
if (!success) {
throw 'Unable to register with backend';
}
- Alert.alert(`Successfully linked ${socialType} 🎉`);
+ Alert.alert(SUCCESS_LINK(socialType));
return true;
} else if (response.type === 'cancel') {
return false;
@@ -178,14 +180,12 @@ export const handlePressForAuthBrowser: (
})
.catch((error) => {
console.log(error);
- Alert.alert(
- `Something went wrong, we can't link with ${socialType} 😔`,
- );
+ Alert.alert(ERROR_LINK(socialType));
return false;
});
} catch (error) {
console.log(error);
- Alert.alert(`Something went wrong, we can't link with ${socialType} 😔`);
+ Alert.alert(ERROR_LINK(socialType));
}
return false;
};
diff --git a/src/services/UserFriendsServices.ts b/src/services/UserFriendsServices.ts
index 18a92481..f2e15824 100644
--- a/src/services/UserFriendsServices.ts
+++ b/src/services/UserFriendsServices.ts
@@ -3,6 +3,7 @@
import {Alert} from 'react-native';
import {FriendshipStatusType} from 'src/types';
import {FRIENDS_ENDPOINT} from '../constants';
+import {ERROR_SOMETHING_WENT_WRONG_REFRESH} from '../constants/strings';
export const loadFriends = async (userId: string, token: string) => {
try {
@@ -104,18 +105,12 @@ export const declineFriendRequestService = async (
return true;
} else {
console.log(await response.json());
- Alert.alert(
- 'Something went wrong! 😭',
- "Would you believe me if I told you that I don't know what happened?",
- );
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH);
return false;
}
} catch (error) {
console.log(error);
- Alert.alert(
- 'Something went wrong! 😭',
- "Would you believe me if I told you that I don't know what happened?",
- );
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH);
return false;
}
};
diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts
index c9ec3604..75d7d367 100644
--- a/src/services/UserProfileService.ts
+++ b/src/services/UserProfileService.ts
@@ -17,6 +17,17 @@ import {
SEND_OTP_ENDPOINT,
PROFILE_PHOTO_THUMBNAIL_ENDPOINT,
} from '../constants';
+import {
+ ERROR_DOUBLE_CHECK_CONNECTION,
+ ERROR_DUP_OLD_PWD,
+ ERROR_INVALID_PWD_CODE,
+ ERROR_PWD_ACCOUNT,
+ ERROR_SOMETHING_WENT_WRONG,
+ ERROR_SOMETHING_WENT_WRONG_REFRESH,
+ ERROR_VERIFICATION_FAILED_SHORT,
+ SUCCESS_PWD_RESET,
+ SUCCESS_VERIFICATION_CODE_SENT,
+} from '../constants/strings';
export const loadProfileInfo = async (token: string, userId: string) => {
try {
@@ -60,10 +71,7 @@ export const loadProfileInfo = async (token: string, userId: string) => {
throw 'Unable to load profile data';
}
} catch (error) {
- Alert.alert(
- 'Something went wrong! 😭',
- "Would you believe me if I told you that I don't know what happened?",
- );
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH);
}
};
@@ -178,10 +186,7 @@ export const handlePasswordResetRequest = async (value: string) => {
`Please make sure that the email / username entered is registered with us. You may contact our customer support at ${TAGG_CUSTOMER_SUPPORT}`,
);
} else {
- Alert.alert(
- 'Something went wrong! 😭',
- "Would you believe me if I told you that I don't know what happened?",
- );
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH);
}
console.log(response);
@@ -189,7 +194,7 @@ export const handlePasswordResetRequest = async (value: string) => {
}
} catch (error) {
console.log(error);
- Alert.alert('Something went wrong! 😭', 'Looks like our servers are down');
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG);
return false;
}
};
@@ -215,16 +220,11 @@ export const handlePasswordCodeVerification = async (
return true;
} else {
if (status == 404) {
- Alert.alert(
- `Please make sure that the email / username entered is registered with us. You may contact our customer support at ${TAGG_CUSTOMER_SUPPORT}`,
- );
+ Alert.alert(ERROR_PWD_ACCOUNT(TAGG_CUSTOMER_SUPPORT));
} else if (status === 401) {
- Alert.alert('Looks like you have entered the wrong code');
+ Alert.alert(ERROR_INVALID_PWD_CODE);
} else {
- Alert.alert(
- 'Something went wrong! 😭',
- "Would you believe me if I told you that I don't know what happened?",
- );
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG);
}
console.log(response);
@@ -232,7 +232,7 @@ export const handlePasswordCodeVerification = async (
}
} catch (error) {
console.log(error);
- Alert.alert('Something went wrong! 😭', 'Looks like our servers are down');
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG);
return false;
}
};
@@ -252,27 +252,22 @@ export const handlePasswordReset = async (value: string, password: string) => {
});
const status = response.status;
if (status === 200) {
- Alert.alert('Your password was reset successfully');
+ Alert.alert(SUCCESS_PWD_RESET);
return true;
} else {
if (status == 404) {
- Alert.alert(
- `Please make sure that the email / username entered is registered with us. You may contact our customer support at ${TAGG_CUSTOMER_SUPPORT}`,
- );
+ Alert.alert(ERROR_PWD_ACCOUNT(TAGG_CUSTOMER_SUPPORT));
} else if (status == 406) {
- Alert.alert('You may not use an already used password');
+ Alert.alert(ERROR_DUP_OLD_PWD);
} else {
- Alert.alert(
- 'Something went wrong! 😭',
- "Would you believe me if I told you that I don't know what happened?",
- );
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH);
}
console.log(response);
return false;
}
} catch (error) {
console.log(error);
- Alert.alert('Something went wrong! 😭', 'Looks like our servers are down');
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG);
return false;
}
};
@@ -296,17 +291,11 @@ export const verifyOtp = async (phone: string, otp: string) => {
'Try again. Tap the resend code button if you need a new code.',
);
} else {
- Alert.alert(
- 'Something went wrong! 😭',
- "Would you believe me if I told you that I don't know what happened?",
- );
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG_REFRESH);
}
}
} catch (error) {
- Alert.alert(
- 'Verifiation failed 😓',
- 'Please double-check your network connection and retry.',
- );
+ Alert.alert(ERROR_VERIFICATION_FAILED_SHORT, ERROR_DOUBLE_CHECK_CONNECTION);
return {
name: 'Verification error',
description: error,
@@ -326,13 +315,10 @@ export const sendOtp = async (phone: string) => {
let status = response.status;
if (status === 200) {
- Alert.alert(
- 'New verification code sent!',
- 'Check your phone messages for your code.',
- );
+ Alert.alert(SUCCESS_VERIFICATION_CODE_SENT);
return true;
} else {
- Alert.alert('Something went wrong!');
+ Alert.alert(ERROR_SOMETHING_WENT_WRONG);
return false;
}
} catch (error) {