playov2-js-utilities 0.3.2 → 0.3.6

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/constants.js CHANGED
@@ -12,7 +12,10 @@ const RATINGS_WEIGHTAGE = Object.freeze({
12
12
  'old': 0.1
13
13
  });
14
14
 
15
+ const DEFAULT_TIME_ZONE = 'Asia/Kolkata';
16
+
15
17
  module.exports = {
16
18
  USER_INDIVIDUAL_RATINGS,
17
- RATINGS_WEIGHTAGE
19
+ RATINGS_WEIGHTAGE,
20
+ DEFAULT_TIME_ZONE
18
21
  }
package/lib/cron.js ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * This file will have all cron related utilities - (e.g. - schedulers etc.).
3
+ * Try to contain service common utilities here.
4
+ */
5
+ const Constants = require('./constants');
6
+ const { CronJob } = require('cron');
7
+ const Utils = require('./util')
8
+
9
+ const cronner = (
10
+ cronTime,
11
+ onTime = Utils.noop,
12
+ onComplete = Utils.noop,
13
+ timeZone = Constants.DEFAULT_TIME_ZONE,
14
+ context = this,
15
+ runOnInit,
16
+ utcOffset,
17
+ ) => {
18
+ const job = new CronJob({
19
+ cronTime,
20
+ // when the time specified by pattern is matched
21
+ onTick: onTime,
22
+ // onComplete
23
+ onComplete,
24
+ // whether the cron should start on constructor invoke (or whether .start() needs to be called)
25
+ start: false,
26
+ // timezone -> defaults to Asia/Kolkata
27
+ timeZone,
28
+ // the context to bind the onTime method to
29
+ context,
30
+ // flat to start cron on invocation of the module
31
+ runOnInit,
32
+ // the utc offset to run the cron at
33
+ utcOffset
34
+ });
35
+ job.start();
36
+ return job;
37
+ };
38
+
39
+ module.exports = {
40
+ cronner
41
+ };
42
+
43
+
package/lib/index.js CHANGED
@@ -1,10 +1,13 @@
1
1
 
2
- //Naming terminology - While exporting constants use PascalCase while exporting functions/methods use camelCase
2
+ /*
3
+ * Naming terminology - While exporting constants use PascalCase while exporting functions/methods use camelCase
4
+ */
3
5
  module.exports = {
4
- ratings : require('./ratings/index'),
5
- Constants : require('./constants'),
6
- playoUtils : require('./util'),
7
- NotificationTemplates : require('./notification-templates'),
6
+ ratings: require('./ratings/index'),
7
+ Constants: require('./constants'),
8
+ playoUtils: require('./util'),
9
+ NotificationTemplates: require('./notification-templates'),
8
10
  NotificationConfig: require('./notification.config'),
9
- httpRequest: require('./request')
11
+ httpRequest: require('./request'),
12
+ Cron: require('./cron')
10
13
  };
@@ -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: 'You have a new game request! 🙌',
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: '{{host_first_name}} has accepted your request! 🥳',
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: 'Your request has been declined. 😟',
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 to join! Join them now. 😀'
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: 'You have a new invite! 📩',
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: 'Your invite has been accepted! 🤝',
111
- text: '{{user_first_name}} has accepted your request for the {{sport_name}} game on {{date}}.',
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: 'Your invite has been declined. 😟',
126
- text: '{{user_first_name}} has declined your request for the {{sport_name}} game on {{date}}.',
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: 'Your invite has been cancelled 😕 ',
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: '{{user_first_name}} has a message for you! Tap to read',
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,16 @@ const host_cancelled_activity = {
204
204
  notificationId: notificationIds.ACTIVITY_CANCEL
205
205
  };
206
206
 
207
+ /**
208
+ *
209
+ */
210
+ const activity_reminder = {
211
+ heading: '⏰, Activity reminder!',
212
+ text: 'You have a {sport_name}} game coming up on {{date}}. Best of luck!',
213
+ buttons: [],
214
+ notificationId: notificationIds.ACTIVITY_REMINDER
215
+ };
216
+
207
217
  const host_updated_activity_details = {
208
218
  // ??
209
219
  };
