playov2-js-utilities 0.3.70 → 0.3.74

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.
Files changed (82) hide show
  1. package/README.md +28 -28
  2. package/index.js +4 -4
  3. package/lib/constants.js +20 -20
  4. package/lib/cron.js +43 -43
  5. package/lib/db/models/user.js +112 -0
  6. package/lib/db/mongo.js +3 -0
  7. package/lib/db_interface/mongo/index.js +5 -5
  8. package/lib/db_interface/mongo/schemas/activitySchemas/_activityIndex.js +10 -10
  9. package/lib/db_interface/mongo/schemas/activitySchemas/activityInsurance.js +17 -17
  10. package/lib/db_interface/mongo/schemas/activitySchemas/activityLocation.js +104 -104
  11. package/lib/db_interface/mongo/schemas/activitySchemas/activityQueryBlock.js +11 -11
  12. package/lib/db_interface/mongo/schemas/activitySchemas/activityView.js +13 -13
  13. package/lib/db_interface/mongo/schemas/activitySchemas/cronJobLog.js +12 -12
  14. package/lib/db_interface/mongo/schemas/activitySchemas/playogame.request.js +37 -37
  15. package/lib/db_interface/mongo/schemas/activitySchemas/scheduled.tasks.js +52 -52
  16. package/lib/db_interface/mongo/schemas/activitySchemas/userActivity.js +133 -133
  17. package/lib/db_interface/mongo/schemas/gamebookSchemas/_gamebookIndex.js +2 -2
  18. package/lib/db_interface/mongo/schemas/gamebookSchemas/activityNotes.js +19 -19
  19. package/lib/db_interface/mongo/schemas/gamebookSchemas/expense.js +36 -36
  20. package/lib/db_interface/mongo/schemas/gamebookSchemas/expenseLogs.js +13 -13
  21. package/lib/db_interface/mongo/schemas/gamebookSchemas/message.requests.js +29 -29
  22. package/lib/db_interface/mongo/schemas/gamebookSchemas/nonPlayoExpenseUsers.js +14 -14
  23. package/lib/db_interface/mongo/schemas/gamebookSchemas/playpals.js +69 -69
  24. package/lib/db_interface/mongo/schemas/gamebookSchemas/postActivity.js +51 -51
  25. package/lib/db_interface/mongo/schemas/gamebookSchemas/tags.js +12 -12
  26. package/lib/db_interface/mongo/schemas/userSchemas/QuickActions.js +25 -25
  27. package/lib/db_interface/mongo/schemas/userSchemas/_userIndex.js +7 -7
  28. package/lib/db_interface/mongo/schemas/userSchemas/blockedUser.js +11 -11
  29. package/lib/db_interface/mongo/schemas/userSchemas/city.js +62 -62
  30. package/lib/db_interface/mongo/schemas/userSchemas/country.js +63 -63
  31. package/lib/db_interface/mongo/schemas/userSchemas/emailOtp.js +12 -12
  32. package/lib/db_interface/mongo/schemas/userSchemas/emailVerificationToken.js +11 -11
  33. package/lib/db_interface/mongo/schemas/userSchemas/gt.trial.games.js +24 -24
  34. package/lib/db_interface/mongo/schemas/userSchemas/invite.js +14 -14
  35. package/lib/db_interface/mongo/schemas/userSchemas/karmaConfig.js +11 -11
  36. package/lib/db_interface/mongo/schemas/userSchemas/karmaLog.js +28 -28
  37. package/lib/db_interface/mongo/schemas/userSchemas/passwordResetToken.js +11 -11
  38. package/lib/db_interface/mongo/schemas/userSchemas/playo.subscription.pack.js +67 -67
  39. package/lib/db_interface/mongo/schemas/userSchemas/rankings.js +16 -16
  40. package/lib/db_interface/mongo/schemas/userSchemas/sports.js +26 -26
  41. package/lib/db_interface/mongo/schemas/userSchemas/sportsCategory.js +11 -11
  42. package/lib/db_interface/mongo/schemas/userSchemas/tempUser.js +35 -35
  43. package/lib/db_interface/mongo/schemas/userSchemas/trendingSports.js +14 -14
  44. package/lib/db_interface/mongo/schemas/userSchemas/user.activity.health.kit.data.js +26 -26
  45. package/lib/db_interface/mongo/schemas/userSchemas/user.contacts.js +33 -33
  46. package/lib/db_interface/mongo/schemas/userSchemas/user.js +111 -111
  47. package/lib/db_interface/mongo/schemas/userSchemas/userAlerts.js +23 -23
  48. package/lib/db_interface/mongo/schemas/userSchemas/userCredentials.js +50 -50
  49. package/lib/db_interface/mongo/schemas/userSchemas/userFavourites.js +81 -81
  50. package/lib/db_interface/mongo/schemas/userSchemas/userOtp.js +9 -9
  51. package/lib/db_interface/mongo/schemas/userSchemas/userReputation.js +21 -21
  52. package/lib/db_interface/mongo/schemas/userSchemas/userSocial.js +17 -17
  53. package/lib/db_interface/mongo/schemas/userSchemas/year.in.playo.js +51 -51
  54. package/lib/db_interface/mongo/schemas/venueSchemas/_venueIndex.js +3 -3
  55. package/lib/db_interface/mongo/schemas/venueSchemas/ameneties.js +9 -9
  56. package/lib/db_interface/mongo/schemas/venueSchemas/cityArea.js +45 -45
  57. package/lib/db_interface/mongo/schemas/venueSchemas/clubConstraints.js +17 -17
  58. package/lib/db_interface/mongo/schemas/venueSchemas/corporateOffer.js +17 -17
  59. package/lib/db_interface/mongo/schemas/venueSchemas/couponOffers.js +39 -39
  60. package/lib/db_interface/mongo/schemas/venueSchemas/gamebagMember.js +11 -11
  61. package/lib/db_interface/mongo/schemas/venueSchemas/offer.js +48 -48
  62. package/lib/db_interface/mongo/schemas/venueSchemas/thirdParty.js +12 -12
  63. package/lib/db_interface/mongo/schemas/venueSchemas/venue.js +136 -134
  64. package/lib/db_interface/mongo/schemas/venueSchemas/venueEnquires.js +22 -22
  65. package/lib/db_interface/mongo/schemas/venueSchemas/venueMembers.js +14 -14
  66. package/lib/db_interface/mongo/schemas/venueSchemas/venueRating.js +18 -18
  67. package/lib/index.js +22 -23
  68. package/lib/logger.js +115 -115
  69. package/lib/message_publisher/index.js +144 -144
  70. package/lib/middleware.js +46 -46
  71. package/lib/notification-templates.js +254 -254
  72. package/lib/notification.config.js +476 -476
  73. package/lib/playo.utils/playo.error.handler.js +23 -23
  74. package/lib/playo.utils/playo.http.handler.js +162 -162
  75. package/lib/playo.utils/playo.res.generator.js +58 -58
  76. package/lib/profanityFilter/profanityFilter.js +15 -16
  77. package/lib/profanityFilter/profanityWords.js +2 -2
  78. package/lib/ratings/index.js +95 -95
  79. package/lib/request.js +135 -135
  80. package/lib/responseHandler/responseHandler.js +52 -52
  81. package/lib/util.js +151 -151
  82. package/package.json +36 -36
