aboutsummaryrefslogtreecommitdiff
path: root/src/services/NotificationService.ts
diff options
context:
space:
mode:
authorBrian Kim <brian@tagg.id>2021-06-15 12:28:32 +0900
committerBrian Kim <brian@tagg.id>2021-06-15 12:28:32 +0900
commitdb0678d647f774dcb1cd60513985d9b6fbd0e28b (patch)
tree00e62c1821d4973d214fdd47f8293749972c1925 /src/services/NotificationService.ts
parenta249f2d027c9cd5d7f20602cf79ec2265f60a54c (diff)
parent78f32c1400eff46d4c768b78fbaf672826c74285 (diff)
Merge branch 'master' of https://github.com/TaggiD-Inc/Frontend
Diffstat (limited to 'src/services/NotificationService.ts')
-rw-r--r--src/services/NotificationService.ts63
1 files changed, 62 insertions, 1 deletions
diff --git a/src/services/NotificationService.ts b/src/services/NotificationService.ts
index c5c843f5..ccaa9135 100644
--- a/src/services/NotificationService.ts
+++ b/src/services/NotificationService.ts
@@ -1,5 +1,9 @@
import AsyncStorage from '@react-native-community/async-storage';
-import {NOTIFICATIONS_ENDPOINT} from '../constants';
+import {
+ NOTIFICATIONS_ENDPOINT,
+ NOTIFICATIONS_COUNT_ENDPOINT,
+ NOTIFICATIONS_DATE,
+} from '../constants';
import {NotificationType} from '../types';
export const getNotificationsData: () => Promise<NotificationType[]> =
@@ -29,3 +33,60 @@ export const getNotificationsData: () => Promise<NotificationType[]> =
return [];
}
};
+
+export const getNotificationsUnreadCount = async () => {
+ try {
+ const token = await AsyncStorage.getItem('token');
+ const response = await fetch(NOTIFICATIONS_COUNT_ENDPOINT, {
+ method: 'GET',
+ headers: {
+ Authorization: 'Token ' + token,
+ },
+ });
+ if (response.status === 200) {
+ const data: any = await response.json();
+ const typedData: {
+ CMT?: number;
+ FRD_REQ?: number;
+ P_VIEW?: number;
+ MOM_TAG?: number;
+ } = {};
+ if (data.CMT) {
+ typedData.CMT = data.CMT;
+ }
+ if (data.FRD_REQ && data.FRD_REQ > 0) {
+ typedData.FRD_REQ = data.FRD_REQ;
+ }
+ if (data.P_VIEW && data.P_VIEW > 0) {
+ typedData.P_VIEW = data.P_VIEW;
+ }
+ if (data.MOM_TAG && data.MOM_TAG > 0) {
+ typedData.MOM_TAG = data.MOM_TAG;
+ }
+ return typedData;
+ }
+ } catch (error) {
+ console.log('Unable to fetch notifications');
+ }
+ return undefined;
+};
+
+export const setNotificationsReadDate: () => Promise<boolean> = async () => {
+ try {
+ const token = await AsyncStorage.getItem('token');
+ const response = await fetch(NOTIFICATIONS_DATE, {
+ method: 'POST',
+ headers: {
+ Authorization: 'Token ' + token,
+ },
+ });
+ if (response.status === 204) {
+ return true;
+ } else {
+ return false;
+ }
+ } catch (error) {
+ console.log('Unable to fetch notifications');
+ return false;
+ }
+};