playov2-js-utilities 0.3.0 → 0.3.4
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 +27 -19
- package/lib/notification.config.js +48 -95
- 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
|
|
@@ -204,6 +204,13 @@ const host_cancelled_activity = {
|
|
|
204
204
|
notificationId: notificationIds.ACTIVITY_CANCEL
|
|
205
205
|
};
|
|
206
206
|
|
|
207
|
+
const activity_reminder = {
|
|
208
|
+
heading: '⏰, Activity reminder!',
|
|
209
|
+
text: 'You have a {sport_name}} game coming up on {{date}}. Best of luck!',
|
|
210
|
+
buttons: [],
|
|
211
|
+
notificationId: ''
|
|
212
|
+
}
|
|
213
|
+
|
|
207
214
|
const host_updated_activity_details = {
|
|
208
215
|
// ??
|
|
209
216
|
};
|
|
@@ -228,5 +235,6 @@ module.exports = {
|
|
|
228
235
|
host_revoked_invite,
|
|
229
236
|
host_retired_user,
|
|
230
237
|
user_left_game,
|
|
231
|
-
host_cancelled_activity
|
|
238
|
+
host_cancelled_activity,
|
|
239
|
+
activity_reminder
|
|
232
240
|
}
|
|
@@ -23,22 +23,29 @@ const notificationChannels = {
|
|
|
23
23
|
// ------------------------------------------ Exported (public) -----------------------------------------//
|
|
24
24
|
|
|
25
25
|
const notificationIds = {
|
|
26
|
-
ACTIVITY_NOTIFY_PUSH: 'activity-notify-push',
|
|
27
|
-
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',
|
|
28
29
|
GROUP_INVITATION: 'group-invitation',
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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',
|
|
33
36
|
GROUP_REQUEST_RESPONSE: 'group-request-response',
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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',
|
|
42
49
|
ACTIVITY_INVITATION: 'activity-invitation',
|
|
43
50
|
ACTIVITY_INVITATION_RESPONSE: 'activity-invitation-response',
|
|
44
51
|
ACTIVITY_REQUEST: 'activity-request',
|
|
@@ -71,29 +78,21 @@ const notificationIds = {
|
|
|
71
78
|
SPLIT_EXPENSE_DELETED: 'split-expense-deleted',
|
|
72
79
|
HOST_ACTIVITY_PAYOUT: 'host-activity-payout',
|
|
73
80
|
KARMA_CASHBACK: 'karma-cashback',
|
|
74
|
-
ACTIVITY_QUERY_ANSWERED: 'activity-query-answered'
|
|
81
|
+
ACTIVITY_QUERY_ANSWERED: 'activity-query-answered',
|
|
82
|
+
ACTIVITY_REMINDER: 'activity-reminder'
|
|
75
83
|
};
|
|
76
84
|
|
|
77
85
|
// TODO - Check targets against current value
|
|
78
86
|
|
|
79
87
|
const config = {
|
|
80
|
-
[notificationIds.
|
|
81
|
-
category: notificationCategories,
|
|
82
|
-
target: "group",
|
|
83
|
-
path: "timeline",
|
|
84
|
-
title: "Group Update",
|
|
85
|
-
type: ["push"],
|
|
86
|
-
buttons: [],
|
|
87
|
-
android_channel_id: ''
|
|
88
|
-
},
|
|
89
|
-
[notificationIds.ACTIVITY_NOTIFY_DRAWER]: {
|
|
88
|
+
[notificationIds.ACTIVITY_NOTIFY]: {
|
|
90
89
|
category: notificationCategories.GROUP,
|
|
91
90
|
target: "group",
|
|
92
91
|
path: "timeline",
|
|
93
92
|
title: "Group Update",
|
|
94
|
-
type: ["drawer"],
|
|
93
|
+
type: ["drawer", "push"],
|
|
95
94
|
buttons: [],
|
|
96
|
-
android_channel_id:
|
|
95
|
+
android_channel_id: notificationChannels.activity_suggestions
|
|
97
96
|
},
|
|
98
97
|
[notificationIds.GROUP_INVITATION]: {
|
|
99
98
|
category: notificationCategories.GROUP,
|
|
@@ -104,39 +103,21 @@ const config = {
|
|
|
104
103
|
buttons: [],
|
|
105
104
|
android_channel_id: notificationChannels.groups_manage_requests
|
|
106
105
|
},
|
|
107
|
-
[notificationIds.
|
|
106
|
+
[notificationIds.GROUP_INVITATION_RESPONSE]: {
|
|
108
107
|
category: notificationCategories.GROUP,
|
|
109
108
|
target: "group",
|
|
110
109
|
path: "manage",
|
|
111
110
|
title: "Group Update",
|
|
112
|
-
type: ["push"],
|
|
113
|
-
buttons: [],
|
|
114
|
-
android_channel_id: notificationChannels.groups_manage_requests
|
|
115
|
-
},
|
|
116
|
-
[notificationIds.GROUP_INVITATION_RESPONSE_DRAWER]: {
|
|
117
|
-
category: notificationCategories.GROUP,
|
|
118
|
-
target: "group",
|
|
119
|
-
path: "manage",
|
|
120
|
-
title: "Group Update",
|
|
121
|
-
type: ["drawer"],
|
|
122
|
-
buttons: [],
|
|
123
|
-
android_channel_id: notificationChannels.groups_manage_requests
|
|
124
|
-
},
|
|
125
|
-
[notificationIds.GROUP_REQUEST_PUSH]: {
|
|
126
|
-
category: notificationCategories.GROUP,
|
|
127
|
-
target: "group",
|
|
128
|
-
path: "manage",
|
|
129
|
-
title: "Group Update",
|
|
130
|
-
type: ["push"],
|
|
111
|
+
type: ["push", "drawer"],
|
|
131
112
|
buttons: [],
|
|
132
113
|
android_channel_id: notificationChannels.groups_manage_requests
|
|
133
114
|
},
|
|
134
|
-
[notificationIds.
|
|
115
|
+
[notificationIds.GROUP_REQUEST]: {
|
|
135
116
|
category: notificationCategories.GROUP,
|
|
136
117
|
target: "group",
|
|
137
118
|
path: "manage",
|
|
138
119
|
title: "Group Update",
|
|
139
|
-
type: ["drawer"],
|
|
120
|
+
type: ["push", "drawer"],
|
|
140
121
|
buttons: [],
|
|
141
122
|
android_channel_id: notificationChannels.groups_manage_requests
|
|
142
123
|
},
|
|
@@ -149,77 +130,41 @@ const config = {
|
|
|
149
130
|
buttons: [],
|
|
150
131
|
android_channel_id: notificationChannels.groups_manage_requests
|
|
151
132
|
},
|
|
152
|
-
[notificationIds.
|
|
153
|
-
category: notificationCategories.GROUP,
|
|
154
|
-
target: "group",
|
|
155
|
-
path: "manage",
|
|
156
|
-
title: "Group Update",
|
|
157
|
-
type: ["push"],
|
|
158
|
-
buttons: [],
|
|
159
|
-
android_channel_id: notificationChannels.group_updates
|
|
160
|
-
},
|
|
161
|
-
[notificationIds.GROUP_NAME_DRAWER]: {
|
|
133
|
+
[notificationIds.GROUP_NAME]: {
|
|
162
134
|
category: notificationCategories.GROUP,
|
|
163
135
|
target: "group",
|
|
164
136
|
path: "manage",
|
|
165
137
|
title: "Group Update",
|
|
166
|
-
type: ["drawer"],
|
|
138
|
+
type: ["push", "drawer"],
|
|
167
139
|
buttons: [],
|
|
168
140
|
android_channel_id: notificationChannels.group_updates
|
|
169
141
|
},
|
|
170
|
-
[notificationIds.
|
|
142
|
+
[notificationIds.ADMIN_STATUS]: {
|
|
171
143
|
category: notificationCategories.GROUP,
|
|
172
144
|
target: "group",
|
|
173
145
|
path: "manage",
|
|
174
146
|
title: "Group Update",
|
|
175
|
-
type: ["push"],
|
|
147
|
+
type: ["drawer", "push"],
|
|
176
148
|
buttons: [],
|
|
177
149
|
android_channel_id: notificationChannels.group_updates
|
|
178
150
|
},
|
|
179
|
-
[notificationIds.
|
|
180
|
-
category: notificationCategories.GROUP,
|
|
181
|
-
target: "group",
|
|
182
|
-
path: "manage",
|
|
183
|
-
title: "Group Update",
|
|
184
|
-
type: ["drawer"],
|
|
185
|
-
buttons: [],
|
|
186
|
-
android_channel_id: ''
|
|
187
|
-
},
|
|
188
|
-
[notificationIds.NEW_MESSAGE_PUSH]: {
|
|
151
|
+
[notificationIds.NEW_MESSAGE]: {
|
|
189
152
|
category: notificationCategories.GROUP,
|
|
190
153
|
target: "group",
|
|
191
154
|
path: "board",
|
|
192
155
|
title: "Group Update",
|
|
193
|
-
type: ["push"],
|
|
156
|
+
type: ["push", "drawer"],
|
|
194
157
|
buttons: [],
|
|
195
|
-
android_channel_id:
|
|
158
|
+
android_channel_id: notificationChannels.group_updates
|
|
196
159
|
},
|
|
197
|
-
[notificationIds.
|
|
160
|
+
[notificationIds.NEW_COMMENT]: {
|
|
198
161
|
category: notificationCategories.GROUP,
|
|
199
162
|
target: "group",
|
|
200
163
|
path: "board",
|
|
201
164
|
title: "Group Update",
|
|
202
|
-
type: ["drawer"],
|
|
165
|
+
type: ["drawer","push"],
|
|
203
166
|
buttons: [],
|
|
204
|
-
android_channel_id:
|
|
205
|
-
},
|
|
206
|
-
[notificationIds.NEW_COMMENT_PUSH]: {
|
|
207
|
-
category: notificationCategories.GROUP,
|
|
208
|
-
target: "group",
|
|
209
|
-
path: "message",
|
|
210
|
-
title: "Group Update",
|
|
211
|
-
type: ["push"],
|
|
212
|
-
buttons: [],
|
|
213
|
-
android_channel_id: ''
|
|
214
|
-
},
|
|
215
|
-
[notificationIds.NEW_COMMENT_DRAWER]: {
|
|
216
|
-
category: notificationCategories.GROUP,
|
|
217
|
-
target: "group",
|
|
218
|
-
path: "message",
|
|
219
|
-
title: "Group Update",
|
|
220
|
-
type: ["drawer"],
|
|
221
|
-
buttons: [],
|
|
222
|
-
android_channel_id: ''
|
|
167
|
+
android_channel_id: notificationChannels.group_updates
|
|
223
168
|
},
|
|
224
169
|
[notificationIds.ACTIVITY_INVITATION]: {
|
|
225
170
|
category: notificationCategories.ACTIVITY,
|
|
@@ -488,6 +433,14 @@ const config = {
|
|
|
488
433
|
type: ["push", "drawer"],
|
|
489
434
|
buttons: [],
|
|
490
435
|
android_channel_id: notificationChannels.activity_query
|
|
436
|
+
},
|
|
437
|
+
[notificationIds.ACTIVITY_REMINDER] : {
|
|
438
|
+
category: notificationCategories.ACTIVITY,
|
|
439
|
+
target: "match",
|
|
440
|
+
title: "Activity Reminder",
|
|
441
|
+
type: ["push", "drawer"],
|
|
442
|
+
buttons: [],
|
|
443
|
+
android_channel_id: ''
|
|
491
444
|
}
|
|
492
445
|
};
|
|
493
446
|
|
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.
|
|
3
|
+
"version": "0.3.4",
|
|
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);
|