playov2-js-utilities 0.3.3 → 0.3.7
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 +4 -1
- package/lib/cron.js +43 -0
- package/lib/index.js +10 -6
- package/lib/message_publisher/index.js +70 -0
- package/lib/notification-templates.js +12 -1
- package/lib/notification.config.js +12 -2
- package/lib/ratings/index.js +1 -1
- package/lib/util.js +7 -2
- package/package.json +4 -2
- package/test.js +0 -8
package/lib/constants.js
CHANGED
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,14 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
2
|
+
/*
|
|
3
|
+
* Naming terminology - While exporting constants use PascalCase while exporting functions/methods use camelCase
|
|
4
|
+
*/
|
|
3
5
|
module.exports = {
|
|
4
|
-
ratings
|
|
5
|
-
Constants
|
|
6
|
-
playoUtils
|
|
7
|
-
NotificationTemplates
|
|
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'),
|
|
13
|
+
MessagePublisher: require('./message_publisher')
|
|
10
14
|
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
const { CloudTasksClient } = require('@google-cloud/tasks');
|
|
4
|
+
|
|
5
|
+
const PLAYO_LOGGER = require("@playo/logger");
|
|
6
|
+
const LOGGER = new PLAYO_LOGGER("playo-message-publisher");
|
|
7
|
+
|
|
8
|
+
// Instantiates a client.
|
|
9
|
+
const client = new CloudTasksClient();
|
|
10
|
+
|
|
11
|
+
const PROJECT = process.env.GCP_PROJECT;
|
|
12
|
+
const LOCATION = process.env.GCP_LOCATION;
|
|
13
|
+
|
|
14
|
+
if (!PROJECT || !LOCATION) {
|
|
15
|
+
console.warn('You need to pass - GCP_PROJECT, GCP_LOCATION in env for message queue to work!');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param {String} queueId - Name of the queue being targeted
|
|
20
|
+
* @param {Object} payload - {
|
|
21
|
+
* httpMethod: String <POST, GET, PUT>
|
|
22
|
+
* url: String,
|
|
23
|
+
* headers: Object,
|
|
24
|
+
* body: Object, // not needed if GET request
|
|
25
|
+
* ...
|
|
26
|
+
*
|
|
27
|
+
* }
|
|
28
|
+
* @param {Object} messageProcessingProperties - {
|
|
29
|
+
* delay
|
|
30
|
+
* }
|
|
31
|
+
* @param {String} requestId
|
|
32
|
+
*/
|
|
33
|
+
async function createHttpTask(queueId, payload, messageProcessingProperties, requestId) {
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const project = PROJECT;
|
|
37
|
+
const queue = queueId;
|
|
38
|
+
const location = LOCATION;
|
|
39
|
+
|
|
40
|
+
const { delay = 0 } = messageProcessingProperties
|
|
41
|
+
|
|
42
|
+
const parent = client.queuePath(project, location, queue);
|
|
43
|
+
|
|
44
|
+
const task = { httpRequest: payload };
|
|
45
|
+
|
|
46
|
+
if (payload.body) {
|
|
47
|
+
task.httpRequest.body = Buffer.from(payload.body).toString('base64');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (delay) {
|
|
51
|
+
// The time when the task is scheduled to be attempted.
|
|
52
|
+
task.scheduleTime = {
|
|
53
|
+
seconds: delay + Date.now() / 1000,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Send create task request.
|
|
58
|
+
LOGGER.info(requestId, task, `Sending task to queue ${queueId}}`)
|
|
59
|
+
|
|
60
|
+
const request = { parent: parent, task: task };
|
|
61
|
+
const [response] = await client.createTask(request);
|
|
62
|
+
LOGGER.info(requestId, { name: response.name }, `Added task to queue ${queueId}}`)
|
|
63
|
+
} catch (err) {
|
|
64
|
+
LOGGER.error(requestId, err, err.message)
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
module.exports = {
|
|
69
|
+
createHttpTask
|
|
70
|
+
};
|
|
@@ -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
|
|
package/lib/ratings/index.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Private package for JS utility functions",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
"jest": "^27.1.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"@google-cloud/tasks": "^2.5.0",
|
|
24
25
|
"@playo/logger": "^0.9.18",
|
|
25
|
-
"axios": "^0.24.0"
|
|
26
|
+
"axios": "^0.24.0",
|
|
27
|
+
"cron": "^1.8.2"
|
|
26
28
|
}
|
|
27
29
|
}
|
package/test.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const data = [{"_id":"619b64773f930c6f90778f94","location":"Indiranagar","hostId":"1b7887d3-8255-409b-9efe-89b64b701862","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":false,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"9a8942e0-9778-4c43-befd-c8f7de4d3985","sportId":"SP5","date":"2021-11-22T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"firstRatedOn":"2021-11-22T09:36:20.000Z","isRemoved":false,"userPresent":null,"palId":"1b7887d3-8255-409b-9efe-89b64b701862","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2021-11-22T09:36:20.000Z"}],"createdTS":"2021-11-22T09:35:51.013Z","modTS":"2021-11-22T09:36:20.095Z","__v":0},{"_id":"619b6c5b8fff1950a20adae2","location":"Jayanagar, Bengaluru","hostId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"5161229a-e82d-498a-beed-8e2bc50bcaf7","sportId":"SP5","date":"2021-11-22T00:00:00.000Z","timing":1,"pals":[{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-11-22T10:09:31.719Z"},{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"1b7887d3-8255-409b-9efe-89b64b701862","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-11-22T10:24:02.000Z"}],"createdTS":"2021-11-22T10:09:31.719Z","modTS":"2021-11-22T11:26:49.742Z","__v":0},{"_id":"619b85378fff1950a20adaf0","location":"Indiranagar","hostId":"1b7887d3-8255-409b-9efe-89b64b701862","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"00f9ff64-214c-470d-b7fb-760a6a3af8e0","sportId":"SP5","date":"2021-11-22T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"1b7887d3-8255-409b-9efe-89b64b701862","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2021-11-22T12:00:26.000Z"},{"noshow":false,"noshowSwitch":false,"rating":3,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2021-11-22T12:02:57.000Z"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"88d8e6ed-207a-4b98-ace7-73a7bd6bc900","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-11-22T11:55:35.344Z"}],"createdTS":"2021-11-22T11:55:35.345Z","modTS":"2021-11-22T12:09:46.320Z","__v":0},{"_id":"612502919345581b9bd0246b","location":"Maker, Bihar, India","hostId":"65a91715-396c-4049-a952-2cc56a100f4a","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"4dbf9ef5-c3a7-4542-8a6d-9241a02b4965","sportId":"SP5","date":"2021-08-24T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":true,"isRemoved":false,"userPresent":null,"palId":"65a91715-396c-4049-a952-2cc56a100f4a","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-08-24T14:30:41.439Z"},{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"isRemoved":false,"userPresent":null,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-08-24T14:31:01.000Z"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":true,"userPresent":null,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-08-24T14:30:41.439Z","userName":"playo user"}],"createdTS":"2021-08-24T14:30:41.439Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"6038ffa7cc84a76c119f1333","location":"Maker, Bihar","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"a1c4ae44-2667-42f9-ac37-dd173b2fa3b1","sportId":"SP5","date":"2021-02-26T00:00:00.000Z","startTime":"2021-02-26T14:00:00.916Z","endTime":"2021-02-26T14:30:00.916Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-02-26T14:03:19.486Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":true,"palId":"54fe8420-dae7-4bb2-aa08-320b7dc40794","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-02-26T14:03:19.485Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"isRemoved":false,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-02-26T14:04:25.000Z"}],"createdTS":"2021-02-26T14:03:19.486Z","modTS":"2021-11-18T07:09:26.826Z","__v":0},{"_id":"6015a56cc8be9072376d7f0d","location":"Maker, Bihar","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"00879220-bd24-4635-add2-ce4b997be0fe","sportId":"SP5","date":"2021-01-30T00:00:00.000Z","timing":3,"pals":[{"noshow":false,"noshowSwitch":false,"rating":4,"newPlaypal":false,"firstRatedOn":"2021-02-02T13:36:32.000Z","isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2021-02-02T13:36:32.000Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"firstRatedOn":null,"isRemoved":false,"palId":"da0df07e-5cdb-4cbc-9b47-a31812aa3be7","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-01-30T18:29:00.257Z"},{"noshow":false,"noshowSwitch":false,"rating":2,"newPlaypal":false,"firstRatedOn":"2021-02-02T14:00:09.000Z","isRemoved":true,"palId":"54fe8420-dae7-4bb2-aa08-320b7dc40794","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-02-02T14:00:09.000Z","userName":"playo user"}],"createdTS":"2021-01-30T18:29:00.258Z","modTS":"2021-11-18T07:09:26.826Z","__v":0},{"_id":"5f9c32a49739b90adc3579b0","location":"BTM Layout","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"d3e71dc8-1aa6-4e32-b10d-50d4b084df31","sportId":"SP5","date":"2020-10-30T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":1,"newPlaypal":false,"firstRatedOn":"2021-02-03T08:19:09.000Z","isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":0},{"reputationId":1,"value":0},{"reputationId":2,"value":0}],"timestamp":"2021-02-03T08:20:04.000Z","userName":"playo user"}],"createdTS":"2020-10-30T15:35:00.552Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5f9c32a49739b90adc3579b2","location":"BTM Layout, Bengaluru","hostId":"54fe8420-dae7-4bb2-aa08-320b7dc40794","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"1d624dfb-38aa-423d-b587-868740d9b5b7","sportId":"SP5","date":"2020-10-30T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":3,"newPlaypal":false,"isRemoved":true,"palId":"54fe8420-dae7-4bb2-aa08-320b7dc40794","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-02-03T08:19:52.000Z","firstRatedOn":"2021-02-03T08:19:52.000Z","userName":"playo user"}],"createdTS":"2020-10-30T15:35:00.562Z","modTS":"2021-11-18T07:09:26.826Z","__v":0},{"_id":"5f6e0e24b61c8b4468f21759","location":"Qatar - Dubai - United Arab Emirates","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"26927e38-56de-4b2e-8c57-dd01abe8109f","sportId":"SP5","date":"2020-09-25T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-09-27T12:28:45.000Z","userName":"playo user"}]
|
|
2
|
-
,"createdTS":"2020-09-25T15:35:00.313Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5efaf808a4b1425a240c2a85","location":"Dribble Arena, Magrath Road","hostId":"2537e208-35f2-4b38-ac65-081ab1a249be","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"7176dd7c-8424-43b8-95f4-a21148141bae","sportId":"SP5","date":"2020-06-30T00:00:00.000Z","startTime":"2020-06-30T07:30:00.000Z","endTime":"2020-06-30T08:30:00.000Z","timing":1,"pals":[{"noshow":false,"noshowSwitch":false,"rating":3,"newPlaypal":false,"firstRatedOn":"2020-07-02T12:52:32.000Z","isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":0},{"reputationId":2,"value":1}],"timestamp":"2020-07-02T12:57:53.000Z","userName":"playo user"}],"createdTS":"2020-06-30T08:30:00.348Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5ee10a8a9a0d8d7d0c611715","location":"Dribble Arena Test,Indiranagar","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"17266219-0b62-4edc-acd3-5775379e7143","sportId":"SP5","date":"2020-06-10T00:00:00.000Z","startTime":"2020-06-10T15:30:00.000Z","endTime":"2020-06-10T16:30:00.000Z","timing":3,"pals":[{"noshow":false,"noshowSwitch":false,"rating":4,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-11T04:30:06.000Z","userName":"playo user"}],"createdTS":"2020-06-10T16:30:02.175Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5ede59780b1f934f45df242a","location":"Dribble Arena Test,Indiranagar","hostId":"2537e208-35f2-4b38-ac65-081ab1a249be","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"dcc3a75f-2841-4317-b4c2-88159285027f","sportId":"SP5","date":"2020-06-08T00:00:00.000Z","startTime":"2020-06-08T11:30:00.000Z","endTime":"2020-06-08T12:30:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-09T03:53:07.000Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":false,"palId":"861c3457-c99c-4dbb-ab2c-5eb447eaf9fe","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-08T15:30:00.261Z"}],"createdTS":"2020-06-08T15:30:00.262Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5edbdf7cf164da32c113b35b","location":"Game Theory - 100 feet road - Indiranagar, 100 Feet Road","hostId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"ee87f1fb-31b0-4640-b718-5b2557c9104f","sportId":"SP5","date":"2020-06-06T00:00:00.000Z","timing":3,"pals":[{"noshow":false,"noshowSwitch":false,"rating":4,"newPlaypal":true,"isRemoved":false,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2020-06-08T17:01:37.000Z"}],"createdTS":"2020-06-06T18:25:00.148Z","modTS":"2020-06-08T18:25:00.227Z","__v":0},{"_id":"5edbdf7df164da32c113b362","location":"BTM Layout","hostId":"2537e208-35f2-4b38-ac65-081ab1a249be","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"e70f154d-6663-401f-922b-a98f737cf0e4","sportId":"SP5","date":"2020-06-06T00:00:00.000Z","timing":3,"pals":[{"noshow":true,"noshowSwitch":false,"rating":4,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-09T03:54:28.000Z","firstRatedOn":"2020-06-09T03:54:28.000Z","userName":"playo user"}],"createdTS":"2020-06-06T18:25:01.155Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5ed5d5c8ec9f4b7276ef8d7e","location":"Dribble Arena Test,Indiranagar","hostId":"d1ba3771-0255-41bf-9889-e222c97e986b","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"f2c4ce11-bde0-45f7-aae9-a470ded10530","sportId":"SP5","date":"2020-06-02T00:00:00.000Z","startTime":"2020-06-02T03:30:00.000Z","endTime":"2020-06-02T04:30:00.000Z","timing":1,"pals":[{"noshow":false,"noshowSwitch":false,"rating":3,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-02T08:22:16.000Z","userName":"playo user"}],"createdTS":"2020-06-02T04:30:00.768Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5ed51ef8749cca727da39f6b","location":"Mekur Hosakeri","hostId":"2537e208-35f2-4b38-ac65-081ab1a249be","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"b76c1f0b-ed02-46c3-847e-c2ed0230f44b","sportId":"SP5","date":"2020-06-01T00:00:00.000Z","timing":2,"pals":[{"noshow":true,"noshowSwitch":false,"rating":5,"newPlaypal":false,"firstRatedOn":"2020-06-04T11:16:18.000Z","isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-04T11:16:23.000Z","userName":"playo user"}],"createdTS":"2020-06-01T15:30:00.186Z","modTS":"2021-11-18T07:03:29.356Z","__v":0},{"_id":"5ed4cafb417f305b48c80d58","location":"Magrath Road, Shanthala Nagar","hostId":"2537e208-35f2-4b38-ac65-081ab1a249be","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":true,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"efb5ee60-ab12-41f4-babf-099b50b2d7ea","sportId":"SP5","date":"2020-05-30T00:00:00.000Z","timing":2,"pals":[{"noshow":false,"noshowSwitch":false,"rating":5,"newPlaypal":true,"isRemoved":false,"palId":"861c3457-c99c-4dbb-ab2c-5eb447eaf9fe","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-05T20:38:34.000Z","firstRatedOn":"2020-06-05T20:38:12.000Z"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":false,"isRemoved":true,"palId":"d1ba3771-0255-41bf-9889-e222c97e986b","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-01T09:31:39.326Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":2,"newPlaypal":true,"isRemoved":true,"palId":"54fe8420-dae7-4bb2-aa08-320b7dc40794","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-10T09:41:20.000Z","firstRatedOn":"2020-06-10T09:41:20.000Z","userName":"playo user"},{"noshow":false,"noshowSwitch":false,"rating":0,"newPlaypal":true,"isRemoved":false,"palId":"2d617f4d-7be2-4fe7-be3a-7c09fd7e513c","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2020-06-01T09:31:39.325Z"}],"createdTS":"2020-06-01T09:31:39.326Z","modTS":"2021-11-18T07:09:26.826Z","__v":0},{"_id":"619b94008fff1950a20adaf2","location":"Indiranagar","hostId":"1b7887d3-8255-409b-9efe-89b64b701862","matchHappened":true,"matchRating":-1,"userPlayed":true,"expired":false,"cancelled":false,"noshow":false,"removed":false,"userId":"2537e208-35f2-4b38-ac65-081ab1a249be","activityId":"afabf002-5260-4248-b200-cedbcbe3fc59","sportId":"SP5","date":"2021-11-22T00:00:00.000Z","startTime":"2021-11-22T13:30:00.794Z","endTime":"2021-11-22T14:00:00.794Z","timing":2,"pals":[{"noshow":true,"noshowSwitch":false,"rating":0,"newPlaypal":false,"firstRatedOn":null,"isRemoved":false,"userPresent":null,"palId":"1b7887d3-8255-409b-9efe-89b64b701862","reputation":[{"reputationId":0,"value":1},{"reputationId":1,"value":1},{"reputationId":2,"value":1}],"timestamp":"2021-11-22T12:58:40.047Z"},{"noshow":true,"noshowSwitch":false,"rating":0,"newPlaypal":false,"firstRatedOn":null,"isRemoved":false,"userPresent":null,"palId":"a458fa2e-37e8-4e9d-beb1-3b4e68e5d56e","reputation":[{"reputationId":0,"value":-1},{"reputationId":1,"value":-1},{"reputationId":2,"value":-1}],"timestamp":"2021-11-22T12:58:40.047Z"}],"createdTS":"2021-11-22T12:58:40.047Z","modTS":"2021-11-22T13:00:41.806Z","__v":0}];
|
|
3
|
-
|
|
4
|
-
const ratingTest = require("./lib/ratings/index");
|
|
5
|
-
|
|
6
|
-
const test = ratingTest.getUserRecentRatings(data, 4);
|
|
7
|
-
|
|
8
|
-
console.log(test, data.length);
|