/
Notifications.ts
117 lines (100 loc) · 3.04 KB
/
Notifications.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { GenericID, GenericToken } from "../../common/common.types";
import TagoIOModule, { GenericModuleParams } from "../../common/TagoIOModule";
import dateParser from "../Utils/dateParser";
import { NotificationInfo, NotificationQuery } from "./notifications.types";
class Notifications extends TagoIOModule<GenericModuleParams> {
/**
* Retrieves a list with all actions from the account
* @param queryObj Search query params
*/
public async list(queryObj?: NotificationQuery): Promise<NotificationInfo[]> {
let result = await this.doRequest<NotificationInfo[]>({
path: "/notification/",
method: "GET",
params: queryObj,
});
result = result.map((data) => dateParser(data, ["created_at"]));
return result;
}
/**
* Mark notifications as read
* @param notificationIDS An array of ids or a single id
*/
public async markAsRead(notificationIDS: GenericID[] | GenericID): Promise<string> {
if (!Array.isArray(notificationIDS)) {
notificationIDS = [notificationIDS];
}
const result = await this.doRequest<string>({
path: "/notification/read",
method: "PUT",
body: {
notification_ids: notificationIDS,
},
});
return result;
}
/**
* Accept a notification
* @param notificationID Notification identification
*/
public async accept(notificationID: GenericID): Promise<string> {
const result = await this.doRequest<string>({
path: `/notification/accept/${notificationID}`,
method: "POST",
});
return result;
}
/**
* Refuse a notification
* @param notificationID Notification identification
*/
public async refuse(notificationID: GenericID): Promise<string> {
const result = await this.doRequest<string>({
path: `/notification/refuse/${notificationID}`,
method: "POST",
});
return result;
}
/**
* Remove a notification
* @param notificationID Notification identification
*/
public async remove(notificationID: GenericID): Promise<string> {
const result = await this.doRequest<string>({
path: `/notification/${notificationID}`,
method: "DELETE",
});
return result;
}
/**
* Register device Token on Push Notification Service
* @param deviceToken Device token
* @param platform Platform of device
*/
public async registerDevice(deviceToken: GenericToken, platform: "ios" | "android"): Promise<string> {
const result = await this.doRequest<string>({
path: `/notification/push/register`,
method: "POST",
body: {
device_token: deviceToken,
platform,
},
});
return result;
}
/**
* Unregister device Token on Push Notification Service
* @param deviceToken Device token
*/
public async unRegisterDevice(deviceToken: GenericToken): Promise<string> {
const result = await this.doRequest<string>({
path: `/notification/push/unregister`,
method: "POST",
body: {
device_token: deviceToken,
},
});
return result;
}
}
export default Notifications;