Skip to content

Commit 8dca9e9

Browse files
authored
feat: stats route return object creation time (#698)
* added application date to hacker stats * undo commit of package-lock.json * add applicationDate stat to the getStats test call * undo accidental gitignore * update sample request + commented timestamp processing updated the sample request for in-line apidoc for /hacker/stats and added comments to clarify timestamp processing
1 parent 1619f92 commit 8dca9e9

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

routes/api/hacker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ module.exports = {
240240
graduationYear: { "2019": 10 },
241241
dietaryRestrictions: { "None": 10 },
242242
shirtSize: { "M": 3, "XL": 7 },
243-
age: { "22": 10 }
243+
age: { "22": 10 },
244+
applicationDate: {"2020-12-27" : 2, "2020-12-28" : 8}
244245
}
245246
* }
246247
* }

services/hacker.service.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ function getStats(hackers) {
148148
graduationYear: {},
149149
dietaryRestrictions: {},
150150
shirtSize: {},
151-
age: {}
151+
age: {},
152+
applicationDate: {}
152153
};
153154

154155
hackers.forEach((hacker) => {
@@ -198,7 +199,7 @@ function getStats(hackers) {
198199
stats.graduationYear[hacker.application.general.graduationYear] = stats
199200
.graduationYear[hacker.application.general.graduationYear]
200201
? stats.graduationYear[hacker.application.general.graduationYear] +
201-
1
202+
1
202203
: 1;
203204
for (const dietaryRestrictions of hacker.accountId
204205
.dietaryRestrictions) {
@@ -213,6 +214,17 @@ function getStats(hackers) {
213214
: 1;
214215
const age = hacker.accountId.getAge();
215216
stats.age[age] = stats.age[age] ? stats.age[age] + 1 : 1;
217+
218+
const applicationDate = hacker._id
219+
.getTimestamp() //
220+
.toISOString() // converts Date to "YYYY-MM-DDTHH:mm:ss.sssZ" format
221+
.slice(0, 10); // slice(beginIndex, endIndex) extracts string from beginIndex to endIndex, used to convert to "YYYY-MM-DD" format
222+
223+
stats.applicationDate[applicationDate] = stats.applicationDate[
224+
applicationDate
225+
]
226+
? stats.applicationDate[applicationDate] + 1
227+
: 1;
216228
});
217229
return stats;
218230
}

tests/hacker.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,7 @@ describe("GET Hacker stats", function() {
16111611
);
16121612
res.body.data.stats.should.have.property("shirtSize");
16131613
res.body.data.stats.should.have.property("age");
1614+
res.body.data.stats.should.have.property("applicationDate");
16141615
done();
16151616
});
16161617
});

0 commit comments

Comments
 (0)