playov2-js-utilities 0.2.8 → 0.3.2

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 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
  };
@@ -2,37 +2,50 @@
2
2
  //\-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_- Private -_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\//
3
3
  const notificationCategories = {
4
4
  GROUP: 'group',
5
- ACTIVITY: 'activity'
5
+ ACTIVITY: 'activity',
6
+ KARMA: 'karma',
7
+ SPLIT_PAYMENTS: 'split_payments'
6
8
  };
7
9
 
8
10
  // Android notification channels will be bound to categories
9
11
  const notificationChannels = {
10
- [notificationCategories.ACTIVITY]: '9704a3d8-e86a-4bd5-9141-cd50972f3d4f'
11
- };
12
-
13
- const notificationButtons = {
14
- [notificationIds.ACTIVITY_NOTIFY_PUSH]: []
12
+ 'karma': '8a9c67b9-1cdc-46a2-bb90-6f00f0e848eb', // done - 1 notification tagged
13
+ 'activity_query': '99863ba1-88ba-44f6-b8b3-6df51d97ae03', // done - 2 notifications tagged
14
+ 'activity_player_in_out': '5e6c5f64-1413-46ed-829d-763a3b7cab22',
15
+ 'activity_updates': '14d7a740-2da3-4bb5-888f-80ed487d6567',// done - 8 notifications tagged
16
+ 'activity_post_game': '23131b6a-2cf0-4a34-bc78-dd6f8676e319', // done - 1 notification tagged
17
+ 'activity_suggestions': '3ab98c37-b93c-4d39-ab55-bb2cc6279cb8', // done - 1 notifications tagged
18
+ 'expenses': '1eb30f33-2b3b-40ce-8798-fce55c1275e2', // done - 6 notifications tagged
19
+ 'groups_manage_requests': '83c024d1-2cb7-47fa-989d-1d8ef343a51c', // done - 6 notifications tagged
20
+ 'group_updates': '9e023a20-deab-4bc4-bd33-08a8d9316322' // done - 3 notifications tagged
15
21
  };
16
22
 
17
23
  // ------------------------------------------ Exported (public) -----------------------------------------//
18
24
 
