playov2-js-utilities 0.3.1 → 0.3.2

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 (3) hide show
  1. package/lib/util.js +4 -1
  2. package/package.json +1 -1
  3. package/test.js +219 -0
package/lib/util.js CHANGED
@@ -70,6 +70,9 @@ const getRecentRatingDictOfPals = (postActivityDocs) => {
70
70
  // pals array contains ratings object as per given by other playpals for a particular activity, check schema for further details
71
71
  const { pals = [] } = postActivityDoc;
72
72
 
73
+ /**
74
+ * Description for code below we are try to get a dictionary of latest non-zero rating the user has received to be processed later
75
+ */
73
76
  if (Array.isArray(pals)) {
74
77
  pals.forEach((palRating) => {
75
78
  const { palId = '', rating = 0, timestamp } = palRating;
@@ -78,7 +81,7 @@ const getRecentRatingDictOfPals = (postActivityDocs) => {
78
81
  rating: rating,
79
82
  timestamp: timestamp
80
83
  }
81
- } else if (palRatingDict[palId] && timestamp >= palRatingDict[palId]["timestamp"]) {
84
+ } else if (palRatingDict[palId] && timestamp >= palRatingDict[palId]["timestamp"] && rating > 0) {
82
85
  // If user received any rating more recent then consider that instead
83
86
  palRatingDict[palId]["rating"] = rating;
84
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playov2-js-utilities",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Private package for JS utility functions",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js ADDED
@@ -0,0 +1,219 @@
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);