@@ -228,5 +238,6 @@ module.exports = {
228
238
  host_revoked_invite,
229
239
  host_retired_user,
230
240
  user_left_game,
231
- host_cancelled_activity
241
+ host_cancelled_activity,
242
+ activity_reminder
232
243
  }
@@ -17,7 +17,8 @@ const notificationChannels = {
17
17
  'activity_suggestions': '3ab98c37-b93c-4d39-ab55-bb2cc6279cb8', // done - 1 notifications tagged
18
18
  'expenses': '1eb30f33-2b3b-40ce-8798-fce55c1275e2', // done - 6 notifications tagged
19
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
20
+ 'group_updates': '9e023a20-deab-4bc4-bd33-08a8d9316322', // done - 3 notifications tagged
21
+ 'activity_reminders': '53c55399-a73c-4800-b824-3c750ac57b98'
21
22
  };
22
23
 
23
24
  // ------------------------------------------ Exported (public) -----------------------------------------//
@@ -78,7 +79,8 @@ const notificationIds = {
78
79
  SPLIT_EXPENSE_DELETED: 'split-expense-deleted',
79
80
  HOST_ACTIVITY_PAYOUT: 'host-activity-payout',
80
81
  KARMA_CASHBACK: 'karma-cashback',
81
- ACTIVITY_QUERY_ANSWERED: 'activity-query-answered'
82
+ ACTIVITY_QUERY_ANSWERED: 'activity-query-answered',
83
+ ACTIVITY_REMINDER: 'activity-reminder'
82
84
  };
83
85
 
84
86
  // TODO - Check targets against current value
@@ -432,6 +434,14 @@ const config = {
432
434
  type: ["push", "drawer"],
433
435
  buttons: [],
434
436
  android_channel_id: notificationChannels.activity_query
437
+ },
438
+ [notificationIds.ACTIVITY_REMINDER] : {
439
+ category: notificationCategories.ACTIVITY,
440
+ target: "match",
441
+ title: "Activity Reminder",
442
+ type: ["push", "drawer"],
443
+ buttons: [],
444
+ android_channel_id: notificationChannels.activity_reminders
435
445
  }
436
446
  };
437
447
 
@@ -77,7 +77,7 @@ const getUserAverageRatingForASport = (currentAvg, prevAvg) => {
77
77
  let oldAvg = prevAvg ? prevAvg * Constants.RATINGS_WEIGHTAGE.old : 0;
78
78
 
79
79
  // If for any reason any player doesn't have any old rating/ new rating, send back both ratings with 100% weightage (as one of them will be zero)
80
- if (!prevAvg || !currentAvg) {
80
+ if (!prevAvg || !currentAvg) {
81
81
  latest25Avg = currentAvg;
82
82
  oldAvg = prevAvg;
83
83
  }
package/lib/util.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**\
2
2
  * This module is not imported in PlayoLib directly as there are already many imports in individual repositories
3
3
  * named util/utils and importing this alongside might cause unforeseen errors or poor readability
4
- * Ideally new repositories should import utils from here only. Todo- look for a workaround
4
+ * Ideally new repositories should import utils from here only. Todo- look for a workaround - named imports
5
5
  */
6
6
 
7
7
  /**
@@ -121,11 +121,16 @@ const getCategoricalBreakUpFromRecentUserRatings = (palRatingDict, levelCategori
121
121
  }
122
122
 
123
123
  return categoricalBreakUp;
124
+ };
125
+
126
+ const noop = () => {
127
+ return undefined;
124
128
  }
125
129
 
126
130
  module.exports = {
127
131
  getRatingsFromPlaypalDocs,
128
132
  findAverage,
129
133
  getRecentRatingDictOfPals,
130
- getCategoricalBreakUpFromRecentUserRatings
134
+ getCategoricalBreakUpFromRecentUserRatings,
135
+ noop
131
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playov2-js-utilities",
3
- "version": "0.3.2",
3
+ "version": "0.3.6",
4
4
  "description": "Private package for JS utility functions",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,6 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@playo/logger": "^0.9.18",
25
- "axios": "^0.24.0"
25
+ "axios": "^0.24.0",
26
+ "cron": "^1.8.2"
26
27
  }
27
28
  }
package/test.js DELETED
@@ -1,219 +0,0 @@
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);