@@ -1,53 +1,53 @@
1
- const Logger = require("../logger");
2
-
3
- /**
4
- * Axios response handler
5
- * @param {Response} resp
6
- * resp structure |
7
- * on success {
8
- * status: HTTP status code returned by the service
9
- * data,
10
- * config: request config
11
- * }
12
- * on fail : {
13
- * code: error code | http errorcode like ECONNREFUSED, ETIMEOUT etc
14
- * message: error message | description of the error code
15
- * config: request config
16
- * }
17
- * @param {String} requestId
18
- * @returns
19
- */
20
- const responseHandler = (resp, requestId) => {
21
- if (resp.isAxiosError) {
22
- //if axios error is triggered then axios throws HTTP code for timeout or other forms of unsuccessful errors
23
- const {
24
- code = "UNCAUGHT_ERROR",
25
- message = "encountered uncaught error",
26
- config = { url: '' },
27
- response = { data: { requestStatus: 0 } }
28
- } = resp;
29
- const { url } = config;
30
- const { data = { requestStatus: 0, statusError: "POTENTIAL-BAD-GATEWAY" }} = response;
31
- data["message"] = message;
32
- Logger.prepareErrorLog(requestId, { code, message }, `Api call to url to ${url} failed`)
33
- throw (data);
34
- }
35
-
36
- const { status, data, config = { url: '' } } = resp;
37
- const { url = '' } = config;
38
- if (status >= 200 && status < 400) {
39
- const { requestStatus, message = 'success' } = data;
40
- if (!requestStatus && requestStatus != 0) { //if the service does not provide request status
41
- data["requestStatus"] = 1;
42
- }
43
- Logger.prepareInfoLog(requestId, { status, requestStatus: data.requestStatus, message }, `Api call to url to ${url} succeeded with status ${status}`)
44
- return data
45
- }
46
-
47
- else { // ideally this should not get triggered unless there is fault in calling lib itself
48
- Logger.prepareErrorLog(requestId, { response: resp }, "axios error");
49
- throw ({ requestStatus: 0, message: "Failed to handle response" })
50
- }
51
- }
52
-
1
+ const Logger = require("../logger");
2
+
3
+ /**
4
+ * Axios response handler
5
+ * @param {Response} resp
6
+ * resp structure |
7
+ * on success {
8
+ * status: HTTP status code returned by the service
9
+ * data,
10
+ * config: request config
11
+ * }
12
+ * on fail : {
13
+ * code: error code | http errorcode like ECONNREFUSED, ETIMEOUT etc
14
+ * message: error message | description of the error code
15
+ * config: request config
16
+ * }
17
+ * @param {String} requestId
18
+ * @returns
19
+ */
20
+ const responseHandler = (resp, requestId) => {
21
+ if (resp.isAxiosError) {
22
+ //if axios error is triggered then axios throws HTTP code for timeout or other forms of unsuccessful errors
23
+ const {
24
+ code = "UNCAUGHT_ERROR",
25
+ message = "encountered uncaught error",
26
+ config = { url: '' },
27
+ response = { data: { requestStatus: 0 } }
28
+ } = resp;
29
+ const { url } = config;
30
+ const { data = { requestStatus: 0, statusError: "POTENTIAL-BAD-GATEWAY" }} = response;
31
+ data["message"] = message;
32
+ Logger.prepareErrorLog(requestId, { code, message }, `Api call to url to ${url} failed`)
33
+ throw (data);
34
+ }
35
+
36
+ const { status, data, config = { url: '' } } = resp;
37
+ const { url = '' } = config;
38
+ if (status >= 200 && status < 400) {
39
+ const { requestStatus, message = 'success' } = data;
40
+ if (!requestStatus && requestStatus != 0) { //if the service does not provide request status
41
+ data["requestStatus"] = 1;
42
+ }
43
+ Logger.prepareInfoLog(requestId, { status, requestStatus: data.requestStatus, message }, `Api call to url to ${url} succeeded with status ${status}`)
44
+ return data
45
+ }
46
+
47
+ else { // ideally this should not get triggered unless there is fault in calling lib itself
48
+ Logger.prepareErrorLog(requestId, { response: resp }, "axios error");
49
+ throw ({ requestStatus: 0, message: "Failed to handle response" })
50
+ }
51
+ }
52
+
53
53
  module.exports = { responseHandler }