19
25
  const notificationIds = {
20
- ACTIVITY_NOTIFY_PUSH: 'activity-notify-push',
21
- 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',
22
29
  GROUP_INVITATION: 'group-invitation',
23
- GROUP_INVITATION_RESPONSE_PUSH: 'group-invitation-response-push',
24
- GROUP_INVITATION_RESPONSE_DRAWER: 'group-invitation-response-drawer',
25
- GROUP_REQUEST_PUSH: 'group-request-push',
26
- GROUP_REQUEST_DRAWER: 'group-request-drawer',
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',
27
36
  GROUP_REQUEST_RESPONSE: 'group-request-response',
28
- GROUP_NAME_PUSH: 'group-name-push',
29
- GROUP_NAME_DRAWER: 'group-name-drawer',
30
- ADMIN_STATUS_PUSH: 'admin-status-push',
31
- ADMIN_STATUS_DRAWER: 'admin-status-drawer',
32
- NEW_MESSAGE_PUSH: 'new-message-push',
33
- NEW_MESSAGE_DRAWER: 'new-message-drawer',
34
- NEW_COMMENT_PUSH: 'new-comment-push',
35
- NEW_COMMENT_DRAWER: 'new-comment-drawer',
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',
36
49
  ACTIVITY_INVITATION: 'activity-invitation',
37
50
  ACTIVITY_INVITATION_RESPONSE: 'activity-invitation-response',
38
51
  ACTIVITY_REQUEST: 'activity-request',
@@ -68,328 +81,362 @@ const notificationIds = {
68
81
  ACTIVITY_QUERY_ANSWERED: 'activity-query-answered'
69
82
  };
70
83
 
84
+ // TODO - Check targets against current value
85
+
71
86
  const config = {
72
- [notificationIds.ACTIVITY_NOTIFY_PUSH]: {
73
- category: notificationCategories,
74
- target: "group",
75
- path: "timeline",
76
- title: "Group Update",
77
- type: ["push"],
78
- channel: notificationChannels[notificationCategories.ACTIVITY],
79
- buttons: []
80
- },
81
- [notificationIds.ACTIVITY_NOTIFY_DRAWER]: {
87
+ [notificationIds.ACTIVITY_NOTIFY]: {
82
88
  category: notificationCategories.GROUP,
83
89
  target: "group",
84
90
  path: "timeline",
85
91
  title: "Group Update",
86
- type: ["drawer"]
92
+ type: ["drawer", "push"],
93
+ buttons: [],
94
+ android_channel_id: notificationChannels.activity_suggestions
87
95
  },
88
96
  [notificationIds.GROUP_INVITATION]: {
89
97
  category: notificationCategories.GROUP,
90
98
  target: "group",
91
99
  path: "manage",
92
100
  title: "Group Invitation",
93
- type: ["push"]
94
- },
95
- [notificationIds.GROUP_INVITATION_RESPONSE_PUSH]: {
96
- category: notificationCategories.GROUP,
97
- target: "group",
98
- path: "manage",
99
- title: "Group Update",
100
- type: ["push"]
101
- },
102
- [notificationIds.GROUP_INVITATION_RESPONSE_DRAWER]: {
103
- category: notificationCategories.GROUP,
104
- target: "group",
105
- path: "manage",
106
- title: "Group Update",
107
- type: ["drawer"]
101
+ type: ["push"],
102
+ buttons: [],
103
+ android_channel_id: notificationChannels.groups_manage_requests
108
104
  },
109
- [notificationIds.GROUP_REQUEST_PUSH]: {
105
+ [notificationIds.GROUP_INVITATION_RESPONSE]: {
110
106
  category: notificationCategories.GROUP,
111
107
  target: "group",
112
108
  path: "manage",
113
109
  title: "Group Update",
114
- type: ["push"]
110
+ type: ["push", "drawer"],
111
+ buttons: [],
112
+ android_channel_id: notificationChannels.groups_manage_requests
115
113
  },
116
- [notificationIds.GROUP_REQUEST_DRAWER]: {
114
+ [notificationIds.GROUP_REQUEST]: {
117
115
  category: notificationCategories.GROUP,
118
116
  target: "group",
119
117
  path: "manage",
120
118
  title: "Group Update",
121
- type: ["drawer"]
119
+ type: ["push", "drawer"],
120
+ buttons: [],
121
+ android_channel_id: notificationChannels.groups_manage_requests
122
122
  },
123
123
  [notificationIds.GROUP_REQUEST_RESPONSE]: {
124
124
  category: notificationCategories.GROUP,
125
125
  target: "group",
126
126
  path: "manage",
127
127
  title: "Group Update",
128
- type: ["push", "drawer"]
129
- },
130
- [notificationIds.GROUP_NAME_PUSH]: {
131
- category: notificationCategories.GROUP,
132
- target: "group",
133
- path: "manage",
134
- title: "Group Update",
135
- type: ["push"]
136
- },
137
- [notificationIds.GROUP_NAME_DRAWER]: {
138
- category: notificationCategories.GROUP,
139
- target: "group",
140
- path: "manage",
141
- title: "Group Update",
142
- type: ["drawer"]
128
+ type: ["push", "drawer"],
129
+ buttons: [],
130
+ android_channel_id: notificationChannels.groups_manage_requests
143
131
  },
144
- [notificationIds.ADMIN_STATUS_PUSH]: {
132
+ [notificationIds.GROUP_NAME]: {
145
133
  category: notificationCategories.GROUP,
146
134
  target: "group",
147
135
  path: "manage",
148
136
  title: "Group Update",
149
- type: ["push"]
137
+ type: ["push", "drawer"],
138
+ buttons: [],
139
+ android_channel_id: notificationChannels.group_updates
150
140
  },
151
- [notificationIds.ADMIN_STATUS_DRAWER]: {
141
+ [notificationIds.ADMIN_STATUS]: {
152
142
  category: notificationCategories.GROUP,
153
143
  target: "group",
154
144
  path: "manage",
155
145
  title: "Group Update",
156
- type: ["drawer"]
146
+ type: ["drawer", "push"],
147
+ buttons: [],
148
+ android_channel_id: notificationChannels.group_updates
157
149
  },
158
- [notificationIds.NEW_MESSAGE_PUSH]: {
150
+ [notificationIds.NEW_MESSAGE]: {
159
151
  category: notificationCategories.GROUP,
160
152
  target: "group",
161
153
  path: "board",
162
154
  title: "Group Update",
163
- type: ["push"]
155
+ type: ["push", "drawer"],
156
+ buttons: [],
157
+ android_channel_id: notificationChannels.group_updates
164
158
  },
165
- [notificationIds.NEW_COMMENT_DRAWER]: {
159
+ [notificationIds.NEW_COMMENT]: {
166
160
  category: notificationCategories.GROUP,
167
161
  target: "group",
168
162
  path: "board",
169
163
  title: "Group Update",
170
- type: ["drawer"]
171
- },
172
- [notificationIds.NEW_COMMENT_PUSH]: {
173
- category: notificationCategories.GROUP,
174
- target: "group",
175
- path: "message",
176
- title: "Group Update",
177
- type: ["push"]
178
- },
179
- [notificationIds.NEW_COMMENT_DRAWER]: {
180
- category: notificationCategories.GROUP,
181
- target: "group",
182
- path: "message",
183
- title: "Group Update",
184
- type: ["drawer"]
164
+ type: ["drawer","push"],
165
+ buttons: [],
166
+ android_channel_id: notificationChannels.group_updates
185
167
  },
186
168
  [notificationIds.ACTIVITY_INVITATION]: {
187
169
  category: notificationCategories.ACTIVITY,
188
170
  target: "match",
189
171
  title: "You've been invited to a game! 📩",
190
172
  type: ["push", "drawer"],
191
- ios_attachments: {
192
- "mediaUrl": "https://playov2.imgix.net/marketing/squid-game-notification02.jpg"
193
- },
194
- big_picture: "https://playov2.imgix.net/marketing/squid-game-notification02.jpg"
195
-
173
+ buttons: [],
174
+ android_channel_id: notificationChannels.activity_player_in_out
196
175
  },
197
176
  [notificationIds.ACTIVITY_INVITATION_RESPONSE]: {
198
177
  category: notificationCategories.ACTIVITY,
199
178
  target: "match",
200
179
  path: "manage",
201
180
  title: "Activity Update",
202
- type: ["push", "drawer"]
181
+ type: ["push", "drawer"],
182
+ buttons: [],
183
+ android_channel_id: notificationChannels.activity_player_in_out
203
184
  },
204
185
  [notificationIds.ACTIVITY_REQUEST]: {
205
186
  category: notificationCategories.ACTIVITY,
206
187
  target: "match",
207
188
  title: "Activity Update",
208
- type: ["push", "drawer"]
189
+ type: ["push", "drawer"],
190
+ buttons: [],
191
+ android_channel_id: notificationChannels.activity_player_in_out
209
192
  },
210
193
  [notificationIds.ACTIVITY_REQUEST_RESPONSE]: {
211
194
  category: notificationCategories.ACTIVITY,
212
195
  target: "match",
213
196
  title: "Activity Update",
214
- type: ["push", "drawer"]
197
+ type: ["push", "drawer"],
198
+ buttons: [],
199
+ android_channel_id: notificationChannels.activity_player_in_out
215
200
  },
216
201
  [notificationIds.HOST_RETIRED]: {
217
202
  category: notificationCategories.ACTIVITY,
218
203
  target: "match",
219
204
  title: "Activity Update",
220
- type: ["push", "drawer"]
205
+ type: ["push", "drawer"],
206
+ buttons: [],
207
+ android_channel_id: notificationChannels.activity_player_in_out
221
208
  },
222
209
  [notificationIds.EDIT_ACTIVITY]: {
223
210
  category: notificationCategories.ACTIVITY,
224
211
  target: "match",
225
212
  title: "Activity Update",
226
- type: ["push", "drawer"]
213
+ type: ["push", "drawer"],
214
+ buttons: [],
215
+ android_channel_id: notificationChannels.activity_updates
227
216
  },
228
217
  [notificationIds.ACTIVITY_FULL]: {
229
218
  category: notificationCategories.ACTIVITY,
230
219
  target: "match",
231
220
  path: "manage",
232
221
  title: "Activity Update",
233
- type: ["push", "drawer"]
222
+ type: ["push", "drawer"],
223
+ buttons: [],
224
+ android_channel_id: notificationChannels.activity_updates
234
225
  },
235
226
  [notificationIds.VENUE_TAGGED]: {
236
227
  category: notificationCategories.ACTIVITY,
237
228
  target: "match",
238
229
  title: "Activity Update",
239
- type: ["push", "drawer"]
230
+ type: ["push", "drawer"],
231
+ buttons: [],
232
+ android_channel_id: notificationChannels.activity_updates
240
233
  },
241
234
  [notificationIds.VENUE_BOOKED]: {
242
235
  category: notificationCategories.ACTIVITY,
243
236
  target: "match",
244
237
  title: "Activity Update",
245
- type: ["push", "drawer"]
238
+ type: ["push", "drawer"],
239
+ buttons: [],
240
+ android_channel_id: notificationChannels.activity_updates
246
241
  },
247
242
  [notificationIds.BOOKING_CANCELLED]: {
248
243
  category: notificationCategories.ACTIVITY,
249
244
  target: "match",
250
245
  title: "Activity Update",
251
- type: ["push", "drawer"]
246
+ type: ["push", "drawer"],
247
+ buttons: [],
248
+ android_channel_id: notificationChannels.activity_updates
252
249
  },
253
250
  [notificationIds.COHOST_ADDED]: {
254
251
  category: notificationCategories.ACTIVITY,
255
252
  target: "match",
256
253
  title: "Activity Update",
257
- type: ["push", "drawer"]
254
+ type: ["push", "drawer"],
255
+ buttons: [],
256
+ android_channel_id: notificationChannels.activity_updates
258
257
  },
259
258
  [notificationIds.COHOST_DELETED]: {
260
259
  category: notificationCategories.ACTIVITY,
261
260
  target: "match",
262
261
  title: "Activity Update",
263
- type: ["push", "drawer"]
262
+ type: ["push", "drawer"],
263
+ buttons: [],
264
+ android_channel_id: notificationChannels.activity_updates
264
265
  },
265
266
  [notificationIds.ACTIVITY_QUERY]: {
266
267
  category: notificationCategories.ACTIVITY,
267
268
  target: "match",
268
269
  title: "Activity Update",
269
- type: ["push", "drawer"]
270
+ type: ["push", "drawer"],
271
+ buttons: [],
272
+ android_channel_id: notificationChannels.activity_query
270
273
  },
271
274
  [notificationIds.ACTIVITY_CANCEL]: {
272
275
  category: notificationCategories.ACTIVITY,
273
276
  target: "match",
274
277
  title: "Activity Update",
275
- type: ["push", "drawer"]
278
+ type: ["push", "drawer"],
279
+ buttons: [],
280
+ android_channel_id: notificationChannels.activity_updates
276
281
  },
277
282
  [notificationIds.ACTIVITY_REMINDER]: {
278
283
  category: notificationCategories.ACTIVITY,
279
284
  target: "match",
280
285
  title: "Activity Reminder",
281
- type: ["push"]
286
+ type: ["push"],
287
+ buttons: [],
288
+ android_channel_id: notificationChannels.activity_player_in_out
282
289
  },
283
290
  [notificationIds.ACTIVITY_HOSTED]: {
284
291
  category: "playpal-activity",
285
292
  target: "match",
286
293
  title: "Activity Update",
287
- type: ["push", "drawer"]
294
+ type: ["push", "drawer"],
295
+ buttons: [],
296
+ android_channel_id: notificationChannels.activity_suggestions
288
297
  },
289
298
  [notificationIds.ACTIVITY_REQUEST_MANAGE]: {
290
299
  category: notificationCategories.ACTIVITY,
291
300
  target: "match",
292
301
  path: "manage",
293
302
  title: "Activity Update",
294
- type: ["push", "drawer"]
303
+ type: ["push", "drawer"],
304
+ buttons: [],
305
+ android_channel_id: notificationChannels.activity_player_in_out
295
306
  },
296
307
  [notificationIds.ACTIVITY_JOINED]: {
297
308
  category: notificationCategories.ACTIVITY,
298
309
  target: "match",
299
310
  title: "Activity Update",
300
- type: ["push", "drawer"]
311
+ type: ["push", "drawer"],
312
+ buttons: [],
313
+ android_channel_id: notificationChannels.activity_player_in_out
301
314
  },
302
315
  [notificationIds.MATCH_RATING]: {
303
316
  category: notificationCategories.ACTIVITY,
304
317
  target: "match",
305
318
  path: "gamebook",
306
319
  title: "Rate Activity",
307
- type: ["push", "drawer"]
320
+ type: ["push", "drawer"],
321
+ buttons: [],
322
+ android_channel_id: notificationChannels.activity_post_game
308
323
  },
309
324
  [notificationIds.BOOKING_RECEIPT]: {
310
325
  category: notificationCategories.ACTIVITY,
311
326
  target: "booking",
312
327
  title: "Booking Update",
313
- type: ["push", "drawer"]
328
+ type: ["push", "drawer"],
329
+ buttons: [],
330
+ android_channel_id: ''
314
331
  },
315
332
  [notificationIds.LOUNGE_QUESTION_SUGGEST]: {
316
333
  category: "lounge",
317
334
  target: "lounge/question",
318
335
  title: "Community Update",
319
- type: ["push"]
336
+ type: ["push"],
337
+ buttons: [],
338
+ android_channel_id: ''
320
339
  },
321
340
  [notificationIds.LOUNGE_ANSWER]: {
322
341
  category: "lounge",
323
342
  target: "lounge/answer",
324
343
  title: "Community Update",
325
- type: ["push", "drawer"]
344
+ type: ["push", "drawer"],
345
+ buttons: [],
346
+ android_channel_id: ''
326
347
  },
327
348
  [notificationIds.LOUNGE_COMMENT]: {
328
349
  category: "lounge",
329
350
  target: "lounge/answer",
330
351
  title: "Community Update",
331
- type: ["push", "drawer"]
352
+ type: ["push", "drawer"],
353
+ buttons: [],
354
+ android_channel_id: ''
332
355
  },
333
356
  [notificationIds.LOUNGE_QUESTION_APPROVED]: {
334
357
  category: "lounge",
335
358
  target: "lounge/question",
336
359
  title: "Community Update",
337
- type: ["push", "drawer"]
360
+ type: ["push", "drawer"],
361
+ buttons: [],
362
+ android_channel_id: ''
338
363
  },
339
364
  [notificationIds.SPLIT_MARK_PAID]: {
340
365
  category: notificationCategories.ACTIVITY,
341
366
  target: "activity/logs",
342
367
  title: "Expense Update",
343
- type: ["push", "drawer"]
368
+ type: ["push", "drawer"],
369
+ buttons: [],
370
+ android_channel_id: notificationChannels.expenses
344
371
  },
345
372
  [notificationIds.SPLIT_REVERT_SETTLEMENT]: {
346
373
  category: notificationCategories.ACTIVITY,
347
374
  target: "activity/logs",
348
375
  title: "Expense Update",
349
- type: ["push", "drawer"]
376
+ type: ["push", "drawer"],
377
+ buttons: [],
378
+ android_channel_id: notificationChannels.expenses
350
379
  },
351
380
  [notificationIds.SPLIT_EXPENSE_COMMENT]: {
352
381
  category: notificationCategories.ACTIVITY,
353
382
  target: "activity/expenses/comments",
354
383
  title: "Expense Update",
355
- type: ["push", "drawer"]
384
+ type: ["push", "drawer"],
385
+ buttons: [],
386
+ android_channel_id: notificationChannels.expenses
356
387
  },
357
388
  [notificationIds.SPLIT_EXPENSE_ADDED]: {
358
389
  category: notificationCategories.ACTIVITY,
359
390
  target: "activity/expenses",
360
391
  title: "Expense Update",
361
- type: ["push", "drawer"]
392
+ type: ["push", "drawer"],
393
+ buttons: [],
394
+ android_channel_id: notificationChannels.expenses
362
395
  },
363
396
  [notificationIds.SPLIT_EXPENSE_EDITED]: {
364
397
  category: notificationCategories.ACTIVITY,
365
398
  target: "activity/expenses",
366
399
  title: "Expense Update",
367
- type: ["push", "drawer"]
400
+ type: ["push", "drawer"],
401
+ buttons: [],
402
+ android_channel_id: notificationChannels.expenses
368
403
  },
369
404
  [notificationIds.SPLIT_EXPENSE_DELETED]: {
370
405
  category: notificationCategories.ACTIVITY,
371
406
  target: "activity/logs",
372
407
  title: "Expense Update",
373
- type: ["push", "drawer"]
408
+ type: ["push", "drawer"],
409
+ buttons: [],
410
+ android_channel_id: notificationChannels.expenses
374
411
  },
375
412
  [notificationIds.HOST_ACTIVITY_PAYOUT]: {
376
413
  category: notificationCategories.ACTIVITY,
377
414
  target: "playocredits",
378
415
  title: "Activity Update",
379
- type: ["push", "drawer"]
416
+ type: ["push", "drawer"],
417
+ buttons: [],
418
+ android_channel_id: ''
380
419
  },
381
420
  [notificationIds.KARMA_CASHBACK]: {
382
421
  category: notificationCategories.ACTIVITY,
383
422
  target: "passbook",
384
423
  title: "Karma Update",
385
- type: ["push", "drawer"]
424
+ type: ["push", "drawer"],
425
+ android_channel_id: notificationChannels.karma,
426
+ buttons: []
386
427
  },
387
428
  [notificationIds.ACTIVITY_QUERY_ANSWERED]: {
388
429
  category: notificationCategories.ACTIVITY,
389
430
  target: "match",
390
431
  title: "Activity Update",
391
- type: ["push", "drawer"]
432
+ type: ["push", "drawer"],
433
+ buttons: [],
434
+ android_channel_id: notificationChannels.activity_query
392
435
  }
393
436
  };
394
437
 
438
+ const notificationButtons = {
439
+ [notificationIds.ACTIVITY_NOTIFY_PUSH]: []
440
+ };
441
+
395
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.2.8",
3
+ "version": "0.3.2",
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,219 @@
1
+ const data =[
2
+ {
3
+ "_id": "619b64773f930c6f90778f93",
4
+ "location": "Indiranagar",
5
+ "hostId": "1b7887d3-8255-409b-9efe-89b64b701862",
6
+ "matchHappened": true,
7
+ "matchRating": -1,
8
+ "userPlayed": true,
9
+ "expired": false,
10
+ "cancelled": false,
11
+ "noshow": false,
12
+ "removed": false,
13
+ "userId": "1b7887d3-8255-409b-9efe-89b64b701862",
14
+ "activityId": "9a8942e0-9778-4c43-befd-c8f7de4d3985",
15
+ "sportId": "SP5",
16
+ "date": "2021-11-22T00:00:00.000Z",
17
+ "timing": 2,
18
+ "pals": [
19
+ {
20
+ "noshow": false,
21
+ "noshowSwitch": false,
22
+ "rating": 5,
23
+ "newPlaypal": false,
24
+ "firstRatedOn": "2021-11-22T09:36:09.000Z",
25
+ "isRemoved": false,
26
+ "userPresent": null,
27
+ "palId": "2537e208-35f2-4b38-ac65-081ab1a249be",
28
+ "reputation": [
29
+ {
30
+ "reputationId": 0,
31
+ "value": -1
32
+ },
33
+ {
34
+ "reputationId": 1,
35
+ "value": -1
36
+ },
37
+ {
38
+ "reputationId": 2,
39
+ "value": -1
40
+ }
41
+ ],
42
+ "timestamp": "2021-11-22T09:59:37.000Z"
43
+ }
44
+ ],
45
+ "createdTS": "2021-11-22T09:35:51.009Z",
46
+ "modTS": "2021-11-22T09:59:37.512Z",
47
+ "__v": 0
48
+ },
49
+ {
50
+ "_id": "619b6c5b8fff1950a20adae1",
51
+ "location": "Jayanagar, Bengaluru",
52
+ "hostId": "a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e",
53
+ "matchHappened": true,
54
+ "matchRating": -1,
55
+ "userPlayed": true,
56
+ "expired": true,
57
+ "cancelled": false,
58
+ "noshow": false,
59
+ "removed": false,
60
+ "userId": "1b7887d3-8255-409b-9efe-89b64b701862",
61
+ "activityId": "5161229a-e82d-498a-beed-8e2bc50bcaf7",
62
+ "sportId": "SP5",
63
+ "date": "2021-11-22T00:00:00.000Z",
64
+ "timing": 1,
65
+ "pals": [
66
+ {
67
+ "noshow": false,
68
+ "noshowSwitch": false,
69
+ "rating": 0,
70
+ "newPlaypal": false,
71
+ "isRemoved": false,
72
+ "userPresent": null,
73
+ "palId": "a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e",
74
+ "reputation": [
75
+ {
76
+ "reputationId": 0,
77
+ "value": -1
78
+ },
79
+ {
80
+ "reputationId": 1,
81
+ "value": -1
82
+ },
83
+ {
84
+ "reputationId": 2,
85
+ "value": -1
86
+ }
87
+ ],
88
+ "timestamp": "2021-11-22T10:09:31.718Z"
89
+ },
90
+ {
91
+ "noshow": false,
92
+ "noshowSwitch": false,
93
+ "rating": 4,
94
+ "newPlaypal": false,
95
+ "isRemoved": false,
96
+ "userPresent": null,
97
+ "palId": "2537e208-35f2-4b38-ac65-081ab1a249be",
98
+ "reputation": [
99
+ {
100
+ "reputationId": 0,
101
+ "value": -1
102
+ },
103
+ {
104
+ "reputationId": 1,
105
+ "value": -1
106
+ },
107
+ {
108
+ "reputationId": 2,
109
+ "value": -1
110
+ }
111
+ ],
112
+ "timestamp": "2021-11-22T11:22:05.000Z"
113
+ }
114
+ ],
115
+ "createdTS": "2021-11-22T10:09:31.718Z",
116
+ "modTS": "2021-11-22T11:26:49.742Z",
117
+ "__v": 0
118
+ },
119
+ {
120
+ "_id": "619b85378fff1950a20adaed",
121
+ "location": "Indiranagar",
122
+ "hostId": "1b7887d3-8255-409b-9efe-89b64b701862",
123
+ "matchHappened": true,
124
+ "matchRating": -1,
125
+ "userPlayed": true,
126
+ "expired": false,
127
+ "cancelled": false,
128
+ "noshow": false,
129
+ "removed": false,
130
+ "userId": "1b7887d3-8255-409b-9efe-89b64b701862",
131
+ "activityId": "00f9ff64-214c-470d-b7fb-760a6a3af8e0",
132
+ "sportId": "SP5",
133
+ "date": "2021-11-22T00:00:00.000Z",
134
+ "timing": 2,
135
+ "pals": [
136
+ {
137
+ "noshow": true,
138
+ "noshowSwitch": false,
139
+ "rating": 0,
140
+ "newPlaypal": false,
141
+ "firstRatedOn": null,
142
+ "isRemoved": false,
143
+ "userPresent": null,
144
+ "palId": "a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e",
145
+ "reputation": [
146
+ {
147
+ "reputationId": 0,
148
+ "value": -1
149
+ },
150
+ {
151
+ "reputationId": 1,
152
+ "value": -1
153
+ },
154
+ {
155
+ "reputationId": 2,
156
+ "value": -1
157
+ }
158
+ ],
159
+ "timestamp": "2021-11-22T11:55:35.341Z"
160
+ },
161
+ {
162
+ "noshow": false,
163
+ "noshowSwitch": false,
164
+ "rating": 0,
165
+ "newPlaypal": false,
166
+ "firstRatedOn": null,
167
+ "isRemoved": false,
168
+ "userPresent": null,
169
+ "palId": "88d8e6ed-207a-4b98-ace7-73a7bd6bc900",
170
+ "reputation": [
171
+ {
172
+ "reputationId": 0,
173
+ "value": -1
174
+ },
175
+ {
176
+ "reputationId": 1,
177
+ "value": -1
178
+ },
179
+ {
180
+ "reputationId": 2,
181
+ "value": -1
182
+ }
183
+ ],
184
+ "timestamp": "2021-11-22T11:55:35.341Z"
185
+ },
186
+ {
187
+ "noshow": true,
188
+ "noshowSwitch": false,
189
+ "rating": 0,
190
+ "newPlaypal": false,
191
+ "firstRatedOn": null,
192
+ "isRemoved": false,
193
+ "userPresent": null,
194
+ "palId": "2537e208-35f2-4b38-ac65-081ab1a249be",
195
+ "reputation": [
196
+ {
197
+ "reputationId": 0,
198
+ "value": 1
199
+ },
200
+ {
201
+ "reputationId": 1,
202
+ "value": 1
203
+ },
204
+ {
205
+ "reputationId": 2,
206
+ "value": 1
207
+ }
208
+ ],
209
+ "timestamp": "2021-11-22T11:55:35.341Z"
210
+ }
211
+ ]
212
+ }
213
+ ];
214
+ const ratingTest = require('./lib/ratings/index');
215
+
216
+
217
+ const test = ratingTest.getUserRecentRatings(data, undefined, 4);
218
+
219
+ console.log(test);