playov2-js-utilities 0.2.9 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +2 -1
- package/lib/notification-templates.js +18 -18
- package/lib/notification.config.js +42 -98
- package/lib/request.js +132 -0
- package/lib/util.js +4 -1
- package/package.json +5 -2
- package/test.js +8 -0
package/lib/index.js
CHANGED
|
@@ -5,5 +5,6 @@ module.exports = {
|
|
|
5
5
|
Constants : require('./constants'),
|
|
6
6
|
playoUtils : require('./util'),
|
|
7
7
|
NotificationTemplates : require('./notification-templates'),
|
|
8
|
-
NotificationConfig: require('./notification.config')
|
|
8
|
+
NotificationConfig: require('./notification.config'),
|
|
9
|
+
httpRequest: require('./request')
|
|
9
10
|
};
|
|
@@ -39,10 +39,10 @@ const host_response_to_query = {
|
|
|
39
39
|
* @param {String} date - Activity's date
|
|
40
40
|
*/
|
|
41
41
|
const activity_join_request = {
|
|
42
|
-
heading: '
|
|
42
|
+
heading: 'New game request! 🙌',
|
|
43
43
|
text: '{{user_first_name}} has requested to join your {{sport_name}} game happening on {{date}}.',
|
|
44
44
|
additional_message_text: {
|
|
45
|
-
text: 'They have a message for you! Tap to read',
|
|
45
|
+
text: 'They have a message for you! Tap to read.',
|
|
46
46
|
default: 'Let them know if you\'re game.'
|
|
47
47
|
},
|
|
48
48
|
buttons: [],
|
|
@@ -58,7 +58,7 @@ const activity_join_request = {
|
|
|
58
58
|
* @param {String} date - Activity's date
|
|
59
59
|
*/
|
|
60
60
|
const activity_request_accepted = {
|
|
61
|
-
heading: '
|
|
61
|
+
heading: 'Request accepted! 🥳',
|
|
62
62
|
text: 'You\'re on for the {{sport_name}} game on {{date}}. You can now chat with your game squad.',
|
|
63
63
|
buttons: [],
|
|
64
64
|
notificationId: notificationIds.ACTIVITY_REQUEST_RESPONSE
|
|
@@ -73,11 +73,11 @@ const activity_request_accepted = {
|
|
|
73
73
|
* @param {String} date - Activity's date
|
|
74
74
|
*/
|
|
75
75
|
const activity_request_declined = {
|
|
76
|
-
heading: '
|
|
76
|
+
heading: 'Request declined. 😟',
|
|
77
77
|
text: '{{host_first_name}} declined your request to join the {{sport_name}} game on {{date}}.',
|
|
78
78
|
additional_message_text: {
|
|
79
|
-
text: 'They have a message for you! Tap to read',
|
|
80
|
-
default: 'No worries, other games are waiting for you
|
|
79
|
+
text: 'They have a message for you! Tap to read.',
|
|
80
|
+
default: 'No worries, other games are waiting for you! Join them now. 😀'
|
|
81
81
|
},
|
|
82
82
|
buttons: [],
|
|
83
83
|
notificationId: notificationIds.HOST_RETIRED
|
|
@@ -92,7 +92,7 @@ const activity_request_declined = {
|
|
|
92
92
|
* @param {String} date - Activity's date
|
|
93
93
|
*/
|
|
94
94
|
const user_invited_by_host = {
|
|
95
|
-
heading: '
|
|
95
|
+
heading: 'New game invite! 📩',
|
|
96
96
|
text: '{{host_first_name}} has invited you to the {{sport_name}} game on {{date}}. Are you game? 💪',
|
|
97
97
|
buttons: [],
|
|
98
98
|
notificationId: notificationIds.ACTIVITY_INVITATION
|
|
@@ -107,8 +107,8 @@ const user_invited_by_host = {
|
|
|
107
107
|
* @param {String} date - Activity's date
|
|
108
108
|
*/
|
|
109
109
|
const user_accepted_invite = {
|
|
110
|
-
heading: '
|
|
111
|
-
text: '{{user_first_name}} has accepted your
|
|
110
|
+
heading: 'Game invite accepted! 🤝',
|
|
111
|
+
text: '{{user_first_name}} has accepted your invite for the {{sport_name}} game on {{date}}.',
|
|
112
112
|
buttons: [],
|
|
113
113
|
notificationId: notificationIds.ACTIVITY_INVITATION_RESPONSE
|
|
114
114
|
};
|
|
@@ -122,11 +122,11 @@ const user_accepted_invite = {
|
|
|
122
122
|
* @param {String} date - Activity's date
|
|
123
123
|
*/
|
|
124
124
|
const user_declined_invite = {
|
|
125
|
-
heading: '
|
|
126
|
-
text: '{{user_first_name}} has declined your
|
|
125
|
+
heading: 'Game invite declined. 😟',
|
|
126
|
+
text: '{{user_first_name}} has declined your invite for the {{sport_name}} game on {{date}}.',
|
|
127
127
|
additional_message_text: {
|
|
128
|
-
text: 'They have a message for you! Tap to read',
|
|
129
|
-
default: ''
|
|
128
|
+
text: 'They have a message for you! Tap to read.',
|
|
129
|
+
default: 'Tap to invite other players.'
|
|
130
130
|
},
|
|
131
131
|
buttons: [],
|
|
132
132
|
notificationId: notificationIds.HOST_RETIRED
|
|
@@ -141,10 +141,10 @@ const user_declined_invite = {
|
|
|
141
141
|
* @param {String} date - Activity's date
|
|
142
142
|
*/
|
|
143
143
|
const host_revoked_invite = {
|
|
144
|
-
heading: '
|
|
144
|
+
heading: 'Game invite cancelled 😕',
|
|
145
145
|
text: '{{host_first_name}} has cancelled your invitation to the {{sport_name}} game on {{date}}.',
|
|
146
146
|
additional_message_text: {
|
|
147
|
-
text: 'They have a message for you! Tap to read',
|
|
147
|
+
text: 'They have a message for you! Tap to read.',
|
|
148
148
|
default: 'But, you can always join another game!'
|
|
149
149
|
},
|
|
150
150
|
buttons: [],
|
|
@@ -160,7 +160,7 @@ const host_revoked_invite = {
|
|
|
160
160
|
* @param {String} date - Activity's date
|
|
161
161
|
*/
|
|
162
162
|
const host_retired_user = {
|
|
163
|
-
heading: 'You have been made to retire
|
|
163
|
+
heading: 'You have been made to retire.😕',
|
|
164
164
|
text: 'You are no longer a part of {{sport_name}} game on {{date}}.',
|
|
165
165
|
additional_message_text: {
|
|
166
166
|
text: '{{host_first_name}} has a message for you! Tap to read',
|
|
@@ -182,8 +182,8 @@ const user_left_game = {
|
|
|
182
182
|
heading: 'Player has left the game.',
|
|
183
183
|
text: '{{user_first_name}} has left {{date}}\'s {{sport_name}} game.',
|
|
184
184
|
additional_message_text: {
|
|
185
|
-
text: '
|
|
186
|
-
default: ''
|
|
185
|
+
text: 'They have a message for you! Tap to read.',
|
|
186
|
+
default: 'Tap to invite other players.'
|
|
187
187
|
},
|
|
188
188
|
buttons: [],
|
|
189
189
|
notificationId: notificationIds.HOST_RETIRED
|
|
@@ -20,29 +20,32 @@ const notificationChannels = {
|
|
|
20
20
|
'group_updates': '9e023a20-deab-4bc4-bd33-08a8d9316322' // done - 3 notifications tagged
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
const notificationButtons = {
|
|
24
|
-
[notificationIds.ACTIVITY_NOTIFY_PUSH]: []
|
|
25
|
-
};
|
|
26
|
-
|
|
27
23
|
// ------------------------------------------ Exported (public) -----------------------------------------//
|
|
28
24
|
|
|
29
25
|
const notificationIds = {
|
|
30
|
-
ACTIVITY_NOTIFY_PUSH: 'activity-notify-push',
|
|
31
|
-
ACTIVITY_NOTIFY_DRAWER: 'activity-notify-drawer',
|
|
26
|
+
ACTIVITY_NOTIFY_PUSH: 'activity-notify-push', // > DEPRECATED
|
|
27
|
+
ACTIVITY_NOTIFY_DRAWER: 'activity-notify-drawer', // > DEPRECATED
|
|
28
|
+
ACTIVITY_NOTIFY: 'activity-notify',
|
|
32
29
|
GROUP_INVITATION: 'group-invitation',
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
GROUP_INVITATION_RESPONSE: 'group-invitation-response',
|
|
31
|
+
GROUP_INVITATION_RESPONSE_PUSH: 'group-invitation-response-push', // > DEPRECATED
|
|
32
|
+
GROUP_INVITATION_RESPONSE_DRAWER: 'group-invitation-response-drawer', // > DEPRECATED
|
|
33
|
+
GROUP_REQUEST_PUSH: 'group-request-push', // > DEPRECATED
|
|
34
|
+
GROUP_REQUEST_DRAWER: 'group-request-drawer', // > DEPRECATED
|
|
35
|
+
GROUP_REQUEST: 'group-request',
|
|
37
36
|
GROUP_REQUEST_RESPONSE: 'group-request-response',
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
GROUP_NAME: 'group-name',
|
|
38
|
+
GROUP_NAME_PUSH: 'group-name-push', // > DEPRECATED
|
|
39
|
+
GROUP_NAME_DRAWER: 'group-name-drawer', // > DEPRECATED
|
|
40
|
+
ADMIN_STATUS: 'admin-status',
|
|
41
|
+
ADMIN_STATUS_PUSH: 'admin-status-push', // > DEPRECATED
|
|
42
|
+
ADMIN_STATUS_DRAWER: 'admin-status-drawer',// > DEPRECATED
|
|
43
|
+
NEW_MESSAGE_PUSH: 'new-message-push', // > DEPRECATED
|
|
44
|
+
NEW_MESSAGE_DRAWER: 'new-message-drawer', // > DEPRECATED
|
|
45
|
+
NEW_MESSAGE: 'new-message',
|
|
46
|
+
NEW_COMMENT_PUSH: 'new-comment-push', // > DEPRECATED
|
|
47
|
+
NEW_COMMENT_DRAWER: 'new-comment-drawer', // > DEPRECATED
|
|
48
|
+
NEW_COMMENT: 'new-comment',
|
|
46
49
|
ACTIVITY_INVITATION: 'activity-invitation',
|
|
47
50
|
ACTIVITY_INVITATION_RESPONSE: 'activity-invitation-response',
|
|
48
51
|
ACTIVITY_REQUEST: 'activity-request',
|
|
@@ -81,23 +84,14 @@ const notificationIds = {
|
|
|
81
84
|
// TODO - Check targets against current value
|
|
82
85
|
|
|
83
86
|
const config = {
|
|
84
|
-
[notificationIds.
|
|
85
|
-
category: notificationCategories,
|
|
86
|
-
target: "group",
|
|
87
|
-
path: "timeline",
|
|
88
|
-
title: "Group Update",
|
|
89
|
-
type: ["push"],
|
|
90
|
-
buttons: [],
|
|
91
|
-
android_channel_id: ''
|
|
92
|
-
},
|
|
93
|
-
[notificationIds.ACTIVITY_NOTIFY_DRAWER]: {
|
|
87
|
+
[notificationIds.ACTIVITY_NOTIFY]: {
|
|
94
88
|
category: notificationCategories.GROUP,
|
|
95
89
|
target: "group",
|
|
96
90
|
path: "timeline",
|
|
97
91
|
title: "Group Update",
|
|
98
|
-
type: ["drawer"],
|
|
92
|
+
type: ["drawer", "push"],
|
|
99
93
|
buttons: [],
|
|
100
|
-
android_channel_id:
|
|
94
|
+
android_channel_id: notificationChannels.activity_suggestions
|
|
101
95
|
},
|
|
102
96
|
[notificationIds.GROUP_INVITATION]: {
|
|
103
97
|
category: notificationCategories.GROUP,
|
|
@@ -108,39 +102,21 @@ const config = {
|
|
|
108
102
|
buttons: [],
|
|
109
103
|
android_channel_id: notificationChannels.groups_manage_requests
|
|
110
104
|
},
|
|
111
|
-
[notificationIds.
|
|
112
|
-
category: notificationCategories.GROUP,
|
|
113
|
-
target: "group",
|
|
114
|
-
path: "manage",
|
|
115
|
-
title: "Group Update",
|
|
116
|
-
type: ["push"],
|
|
117
|
-
buttons: [],
|
|
118
|
-
android_channel_id: notificationChannels.groups_manage_requests
|
|
119
|
-
},
|
|
120
|
-
[notificationIds.GROUP_INVITATION_RESPONSE_DRAWER]: {
|
|
121
|
-
category: notificationCategories.GROUP,
|
|
122
|
-
target: "group",
|
|
123
|
-
path: "manage",
|
|
124
|
-
title: "Group Update",
|
|
125
|
-
type: ["drawer"],
|
|
126
|
-
buttons: [],
|
|
127
|
-
android_channel_id: notificationChannels.groups_manage_requests
|
|
128
|
-
},
|
|
129
|
-
[notificationIds.GROUP_REQUEST_PUSH]: {
|
|
105
|
+
[notificationIds.GROUP_INVITATION_RESPONSE]: {
|
|
130
106
|
category: notificationCategories.GROUP,
|
|
131
107
|
target: "group",
|
|
132
108
|
path: "manage",
|
|
133
109
|
title: "Group Update",
|
|
134
|
-
type: ["push"],
|
|
110
|
+
type: ["push", "drawer"],
|
|
135
111
|
buttons: [],
|
|
136
112
|
android_channel_id: notificationChannels.groups_manage_requests
|
|
137
113
|
},
|
|
138
|
-
[notificationIds.
|
|
114
|
+
[notificationIds.GROUP_REQUEST]: {
|
|
139
115
|
category: notificationCategories.GROUP,
|
|
140
116
|
target: "group",
|
|
141
117
|
path: "manage",
|
|
142
118
|
title: "Group Update",
|
|
143
|
-
type: ["drawer"],
|
|
119
|
+
type: ["push", "drawer"],
|
|
144
120
|
buttons: [],
|
|
145
121
|
android_channel_id: notificationChannels.groups_manage_requests
|
|
146
122
|
},
|
|
@@ -153,77 +129,41 @@ const config = {
|
|
|
153
129
|
buttons: [],
|
|
154
130
|
android_channel_id: notificationChannels.groups_manage_requests
|
|
155
131
|
},
|
|
156
|
-
[notificationIds.
|
|
132
|
+
[notificationIds.GROUP_NAME]: {
|
|
157
133
|
category: notificationCategories.GROUP,
|
|
158
134
|
target: "group",
|
|
159
135
|
path: "manage",
|
|
160
136
|
title: "Group Update",
|
|
161
|
-
type: ["push"],
|
|
162
|
-
buttons: [],
|
|
163
|
-
android_channel_id: notificationChannels.group_updates
|
|
164
|
-
},
|
|
165
|
-
[notificationIds.GROUP_NAME_DRAWER]: {
|
|
166
|
-
category: notificationCategories.GROUP,
|
|
167
|
-
target: "group",
|
|
168
|
-
path: "manage",
|
|
169
|
-
title: "Group Update",
|
|
170
|
-
type: ["drawer"],
|
|
137
|
+
type: ["push", "drawer"],
|
|
171
138
|
buttons: [],
|
|
172
139
|
android_channel_id: notificationChannels.group_updates
|
|
173
140
|
},
|
|
174
|
-
[notificationIds.
|
|
141
|
+
[notificationIds.ADMIN_STATUS]: {
|
|
175
142
|
category: notificationCategories.GROUP,
|
|
176
143
|
target: "group",
|
|
177
144
|
path: "manage",
|
|
178
145
|
title: "Group Update",
|
|
179
|
-
type: ["push"],
|
|
146
|
+
type: ["drawer", "push"],
|
|
180
147
|
buttons: [],
|
|
181
148
|
android_channel_id: notificationChannels.group_updates
|
|
182
149
|
},
|
|
183
|
-
[notificationIds.
|
|
184
|
-
category: notificationCategories.GROUP,
|
|
185
|
-
target: "group",
|
|
186
|
-
path: "manage",
|
|
187
|
-
title: "Group Update",
|
|
188
|
-
type: ["drawer"],
|
|
189
|
-
buttons: [],
|
|
190
|
-
android_channel_id: ''
|
|
191
|
-
},
|
|
192
|
-
[notificationIds.NEW_MESSAGE_PUSH]: {
|
|
150
|
+
[notificationIds.NEW_MESSAGE]: {
|
|
193
151
|
category: notificationCategories.GROUP,
|
|
194
152
|
target: "group",
|
|
195
153
|
path: "board",
|
|
196
154
|
title: "Group Update",
|
|
197
|
-
type: ["push"],
|
|
155
|
+
type: ["push", "drawer"],
|
|
198
156
|
buttons: [],
|
|
199
|
-
android_channel_id:
|
|
157
|
+
android_channel_id: notificationChannels.group_updates
|
|
200
158
|
},
|
|
201
|
-
[notificationIds.
|
|
159
|
+
[notificationIds.NEW_COMMENT]: {
|
|
202
160
|
category: notificationCategories.GROUP,
|
|
203
161
|
target: "group",
|
|
204
162
|
path: "board",
|
|
205
163
|
title: "Group Update",
|
|
206
|
-
type: ["drawer"],
|
|
164
|
+
type: ["drawer","push"],
|
|
207
165
|
buttons: [],
|
|
208
|
-
android_channel_id:
|
|
209
|
-
},
|
|
210
|
-
[notificationIds.NEW_COMMENT_PUSH]: {
|
|
211
|
-
category: notificationCategories.GROUP,
|
|
212
|
-
target: "group",
|
|
213
|
-
path: "message",
|
|
214
|
-
title: "Group Update",
|
|
215
|
-
type: ["push"],
|
|
216
|
-
buttons: [],
|
|
217
|
-
android_channel_id: ''
|
|
218
|
-
},
|
|
219
|
-
[notificationIds.NEW_COMMENT_DRAWER]: {
|
|
220
|
-
category: notificationCategories.GROUP,
|
|
221
|
-
target: "group",
|
|
222
|
-
path: "message",
|
|
223
|
-
title: "Group Update",
|
|
224
|
-
type: ["drawer"],
|
|
225
|
-
buttons: [],
|
|
226
|
-
android_channel_id: ''
|
|
166
|
+
android_channel_id: notificationChannels.group_updates
|
|
227
167
|
},
|
|
228
168
|
[notificationIds.ACTIVITY_INVITATION]: {
|
|
229
169
|
category: notificationCategories.ACTIVITY,
|
|
@@ -495,4 +435,8 @@ const config = {
|
|
|
495
435
|
}
|
|
496
436
|
};
|
|
497
437
|
|
|
438
|
+
const notificationButtons = {
|
|
439
|
+
[notificationIds.ACTIVITY_NOTIFY_PUSH]: []
|
|
440
|
+
};
|
|
441
|
+
|
|
498
442
|
module.exports = { config, notificationIds };
|
package/lib/request.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const Axios = require('axios');
|
|
2
|
+
const TIMEOUT_DURATION = 10 * 1000 // milliseconds, used as default
|
|
3
|
+
const PLAYO_LOGGER = require("@playo/logger");
|
|
4
|
+
|
|
5
|
+
const LOGGER = new PLAYO_LOGGER("playo-http-request-handler");
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This function assumes the external api being called gives response,
|
|
9
|
+
* following same structure as being used in playo currently for showing success/failure , i.e. -
|
|
10
|
+
* for successful http request, { requestStatus : 1 } & http failure/ error would be recorded otherwise
|
|
11
|
+
* the responses for external services should be logged for requestId tracing , and analytics purpose later on
|
|
12
|
+
* @param {*} resp
|
|
13
|
+
*/
|
|
14
|
+
const playoResponseHandler = (resp, requestId) => {
|
|
15
|
+
const { status, data, config } = resp;
|
|
16
|
+
const { url } = config;
|
|
17
|
+
if (status === 200) {
|
|
18
|
+
const { requestStatus } = data;
|
|
19
|
+
LOGGER.info(requestId, data, `Api call to url to ${url} succeeded with status ${status}`);
|
|
20
|
+
return ({ requestStatus, data });
|
|
21
|
+
} else {
|
|
22
|
+
LOGGER.error(requestId, data, `Api call to url to ${url} failed with status : ${status}`);
|
|
23
|
+
return Promise.reject({ requestStatus: 0, data });
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Makes a get http request - throws error to be handled by calling function
|
|
29
|
+
* @param {String} url
|
|
30
|
+
* @param {Object} headers
|
|
31
|
+
* @param {Object} query
|
|
32
|
+
* @param {String} requestId
|
|
33
|
+
* @param {Boolean} shouldTimeOut - Defaults to false
|
|
34
|
+
* @param {Number} timeout - in seconds, Defaults to 10 seconds
|
|
35
|
+
* @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
|
|
36
|
+
*/
|
|
37
|
+
const get = async (url, headers = {}, query = {}, requestId = '', responseHandler = playoResponseHandler, shouldTimeOut = false, timeout = TIMEOUT_DURATION) => {
|
|
38
|
+
try {
|
|
39
|
+
if (!shouldTimeOut) {
|
|
40
|
+
timeout = 0; // no timeout
|
|
41
|
+
}
|
|
42
|
+
const resp = await Axios.get(url, { headers, params: query, timeout });
|
|
43
|
+
return responseHandler(resp, requestId);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
LOGGER.error(requestId, error, `Api call to url to ${url} failed due to ${error.message}`);
|
|
46
|
+
return Promise.reject(error);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Makes a POST http request - throws error to be handled by calling function
|
|
52
|
+
* @param {String} url
|
|
53
|
+
* @param {Object} headers
|
|
54
|
+
* @param {Object} query
|
|
55
|
+
* @param {Object} body
|
|
56
|
+
* @param {String} requestId
|
|
57
|
+
* @param {Boolean} shouldTimeOut - Defaults to false
|
|
58
|
+
* @param {Number} timeout - in seconds, Defaults to 10 seconds
|
|
59
|
+
* @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
|
|
60
|
+
*/
|
|
61
|
+
const post = async (url, headers = {}, query = {}, body = {}, requestId = '', responseHandler = playoResponseHandler, shouldTimeOut = false, timeout = TIMEOUT_DURATION) => {
|
|
62
|
+
try {
|
|
63
|
+
if (!shouldTimeOut) {
|
|
64
|
+
timeout = 0; // no timeout
|
|
65
|
+
}
|
|
66
|
+
const options = { headers, query, timeout };
|
|
67
|
+
const resp = await Axios.post(url, body, options);
|
|
68
|
+
return responseHandler(resp, requestId);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
LOGGER.error(requestId, err, `Api call to url to ${url} failed due to ${err.message}`);
|
|
71
|
+
return Promise.reject(err);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Makes a PUT http request - throws error to be handled by calling function
|
|
77
|
+
* @param {String} url
|
|
78
|
+
* @param {Object} headers
|
|
79
|
+
* @param {Object} query
|
|
80
|
+
* @param {Object} body
|
|
81
|
+
* @param {String} requestId
|
|
82
|
+
* @param {Boolean} shouldTimeOut - Defaults to false
|
|
83
|
+
* @param {Number} timeout - in seconds, Defaults to 10 seconds
|
|
84
|
+
* @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
|
|
85
|
+
*/
|
|
86
|
+
const put = async (url, headers = {}, query = {}, body = {}, requestId = '', responseHandler = playoResponseHandler, shouldTimeOut = false, timeout = TIMEOUT_DURATION) => {
|
|
87
|
+
try {
|
|
88
|
+
if (!shouldTimeOut) {
|
|
89
|
+
timeout = 0; // no timeout
|
|
90
|
+
}
|
|
91
|
+
const options = { headers, query, timeout };
|
|
92
|
+
const resp = await Axios.put(url, body, options);
|
|
93
|
+
|
|
94
|
+
return responseHandler(resp, requestId);
|
|
95
|
+
} catch (error) {
|
|
96
|
+
LOGGER.error(requestId, error, `Api call to url to ${url} failed due to ${error.message}`);
|
|
97
|
+
return Promise.reject(error);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Makes a DELETE http request - throws error to be handled by calling function
|
|
103
|
+
* @param {String} url
|
|
104
|
+
* @param {Object} headers
|
|
105
|
+
* @param {Object} query
|
|
106
|
+
* @param {Object} body
|
|
107
|
+
* @param {String} requestId
|
|
108
|
+
* @param {Boolean} shouldTimeOut - Defaults to false
|
|
109
|
+
* @param {Number} timeout - in seconds, Defaults to 10 seconds
|
|
110
|
+
* @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
|
|
111
|
+
*/
|
|
112
|
+
const remove = async (url, headers = {}, query = {}, body, requestId = '', responseHandler = playoResponseHandler, shouldTimeOut = false, timeout = TIMEOUT_DURATION) => {
|
|
113
|
+
try {
|
|
114
|
+
if (!shouldTimeOut) {
|
|
115
|
+
timeout = 0; // no timeout
|
|
116
|
+
}
|
|
117
|
+
const options = { headers, params: query, data: body, timeout };
|
|
118
|
+
const resp = await Axios.delete(url, options);
|
|
119
|
+
return responseHandler(resp, requestId);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
LOGGER.error(requestId, error, `Api call to url to ${url} failed due to ${error.message}`);
|
|
122
|
+
return Promise.reject(error);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
module.exports = {
|
|
128
|
+
get,
|
|
129
|
+
post,
|
|
130
|
+
put,
|
|
131
|
+
remove
|
|
132
|
+
}
|
package/lib/util.js
CHANGED
|
@@ -70,6 +70,9 @@ const getRecentRatingDictOfPals = (postActivityDocs) => {
|
|
|
70
70
|
// pals array contains ratings object as per given by other playpals for a particular activity, check schema for further details
|
|
71
71
|
const { pals = [] } = postActivityDoc;
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Description for code below we are try to get a dictionary of latest non-zero rating the user has received to be processed later
|
|
75
|
+
*/
|
|
73
76
|
if (Array.isArray(pals)) {
|
|
74
77
|
pals.forEach((palRating) => {
|
|
75
78
|
const { palId = '', rating = 0, timestamp } = palRating;
|
|
@@ -78,7 +81,7 @@ const getRecentRatingDictOfPals = (postActivityDocs) => {
|
|
|
78
81
|
rating: rating,
|
|
79
82
|
timestamp: timestamp
|
|
80
83
|
}
|
|
81
|
-
} else if (palRatingDict[palId] && timestamp >= palRatingDict[palId]["timestamp"]) {
|
|
84
|
+
} else if (palRatingDict[palId] && timestamp >= palRatingDict[palId]["timestamp"] && rating > 0) {
|
|
82
85
|
// If user received any rating more recent then consider that instead
|
|
83
86
|
palRatingDict[palId]["rating"] = rating;
|
|
84
87
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "playov2-js-utilities",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Private package for JS utility functions",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,9 +16,12 @@
|
|
|
16
16
|
"author": "Saurabh Agrawal",
|
|
17
17
|
"license": "ISC",
|
|
18
18
|
"homepage": "https://bitbucket.org/techmash/playov2-js-utilities#readme",
|
|
19
|
-
|
|
20
19
|
"devDependencies": {
|
|
21
20
|
"faker": "^5.5.3",
|
|
22
21
|
"jest": "^27.1.0"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@playo/logger": "^0.9.18",
|
|
25
|
+
"axios": "^0.24.0"
|
|
23
26
|
}
|
|
24
27
|
}
|
package/test.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const data = [{"_id":"619b64773f930c6f90778f94","location":"Indiranagar","hostId":"1b7887d3-8255-409b-9efe-89b64b701862","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":false,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"9a8942e0-9778-4c43-befd-c8f7de4d3985","sportId":"SP5","date":"2021-11-22T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"firstRatedOn":"2021-11-22T09:36:20.000Z","isRemoved":false,"userPresent":null,"palId":"1b7887d3-8255-409b-9efe-89b64b701862","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2021-11-22T09:36:20.000Z"}],"createdTS":"2021-11-22T09:35:51.013Z","modTS":"2021-11-22T09:36:20.095Z","__v":0},{"_id":"619b6c5b8fff1950a20adae2","location":"Jayanagar, Bengaluru","hostId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"5161229a-e82d-498a-beed-8e2bc50bcaf7","sportId":"SP5","date":"2021-11-22T00:00:00.000Z","timing":1,"pals":[{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-11-22T10:09:31.719Z"},{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"1b7887d3-8255-409b-9efe-89b64b701862","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-11-22T10:24:02.000Z"}],"createdTS":"2021-11-22T10:09:31.719Z","modTS":"2021-11-22T11:26:49.742Z","__v":0},{"_id":"619b85378fff1950a20adaf0","location":"Indiranagar","hostId":"1b7887d3-8255-409b-9efe-89b64b701862","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"00f9ff64-214c-470d-b7fb-760a6a3af8e0","sportId":"SP5","date":"2021-11-22T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"1b7887d3-8255-409b-9efe-89b64b701862","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2021-11-22T12:00:26.000Z"},{"noshow":false,"noshowSwitch":false,"rating":3,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2021-11-22T12:02:57.000Z"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"88d8e6ed-207a-4b98-ace7-73a7bd6bc900","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-11-22T11:55:35.344Z"}],"createdTS":"2021-11-22T11:55:35.345Z","modTS":"2021-11-22T12:09:46.320Z","__v":0},{"_id":"612502919345581b9bd0246b","location":"Maker, Bihar, India","hostId":"65a91715-396c-4049-a952-2cc56a100f4a","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"4dbf9ef5-c3a7-4542-8a6d-9241a02b4965","sportId":"SP5","date":"2021-08-24T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":true,"isRemoved":false,"userPresent":null,"palId":"65a91715-396c-4049-a952-2cc56a100f4a","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-08-24T14:30:41.439Z"},{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-08-24T14:31:01.000Z"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":true,"userPresent":null,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-08-24T14:30:41.439Z","userName":"playo user"}],"createdTS":"2021-08-24T14:30:41.439Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"6038ffa7cc84a76c119f1333","location":"Maker, Bihar","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"a1c4ae44-2667-42f9-ac37-dd173b2fa3b1","sportId":"SP5","date":"2021-02-26T00:00:00.000Z","startTime":"2021-02-26T14:00:00.916Z","endTime":"2021-02-26T14:30:00.916Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-02-26T14:03:19.486Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":true,"palId":"54fe8420-dae7-4bb2-aa08-320b7dc40794","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-02-26T14:03:19.485Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"isRemoved":false,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-02-26T14:04:25.000Z"}],"createdTS":"2021-02-26T14:03:19.486Z","modTS":"2021-11-18T07:09:26.826Z","__v":0},{"_id":"6015a56cc8be9072376d7f0d","location":"Maker, Bihar","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"00879220-bd24-4635-add2-ce4b997be0fe","sportId":"SP5","date":"2021-01-30T00:00:00.000Z","timing":3,"pals":[{"noshow":false,"noshowSwitch":false,"rating":4,"newPlaypal":false,"firstRatedOn":"2021-02-02T13:36:32.000Z","isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2021-02-02T13:36:32.000Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"firstRatedOn":null,"isRemoved":false,"palId":"da0df07e-5cdb-4cbc-9b47-a31812aa3be7","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-01-30T18:29:00.257Z"},{"noshow":false,"noshowSwitch":false,"rating":2,"newPlaypal":false,"firstRatedOn":"2021-02-02T14:00:09.000Z","isRemoved":true,"palId":"54fe8420-dae7-4bb2-aa08-320b7dc40794","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-02-02T14:00:09.000Z","userName":"playo user"}],"createdTS":"2021-01-30T18:29:00.258Z","modTS":"2021-11-18T07:09:26.826Z","__v":0},{"_id":"5f9c32a49739b90adc3579b0","location":"BTM Layout","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"d3e71dc8-1aa6-4e32-b10d-50d4b084df31","sportId":"SP5","date":"2020-10-30T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":1,"newPlaypal":false,"firstRatedOn":"2021-02-03T08:19:09.000Z","isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":0},{"reputationId":1,"value":0},{"reputationId":2,"value":0}],"timestamp":"2021-02-03T08:20:04.000Z","userName":"playo user"}],"createdTS":"2020-10-30T15:35:00.552Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5f9c32a49739b90adc3579b2","location":"BTM Layout, Bengaluru","hostId":"54fe8420-dae7-4bb2-aa08-320b7dc40794","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"1d624dfb-38aa-423d-b587-868740d9b5b7","sportId":"SP5","date":"2020-10-30T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":3,"newPlaypal":false,"isRemoved":true,"palId":"54fe8420-dae7-4bb2-aa08-320b7dc40794","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-02-03T08:19:52.000Z","firstRatedOn":"2021-02-03T08:19:52.000Z","userName":"playo user"}],"createdTS":"2020-10-30T15:35:00.562Z","modTS":"2021-11-18T07:09:26.826Z","__v":0},{"_id":"5f6e0e24b61c8b4468f21759","location":"Qatar - Dubai - United Arab Emirates","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"26927e38-56de-4b2e-8c57-dd01abe8109f","sportId":"SP5","date":"2020-09-25T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-09-27T12:28:45.000Z","userName":"playo user"}]
|
|
2
|
+
,"createdTS":"2020-09-25T15:35:00.313Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5efaf808a4b1425a240c2a85","location":"Dribble Arena, Magrath Road","hostId":"2537e208-35f2-4b38-ac65-081ab1a249be","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"7176dd7c-8424-43b8-95f4-a21148141bae","sportId":"SP5","date":"2020-06-30T00:00:00.000Z","startTime":"2020-06-30T07:30:00.000Z","endTime":"2020-06-30T08:30:00.000Z","timing":1,"pals":[{"noshow":false,"noshowSwitch":false,"rating":3,"newPlaypal":false,"firstRatedOn":"2020-07-02T12:52:32.000Z","isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":0},{"reputationId":2,"value":1}],"timestamp":"2020-07-02T12:57:53.000Z","userName":"playo user"}],"createdTS":"2020-06-30T08:30:00.348Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5ee10a8a9a0d8d7d0c611715","location":"Dribble Arena Test,Indiranagar","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"17266219-0b62-4edc-acd3-5775379e7143","sportId":"SP5","date":"2020-06-10T00:00:00.000Z","startTime":"2020-06-10T15:30:00.000Z","endTime":"2020-06-10T16:30:00.000Z","timing":3,"pals":[{"noshow":false,"noshowSwitch":false,"rating":4,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-11T04:30:06.000Z","userName":"playo user"}],"createdTS":"2020-06-10T16:30:02.175Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5ede59780b1f934f45df242a","location":"Dribble Arena Test,Indiranagar","hostId":"2537e208-35f2-4b38-ac65-081ab1a249be","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"dcc3a75f-2841-4317-b4c2-88159285027f","sportId":"SP5","date":"2020-06-08T00:00:00.000Z","startTime":"2020-06-08T11:30:00.000Z","endTime":"2020-06-08T12:30:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-09T03:53:07.000Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":false,"palId":"861c3457-c99c-4dbb-ab2c-5eb447eaf9fe","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-08T15:30:00.261Z"}],"createdTS":"2020-06-08T15:30:00.262Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5edbdf7cf164da32c113b35b","location":"Game Theory - 100 feet road - Indiranagar, 100 Feet Road","hostId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"ee87f1fb-31b0-4640-b718-5b2557c9104f","sportId":"SP5","date":"2020-06-06T00:00:00.000Z","timing":3,"pals":[{"noshow":false,"noshowSwitch":false,"rating":4,"newPlaypal":true,"isRemoved":false,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2020-06-08T17:01:37.000Z"}],"createdTS":"2020-06-06T18:25:00.148Z","modTS":"2020-06-08T18:25:00.227Z","__v":0},{"_id":"5edbdf7df164da32c113b362","location":"BTM Layout","hostId":"2537e208-35f2-4b38-ac65-081ab1a249be","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"e70f154d-6663-401f-922b-a98f737cf0e4","sportId":"SP5","date":"2020-06-06T00:00:00.000Z","timing":3,"pals":[{"noshow":true,"noshowSwitch":false,"rating":4,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-09T03:54:28.000Z","firstRatedOn":"2020-06-09T03:54:28.000Z","userName":"playo user"}],"createdTS":"2020-06-06T18:25:01.155Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5ed5d5c8ec9f4b7276ef8d7e","location":"Dribble Arena Test,Indiranagar","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"f2c4ce11-bde0-45f7-aae9-a470ded10530","sportId":"SP5","date":"2020-06-02T00:00:00.000Z","startTime":"2020-06-02T03:30:00.000Z","endTime":"2020-06-02T04:30:00.000Z","timing":1,"pals":[{"noshow":false,"noshowSwitch":false,"rating":3,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-02T08:22:16.000Z","userName":"playo user"}],"createdTS":"2020-06-02T04:30:00.768Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5ed51ef8749cca727da39f6b","location":"Mekur Hosakeri","hostId":"2537e208-35f2-4b38-ac65-081ab1a249be","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"b76c1f0b-ed02-46c3-847e-c2ed0230f44b","sportId":"SP5","date":"2020-06-01T00:00:00.000Z","timing":2,"pals":[{"noshow":true,"noshowSwitch":false,"rating":5,"newPlaypal":false,"firstRatedOn":"2020-06-04T11:16:18.000Z","isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-04T11:16:23.000Z","userName":"playo user"}],"createdTS":"2020-06-01T15:30:00.186Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5ed4cafb417f305b48c80d58","location":"Magrath Road, Shanthala Nagar","hostId":"2537e208-35f2-4b38-ac65-081ab1a249be","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"efb5ee60-ab12-41f4-babf-099b50b2d7ea","sportId":"SP5","date":"2020-05-30T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":true,"isRemoved":false,"palId":"861c3457-c99c-4dbb-ab2c-5eb447eaf9fe","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-05T20:38:34.000Z","firstRatedOn":"2020-06-05T20:38:12.000Z"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-01T09:31:39.326Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":2,"newPlaypal":true,"isRemoved":true,"palId":"54fe8420-dae7-4bb2-aa08-320b7dc40794","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-10T09:41:20.000Z","firstRatedOn":"2020-06-10T09:41:20.000Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":true,"isRemoved":false,"palId":"2d617f4d-7be2-4fe7-be3a-7c09fd7e513c","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-01T09:31:39.325Z"}],"createdTS":"2020-06-01T09:31:39.326Z","modTS":"2021-11-18T07:09:26.826Z","__v":0},{"_id":"619b94008fff1950a20adaf2","location":"Indiranagar","hostId":"1b7887d3-8255-409b-9efe-89b64b701862","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":false,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"afabf002-5260-4248-b200-cedbcbe3fc59","sportId":"SP5","date":"2021-11-22T00:00:00.000Z","startTime":"2021-11-22T13:30:00.794Z","endTime":"2021-11-22T14:00:00.794Z","timing":2,"pals":[{"noshow":true,"noshowSwitch":false,"rating":0,"newPlaypal":false,"firstRatedOn":null,"isRemoved":false,"userPresent":null,"palId":"1b7887d3-8255-409b-9efe-89b64b701862","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2021-11-22T12:58:40.047Z"},{"noshow":true,"noshowSwitch":false,"rating":0,"newPlaypal":false,"firstRatedOn":null,"isRemoved":false,"userPresent":null,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-11-22T12:58:40.047Z"}],"createdTS":"2021-11-22T12:58:40.047Z","modTS":"2021-11-22T13:00:41.806Z","__v":0}];
|
|
3
|
+
|
|
4
|
+
const ratingTest = require("./lib/ratings/index");
|
|
5
|
+
|
|
6
|
+
const test = ratingTest.getUserRecentRatings(data, 4);
|
|
7
|
+
|
|
8
|
+
console.log(test, data.length);
|