package/lib/util.js CHANGED
@@ -1,152 +1,152 @@
1
- /**\
2
- * This module is not imported in PlayoLib directly as there are already many imports in individual repositories
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 - named imports
5
- */
6
-
7
- const hbs = require('handlebars');
8
-
9
- /**
10
- * Finds rating given to a user for a sport by playpals <Assumes playpalDocs supplied are already filtered for a user>
11
- * @param {Array} playpalDocs
12
- * @param {String} sportId
13
- * @returns {Array<Number>}
14
- */
15
- const getRatingsFromPlaypalDocs = (playpalDocs = [], sport) => {
16
- const ratings = [];
17
-
18
- for (const playpalDoc of playpalDocs) {
19
- if (playpalDoc.ratings && Array.isArray(playpalDoc.ratings)) {
20
- for (const ratingData of playpalDoc.ratings) {
21
- const { rating, sportId } = ratingData;
22
- if (rating && sportId && sportId === sport) {
23
- ratings.push(rating);
24
- continue;
25
- }
26
- }
27
- }
28
- }
29
- return ratings;
30
- };
31
-
32
-
33
- /**
34
- * Returns average of an array of numbers
35
- * @param {Array<Number>} arr
36
- */
37
- const findAverage = (arr = []) => {
38
-
39
- if (arr.length === 0) {
40
- return 0;
41
- }
42
-
43
- let sum = 0;
44
-
45
- for (const num of arr) {
46
- if (typeof num === 'number') {
47
- sum += num;
48
- }
49
- }
50
-
51
- const avg = sum / (arr.length);
52
-
53
- return avg;
54
- };
55
-
56
- /**
57
- *
58
- * @param {Array<PostActivityDoc>} postActivityDocs - Assumes this is filtered for a particular sport
59
- * @return {
60
- * palId: {
61
- * rating: Number (Most recent),
62
- * timestamp
63
- * }
64
- * }
65
- */
66
- const getRecentRatingDictOfPals = (postActivityDocs) => {
67
-
68
- const palRatingDict = {};
69
-
70
- postActivityDocs.forEach((postActivityDoc) => {
71
-
72
- // pals array contains ratings object as per given by other playpals for a particular activity, check schema for further details
73
- const { pals = [] } = postActivityDoc;
74
-
75
- /**
76
- * Description for code below we are try to get a dictionary of latest non-zero rating the user has received to be processed later
77
- */
78
- if (Array.isArray(pals)) {
79
- pals.forEach((palRating) => {
80
- const { palId = '', rating = 0, timestamp } = palRating;
81
- if (!palRatingDict[palId] && rating > 0) { // only consider pals who have rated the user
82
- palRatingDict[palId] = {
83
- rating: rating,
84
- timestamp: timestamp
85
- }
86
- } else if (palRatingDict[palId] && timestamp >= palRatingDict[palId]["timestamp"] && rating > 0) {
87
- // If user received any rating more recent then consider that instead
88
- palRatingDict[palId]["rating"] = rating;
89
- }
90
- });
91
- }
92
- });
93
-
94
- return palRatingDict;
95
- };
96
-
97
- /**
98
- * Returns categorical breakup of ratings the user received - data source - post activity docs
99
- * @param {*} palRatingDict
100
- * @param {*} levelCategories
101
- * @returns
102
- */
103
- const getCategoricalBreakUpFromRecentUserRatings = (palRatingDict, levelCategories) => {
104
- const categoricalBreakUp = {};
105
-
106
- for (let pal in palRatingDict) {
107
- const level = palRatingDict[pal].rating;
108
-
109
- if (levelCategories[level]) {
110
- if (!categoricalBreakUp[levelCategories[level]]) {
111
- categoricalBreakUp[levelCategories[level]] = 1;
112
- } else {
113
- categoricalBreakUp[levelCategories[level]] += 1;
114
- }
115
- }
116
- }
117
-
118
- // Inject default zero rating for non-rated levels
119
- for (level in levelCategories) {
120
- if (!categoricalBreakUp[levelCategories[level]]) {
121
- categoricalBreakUp[levelCategories[level]] = 0;
122
- }
123
- }
124
-
125
- return categoricalBreakUp;
126
- };
127
-
128
- const noop = () => {
129
- return undefined;
130
- };
131
-
132
- /**
133
- *
134
- * @param {String} template - Handlebars compatible template
135
- * @param {Object} data - Data points containing key value pairs of data required in template supplied
136
- * @returns {String}
137
- */
138
- const renderTemplate = (template, data) => {
139
-
140
- const temp = hbs.compile(template);
141
-
142
- return temp(data);
143
- };
144
-
145
- module.exports = {
146
- getRatingsFromPlaypalDocs,
147
- findAverage,
148
- getRecentRatingDictOfPals,
149
- getCategoricalBreakUpFromRecentUserRatings,
150
- noop,
151
- renderTemplate
1
+ /**\
2
+ * This module is not imported in PlayoLib directly as there are already many imports in individual repositories
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 - named imports
5
+ */
6
+
7
+ const hbs = require('handlebars');
8
+
9
+ /**
10
+ * Finds rating given to a user for a sport by playpals <Assumes playpalDocs supplied are already filtered for a user>
11
+ * @param {Array} playpalDocs
12
+ * @param {String} sportId
13
+ * @returns {Array<Number>}
14
+ */
15
+ const getRatingsFromPlaypalDocs = (playpalDocs = [], sport) => {
16
+ const ratings = [];
17
+
18
+ for (const playpalDoc of playpalDocs) {
19
+ if (playpalDoc.ratings && Array.isArray(playpalDoc.ratings)) {
20
+ for (const ratingData of playpalDoc.ratings) {
21
+ const { rating, sportId } = ratingData;
22
+ if (rating && sportId && sportId === sport) {
23
+ ratings.push(rating);
24
+ continue;
25
+ }
26
+ }
27
+ }
28
+ }
29
+ return ratings;
30
+ };
31
+
32
+
33
+ /**
34
+ * Returns average of an array of numbers
35
+ * @param {Array<Number>} arr
36
+ */
37
+ const findAverage = (arr = []) => {
38
+
39
+ if (arr.length === 0) {
40
+ return 0;
41
+ }
42
+
43
+ let sum = 0;
44
+
45
+ for (const num of arr) {
46
+ if (typeof num === 'number') {
47
+ sum += num;
48
+ }
49
+ }
50
+
51
+ const avg = sum / (arr.length);
52
+
53
+ return avg;
54
+ };
55
+
56
+ /**
57
+ *
58
+ * @param {Array<PostActivityDoc>} postActivityDocs - Assumes this is filtered for a particular sport
59
+ * @return {
60
+ * palId: {
61
+ * rating: Number (Most recent),
62
+ * timestamp
63
+ * }
64
+ * }
65
+ */
66
+ const getRecentRatingDictOfPals = (postActivityDocs) => {
67
+
68
+ const palRatingDict = {};
69
+
70
+ postActivityDocs.forEach((postActivityDoc) => {
71
+
72
+ // pals array contains ratings object as per given by other playpals for a particular activity, check schema for further details
73
+ const { pals = [] } = postActivityDoc;
74
+
75
+ /**
76
+ * Description for code below we are try to get a dictionary of latest non-zero rating the user has received to be processed later
77
+ */
78
+ if (Array.isArray(pals)) {
79
+ pals.forEach((palRating) => {
80
+ const { palId = '', rating = 0, timestamp } = palRating;
81
+ if (!palRatingDict[palId] && rating > 0) { // only consider pals who have rated the user
82
+ palRatingDict[palId] = {
83
+ rating: rating,
84
+ timestamp: timestamp
85
+ }
86
+ } else if (palRatingDict[palId] && timestamp >= palRatingDict[palId]["timestamp"] && rating > 0) {
87
+ // If user received any rating more recent then consider that instead
88
+ palRatingDict[palId]["rating"] = rating;
89
+ }
90
+ });
91
+ }
92
+ });
93
+
94
+ return palRatingDict;
95
+ };
96
+
97
+ /**
98
+ * Returns categorical breakup of ratings the user received - data source - post activity docs
99
+ * @param {*} palRatingDict
100
+ * @param {*} levelCategories
101
+ * @returns
102
+ */
103
+ const getCategoricalBreakUpFromRecentUserRatings = (palRatingDict, levelCategories) => {
104
+ const categoricalBreakUp = {};
105
+
106
+ for (let pal in palRatingDict) {
107
+ const level = palRatingDict[pal].rating;
108
+
109
+ if (levelCategories[level]) {
110
+ if (!categoricalBreakUp[levelCategories[level]]) {
111
+ categoricalBreakUp[levelCategories[level]] = 1;
112
+ } else {
113
+ categoricalBreakUp[levelCategories[level]] += 1;
114
+ }
115
+ }
116
+ }
117
+
118
+ // Inject default zero rating for non-rated levels
119
+ for (level in levelCategories) {
120
+ if (!categoricalBreakUp[levelCategories[level]]) {
121
+ categoricalBreakUp[levelCategories[level]] = 0;
122
+ }
123
+ }
124
+
125
+ return categoricalBreakUp;
126
+ };
127
+
128
+ const noop = () => {
129
+ return undefined;
130
+ };
131
+
132
+ /**
133
+ *
134
+ * @param {String} template - Handlebars compatible template
135
+ * @param {Object} data - Data points containing key value pairs of data required in template supplied
136
+ * @returns {String}
137
+ */
138
+ const renderTemplate = (template, data) => {
139
+
140
+ const temp = hbs.compile(template);
141
+
142
+ return temp(data);
143
+ };
144
+
145
+ module.exports = {
146
+ getRatingsFromPlaypalDocs,
147
+ findAverage,
148
+ getRecentRatingDictOfPals,
149
+ getCategoricalBreakUpFromRecentUserRatings,
150
+ noop,
151
+ renderTemplate
152
152
  };
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
- {
2
- "name": "playov2-js-utilities",
3
- "version": "0.3.70",
4
- "description": "Private package for JS utility functions",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "npm test"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+ssh://git@bitbucket.org/techmash/playov2-js-utilities.git"
12
- },
13
- "keywords": [
14
- "Playo"
15
- ],
16
- "author": "Avish",
17
- "license": "ISC",
18
- "homepage": "https://bitbucket.org/techmash/playov2-js-utilities#readme",
19
- "devDependencies": {
20
- "@types/uuid": "^8.3.4",
21
- "faker": "^5.5.3",
22
- "jest": "^27.1.0"
23
- },
24
- "dependencies": {
25
- "@google-cloud/tasks": "^2.5.0",
26
- "@playo/logger": "^0.9.24",
27
- "axios": "^0.24.0",
28
- "bad-words": "^3.0.4",
29
- "cron": "^1.8.2",
30
- "googleapis": "^109.0.1",
31
- "handlebars": "^4.7.7",
32
- "moment": "^2.29.4",
33
- "mongoose": "8.4.5",
34
- "uuid": "^8.3.2"
35
- }
36
- }
1
+ {
2
+ "name": "playov2-js-utilities",
3
+ "version": "0.3.74",
4
+ "description": "Private package for JS utility functions",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "npm test"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@bitbucket.org/techmash/playov2-js-utilities.git"
12
+ },
13
+ "keywords": [
14
+ "Playo"
15
+ ],
16
+ "author": "Avish",
17
+ "license": "ISC",
18
+ "homepage": "https://bitbucket.org/techmash/playov2-js-utilities#readme",
19
+ "devDependencies": {
20
+ "@types/uuid": "^8.3.4",
21
+ "faker": "^5.5.3",
22
+ "jest": "^27.1.0"
23
+ },
24
+ "dependencies": {
25
+ "@google-cloud/tasks": "^2.5.0",
26
+ "@playo/logger": "^0.9.24",
27
+ "axios": "^0.24.0",
28
+ "bad-words": "^3.0.4",
29
+ "cron": "^1.8.2",
30
+ "googleapis": "^109.0.1",
31
+ "handlebars": "^4.7.7",
32
+ "moment": "^2.29.4",
33
+ "mongoose": "8.4.5",
34
+ "uuid": "^8.3.2"
35
+ }
36
+ }