playov2-js-utilities 0.3.70 → 0.3.73

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 +134 -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,24 +1,24 @@
1
- const {generatePlayoResponse} = require("./playo.res.generator");
2
- const LOGGER = require("../logger");
3
-
4
- const playoError = (error, sourceFunction = "") => {
5
- return {
6
- stack: error.stack,
7
- source: {
8
- sourceFunction,
9
- errorType: error.name || "Unknown error"
10
- },
11
- type: error.type
12
- }
13
- }
14
-
15
- const badResponseErrorHandler = (error, message = "", requestId) => {
16
- const {stack, source = {}} = error;
17
- LOGGER.prepareErrorLog(requestId, {errorStack: stack, source}, message);
18
- return generatePlayoResponse("BAD_REQUEST", 0, {message}, "OOPs!! something does not seem right, we are on it ;)");
19
- }
20
-
21
- module.exports = {
22
- badResponseErrorHandler,
23
- playoError
1
+ const {generatePlayoResponse} = require("./playo.res.generator");
2
+ const LOGGER = require("../logger");
3
+
4
+ const playoError = (error, sourceFunction = "") => {
5
+ return {
6
+ stack: error.stack,
7
+ source: {
8
+ sourceFunction,
9
+ errorType: error.name || "Unknown error"
10
+ },
11
+ type: error.type
12
+ }
13
+ }
14
+
15
+ const badResponseErrorHandler = (error, message = "", requestId) => {
16
+ const {stack, source = {}} = error;
17
+ LOGGER.prepareErrorLog(requestId, {errorStack: stack, source}, message);
18
+ return generatePlayoResponse("BAD_REQUEST", 0, {message}, "OOPs!! something does not seem right, we are on it ;)");
19
+ }
20
+
21
+ module.exports = {
22
+ badResponseErrorHandler,
23
+ playoError
24
24
  }
@@ -1,163 +1,163 @@
1
- const Axios = require('axios');
2
- const TIMEOUT_DURATION = 15 * 1000 // seconds, used as default
3
- const Logger = require('../logger.js');
4
-
5
-
6
- /**
7
- * Axios response handler
8
- * @param {Response} resp
9
- * resp structure |
10
- * on success {
11
- * status: HTTP status code returned by the service
12
- * data,
13
- * config: request config
14
- * }
15
- * on fail : {
16
- * code: error code | http errorcode like ECONNREFUSED, ETIMEOUT etc
17
- * message: error message | description of the error code
18
- * config: request config
19
- * }
20
- * @param {String} requestId
21
- * @returns
22
- */
23
- const playoResponseHandler = (resp, requestId) => {
24
-
25
- if(!resp) {
26
- resp = {
27
- isAxiosError: true,
28
- code: "NO_RESPONSE",
29
- message: "No response from the service",
30
- data : {requestStatus: 0}
31
- }
32
- }
33
-
34
- if (resp.isAxiosError) {
35
- //if axios error is triggered then axios throws HTTP code for timeout or other forms of unsuccessful errors
36
- const {
37
- code = "UNCAUGHT_ERROR",
38
- message = "encountered uncaught error",
39
- config = { url: '' },
40
- response = { data: { requestStatus: 0 } }
41
- } = resp;
42
- const { url } = config;
43
- const { data = { requestStatus: 0, statusError: "POTENTIAL-BAD-GATEWAY" } } = response;
44
- data["message"] = message;
45
- Logger.prepareErrorLog(requestId, { code, message }, `Api call to url to ${url} failed`)
46
- throw (data);
47
- }
48
-
49
- const { status, data = {requestStatus: null}, config = { url: '' } } = resp;
50
- const { url = '' } = config;
51
- if (status >= 200 && status < 400) {
52
- const { requestStatus, message = 'success' } = data;
53
- if (!requestStatus && requestStatus != 0) { //if the service does not provide request status
54
- data["requestStatus"] = 1;
55
- }
56
- Logger.prepareInfoLog(requestId, { status, requestStatus: data.requestStatus, message }, `Api call to url to ${url} succeeded with status ${status}`)
57
- return data
58
- }
59
-
60
- if(status >= 400) {
61
- Logger.prepareErrorLog(requestId, data, `Api call to url to ${url} failed`)
62
- throw (data);
63
- }
64
-
65
- else { // ideally this should not get triggered unless there is fault in calling lib itself
66
- Logger.prepareErrorLog(requestId, { response: resp }, "axios error");
67
- throw ({ requestStatus: 0, message: "Failed to handle response" })
68
- }
69
- }
70
-
71
-
72
- /**
73
- * Makes a get http request - throws error to be handled by calling function
74
- * @param {String} url
75
- * @param {Object} headers
76
- * @param {Object} query
77
- * @param {String} requestId
78
- * @param {Boolean} shouldTimeOut - Defaults to false
79
- * @param {Number} timeout - in seconds, Defaults to 10 seconds
80
- * @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
81
- */
82
- const get = async (url, headers = {}, query = {}, requestId = '', responseHandler = playoResponseHandler, timeout = TIMEOUT_DURATION, apiName = '') => {
83
- try {
84
- const resp = await Axios.get(url, { headers, params: query, timeout });
85
- return responseHandler(resp, requestId, apiName);
86
- } catch (error) {
87
- Logger.prepareErrorLog(requestId, { url, headers, query }, `Api call to url to ${url} failed!`);
88
- return responseHandler(error.response, requestId, apiName);
89
- }
90
- };
91
-
92
- /**
93
- * Makes a POST http request - throws error to be handled by calling function
94
- * @param {String} url
95
- * @param {Object} headers
96
- * @param {Object} query
97
- * @param {Object} body
98
- * @param {String} requestId
99
- * @param {Boolean} shouldTimeOut - Defaults to false
100
- * @param {Number} timeout - in seconds, Defaults to 10 seconds
101
- * @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
102
- */
103
- const post = async (url, headers = {}, query = {}, body = {}, requestId = '', responseHandler = playoResponseHandler, timeout = TIMEOUT_DURATION, apiName = '') => {
104
- try {
105
- const options = { headers, params: query, timeout };
106
- const resp = await Axios.post(url, body, options);
107
- return responseHandler(resp, requestId, apiName);
108
- } catch (error) {
109
- Logger.prepareErrorLog(requestId, { url, headers, query, body }, `Api call to url to ${url} failed due to ${error.response.message}`);
110
- return responseHandler(error.response, requestId, apiName);
111
- }
112
- };
113
-
114
- /**
115
- * Makes a PUT http request - throws error to be handled by calling function
116
- * @param {String} url
117
- * @param {Object} headers
118
- * @param {Object} query
119
- * @param {Object} body
120
- * @param {String} requestId
121
- * @param {Boolean} shouldTimeOut - Defaults to false
122
- * @param {Number} timeout - in seconds, Defaults to 10 seconds
123
- * @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
124
- */
125
- const put = async (url, headers = {}, query = {}, body = {}, requestId = '', responseHandler = playoResponseHandler, timeout = TIMEOUT_DURATION, apiName = '') => {
126
- try {
127
- const options = { headers, params: query, timeout };
128
- const resp = await Axios.put(url, body, options);
129
- return responseHandler(resp, requestId, apiName);
130
- } catch (error) {
131
- Logger.prepareErrorLog(requestId, { url, headers, query, body }, `Api call to url to ${url} failed due to ${error.response.message}`);
132
- return responseHandler(error.response, requestId, apiName);
133
- }
134
- };
135
-
136
- /**
137
- * Makes a DELETE http request - throws error to be handled by calling function
138
- * @param {String} url
139
- * @param {Object} headers
140
- * @param {Object} query
141
- * @param {Object} body
142
- * @param {String} requestId
143
- * @param {Boolean} shouldTimeOut - Defaults to false
144
- * @param {Number} timeout - in seconds, Defaults to 10 seconds
145
- * @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
146
- */
147
- const remove = async (url, headers = {}, query = {}, body, requestId = '', responseHandler = playoResponseHandler, timeout = TIMEOUT_DURATION) => {
148
- try {
149
- const options = { headers, params: query, data: body, timeout };
150
- const resp = await Axios.delete(url, options);
151
- return responseHandler(resp, requestId);
152
- } catch (error) {
153
- Logger.prepareErrorLog(requestId, { url, headers, query, body }, `Api call to url to ${url} failed due to ${error.response.message}`);
154
- return responseHandler(error.response, requestId, apiName);
155
- }
156
- };
157
-
158
- module.exports = {
159
- get,
160
- post,
161
- put,
162
- remove
1
+ const Axios = require('axios');
2
+ const TIMEOUT_DURATION = 15 * 1000 // seconds, used as default
3
+ const Logger = require('../logger.js');
4
+
5
+
6
+ /**
7
+ * Axios response handler
8
+ * @param {Response} resp
9
+ * resp structure |
10
+ * on success {
11
+ * status: HTTP status code returned by the service
12
+ * data,
13
+ * config: request config
14
+ * }
15
+ * on fail : {
16
+ * code: error code | http errorcode like ECONNREFUSED, ETIMEOUT etc
17
+ * message: error message | description of the error code
18
+ * config: request config
19
+ * }
20
+ * @param {String} requestId
21
+ * @returns
22
+ */
23
+ const playoResponseHandler = (resp, requestId) => {
24
+
25
+ if(!resp) {
26
+ resp = {
27
+ isAxiosError: true,
28
+ code: "NO_RESPONSE",
29
+ message: "No response from the service",
30
+ data : {requestStatus: 0}
31
+ }
32
+ }
33
+
34
+ if (resp.isAxiosError) {
35
+ //if axios error is triggered then axios throws HTTP code for timeout or other forms of unsuccessful errors
36
+ const {
37
+ code = "UNCAUGHT_ERROR",
38
+ message = "encountered uncaught error",
39
+ config = { url: '' },
40
+ response = { data: { requestStatus: 0 } }
41
+ } = resp;
42
+ const { url } = config;
43
+ const { data = { requestStatus: 0, statusError: "POTENTIAL-BAD-GATEWAY" } } = response;
44
+ data["message"] = message;
45
+ Logger.prepareErrorLog(requestId, { code, message }, `Api call to url to ${url} failed`)
46
+ throw (data);
47
+ }
48
+
49
+ const { status, data = {requestStatus: null}, config = { url: '' } } = resp;
50
+ const { url = '' } = config;
51
+ if (status >= 200 && status < 400) {
52
+ const { requestStatus, message = 'success' } = data;
53
+ if (!requestStatus && requestStatus != 0) { //if the service does not provide request status
54
+ data["requestStatus"] = 1;
55
+ }
56
+ Logger.prepareInfoLog(requestId, { status, requestStatus: data.requestStatus, message }, `Api call to url to ${url} succeeded with status ${status}`)
57
+ return data
58
+ }
59
+
60
+ if(status >= 400) {
61
+ Logger.prepareErrorLog(requestId, data, `Api call to url to ${url} failed`)
62
+ throw (data);
63
+ }
64
+
65
+ else { // ideally this should not get triggered unless there is fault in calling lib itself
66
+ Logger.prepareErrorLog(requestId, { response: resp }, "axios error");
67
+ throw ({ requestStatus: 0, message: "Failed to handle response" })
68
+ }
69
+ }
70
+
71
+
72
+ /**
73
+ * Makes a get http request - throws error to be handled by calling function
74
+ * @param {String} url
75
+ * @param {Object} headers
76
+ * @param {Object} query
77
+ * @param {String} requestId
78
+ * @param {Boolean} shouldTimeOut - Defaults to false
79
+ * @param {Number} timeout - in seconds, Defaults to 10 seconds
80
+ * @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
81
+ */
82
+ const get = async (url, headers = {}, query = {}, requestId = '', responseHandler = playoResponseHandler, timeout = TIMEOUT_DURATION, apiName = '') => {
83
+ try {
84
+ const resp = await Axios.get(url, { headers, params: query, timeout });
85
+ return responseHandler(resp, requestId, apiName);
86
+ } catch (error) {
87
+ Logger.prepareErrorLog(requestId, { url, headers, query }, `Api call to url to ${url} failed!`);
88
+ return responseHandler(error.response, requestId, apiName);
89
+ }
90
+ };
91
+
92
+ /**
93
+ * Makes a POST http request - throws error to be handled by calling function
94
+ * @param {String} url
95
+ * @param {Object} headers
96
+ * @param {Object} query
97
+ * @param {Object} body
98
+ * @param {String} requestId
99
+ * @param {Boolean} shouldTimeOut - Defaults to false
100
+ * @param {Number} timeout - in seconds, Defaults to 10 seconds
101
+ * @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
102
+ */
103
+ const post = async (url, headers = {}, query = {}, body = {}, requestId = '', responseHandler = playoResponseHandler, timeout = TIMEOUT_DURATION, apiName = '') => {
104
+ try {
105
+ const options = { headers, params: query, timeout };
106
+ const resp = await Axios.post(url, body, options);
107
+ return responseHandler(resp, requestId, apiName);
108
+ } catch (error) {
109
+ Logger.prepareErrorLog(requestId, { url, headers, query, body }, `Api call to url to ${url} failed due to ${error.response.message}`);
110
+ return responseHandler(error.response, requestId, apiName);
111
+ }
112
+ };
113
+
114
+ /**
115
+ * Makes a PUT http request - throws error to be handled by calling function
116
+ * @param {String} url
117
+ * @param {Object} headers
118
+ * @param {Object} query
119
+ * @param {Object} body
120
+ * @param {String} requestId
121
+ * @param {Boolean} shouldTimeOut - Defaults to false
122
+ * @param {Number} timeout - in seconds, Defaults to 10 seconds
123
+ * @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
124
+ */
125
+ const put = async (url, headers = {}, query = {}, body = {}, requestId = '', responseHandler = playoResponseHandler, timeout = TIMEOUT_DURATION, apiName = '') => {
126
+ try {
127
+ const options = { headers, params: query, timeout };
128
+ const resp = await Axios.put(url, body, options);
129
+ return responseHandler(resp, requestId, apiName);
130
+ } catch (error) {
131
+ Logger.prepareErrorLog(requestId, { url, headers, query, body }, `Api call to url to ${url} failed due to ${error.response.message}`);
132
+ return responseHandler(error.response, requestId, apiName);
133
+ }
134
+ };
135
+
136
+ /**
137
+ * Makes a DELETE http request - throws error to be handled by calling function
138
+ * @param {String} url
139
+ * @param {Object} headers
140
+ * @param {Object} query
141
+ * @param {Object} body
142
+ * @param {String} requestId
143
+ * @param {Boolean} shouldTimeOut - Defaults to false
144
+ * @param {Number} timeout - in seconds, Defaults to 10 seconds
145
+ * @param {Function} responseHandler - Caller should pass it's own http response handler. Defaults to playo's response function handler
146
+ */
147
+ const remove = async (url, headers = {}, query = {}, body, requestId = '', responseHandler = playoResponseHandler, timeout = TIMEOUT_DURATION) => {
148
+ try {
149
+ const options = { headers, params: query, data: body, timeout };
150
+ const resp = await Axios.delete(url, options);
151
+ return responseHandler(resp, requestId);
152
+ } catch (error) {
153
+ Logger.prepareErrorLog(requestId, { url, headers, query, body }, `Api call to url to ${url} failed due to ${error.response.message}`);
154
+ return responseHandler(error.response, requestId, apiName);
155
+ }
156
+ };
157
+
158
+ module.exports = {
159
+ get,
160
+ post,
161
+ put,
162
+ remove
163
163
  }
@@ -1,59 +1,59 @@
1
- // these file's functionality should be in utils.js file
2
- const httpStatusMap = {
3
- 'OK': 200,
4
- 'BAD_REQUEST': 400,
5
- 'URL_NOT_FOUND': 404,
6
- 'INTERNAL_ERROR': 500,
7
- };
8
-
9
- const responseStatusMessageMap = {
10
- 1: "Success",
11
- 0: "Failed",
12
- 2: "Invalid Request",
13
- 3: "warning",
14
- }
15
-
16
- /**
17
- * Function to generate dynamic playo response
18
- * @typedef {"OK" | "BAD_REQUEST" | "URL_NOT_FOUND" | "INTERNAL_ERROR" } httpMessage
19
- * @typedef {0 | 1 | 2 | 3} requestStatus
20
- * @param {httpMessage} httpMessage ['OK', 'BAD_REQUEST', 'URL_NOT_FOUND', 'INTERNAL_ERROR']
21
- * @param {requestStatus} requestStatus [0, 1, 2, 3]
22
- * @param {Object} jsonData
23
- * @param {String} customMessage
24
- * @returns {Object} -
25
- * {
26
- * httpStatus: 200,
27
- * httpMessage: 'Ok',
28
- * playoResponse: {
29
- * requestStatus: 1,
30
- * message: "Success",
31
- * data: {}
32
- * }
33
- * }
34
- */
35
- const generatePlayoResponse = (httpMessage = 'Ok', requestStatus = 1, jsonData = {}, customMessage = null, addOnJson = {}) => {
36
-
37
- const httpStatus = httpStatusMap[httpMessage] || 200;
38
-
39
- const playoResponse = {
40
- requestStatus,
41
- message: responseStatusMessageMap[requestStatus] || "Success",
42
- data: jsonData,
43
- ...addOnJson
44
- }
45
-
46
- if (customMessage) {
47
- playoResponse.message = customMessage;
48
- }
49
-
50
- return {
51
- httpStatus,
52
- httpMessage,
53
- playoResponse
54
- }
55
- }
56
-
57
- module.exports = {
58
- generatePlayoResponse
1
+ // these file's functionality should be in utils.js file
2
+ const httpStatusMap = {
3
+ 'OK': 200,
4
+ 'BAD_REQUEST': 400,
5
+ 'URL_NOT_FOUND': 404,
6
+ 'INTERNAL_ERROR': 500,
7
+ };
8
+
9
+ const responseStatusMessageMap = {
10
+ 1: "Success",
11
+ 0: "Failed",
12
+ 2: "Invalid Request",
13
+ 3: "warning",
14
+ }
15
+
16
+ /**
17
+ * Function to generate dynamic playo response
18
+ * @typedef {"OK" | "BAD_REQUEST" | "URL_NOT_FOUND" | "INTERNAL_ERROR" } httpMessage
19
+ * @typedef {0 | 1 | 2 | 3} requestStatus
20
+ * @param {httpMessage} httpMessage ['OK', 'BAD_REQUEST', 'URL_NOT_FOUND', 'INTERNAL_ERROR']
21
+ * @param {requestStatus} requestStatus [0, 1, 2, 3]
22
+ * @param {Object} jsonData
23
+ * @param {String} customMessage
24
+ * @returns {Object} -
25
+ * {
26
+ * httpStatus: 200,
27
+ * httpMessage: 'Ok',
28
+ * playoResponse: {
29
+ * requestStatus: 1,
30
+ * message: "Success",
31
+ * data: {}
32
+ * }
33
+ * }
34
+ */
35
+ const generatePlayoResponse = (httpMessage = 'Ok', requestStatus = 1, jsonData = {}, customMessage = null, addOnJson = {}) => {
36
+
37
+ const httpStatus = httpStatusMap[httpMessage] || 200;
38
+
39
+ const playoResponse = {
40
+ requestStatus,
41
+ message: responseStatusMessageMap[requestStatus] || "Success",
42
+ data: jsonData,
43
+ ...addOnJson
44
+ }
45
+
46
+ if (customMessage) {
47
+ playoResponse.message = customMessage;
48
+ }
49
+
50
+ return {
51
+ httpStatus,
52
+ httpMessage,
53
+ playoResponse
54
+ }
55
+ }
56
+
57
+ module.exports = {
58
+ generatePlayoResponse
59
59
  }
@@ -1,16 +1,15 @@
1
- const { profanityWords } = require("./profanityWords");
2
- const Filter = require("bad-words");
3
- const profanityFilter = new Filter();
4
- const profanityWordList = profanityWords.split(",");
5
-
6
- const excludeWords = ["dink", "dings", "swastik", "swastika", "islam"];
7
-
8
- profanityFilter.addWords(...profanityWordList);
9
- profanityFilter.removeWords(...excludeWords);
10
-
11
- const checkProfanity = (message) => {
12
- return profanityFilter.isProfane(message);
13
- };
14
-
15
- module.exports = { checkProfanity };
16
-
1
+ const {profanityWords} = require("./profanityWords");
2
+ const Filter = require("bad-words");
3
+ const profanityFilter = new Filter();
4
+ const profanityWordList = profanityWords.split(",");
5
+
6
+ const excludeWords = ['swastik', 'swastika', 'islam'];
7
+
8
+ profanityFilter.addWords(...profanityWordList);
9
+ profanityFilter.removeWords(...excludeWords)
10
+
11
+ const checkProfanity = (message) => {
12
+ return profanityFilter.isProfane(message);
13
+ }
14
+
15
+ module.exports = { checkProfanity }