playov2-js-utilities 0.3.5 → 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
  };
@@ -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.5",
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
  }