From bb2a2f5d6e334c981a8e1e5c4d44171b7d39b18d Mon Sep 17 00:00:00 2001 From: Pierre Theo Klein Date: Fri, 18 Jan 2019 20:37:35 -0500 Subject: [PATCH 1/8] Add teamId to expansion of query result, and keep team member ids in get team --- controllers/team.controller.js | 1 - services/search.service.js | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/controllers/team.controller.js b/controllers/team.controller.js index 359aeffe..943c3e55 100644 --- a/controllers/team.controller.js +++ b/controllers/team.controller.js @@ -20,7 +20,6 @@ const Constants = { */ function showTeam(req, res) { const teamData = req.body.team.toJSON(); - delete teamData.members; const memberNames = []; for (const member of req.body.teamMembers) { diff --git a/services/search.service.js b/services/search.service.js index 7d0f3b3e..597a4cb1 100644 --- a/services/search.service.js +++ b/services/search.service.js @@ -17,10 +17,12 @@ function executeQuery(model, queryArray, page, limit, sort, sort_by, shouldExpan var query; switch (model.toLowerCase()) { case "hacker": - query = (shouldExpand) ? Hacker.find().populate({ + query = (shouldExpand) ? Hacker.find().populate([{ path: "accountId", select: " -password" - }) : Hacker.find(); + }, { + path: "teamId" + }]) : Hacker.find(); break; default: return []; From a68e22ca79c9bbb01f93154c9c9ba752cd81937b Mon Sep 17 00:00:00 2001 From: Pierre Theo Klein Date: Fri, 18 Jan 2019 20:42:00 -0500 Subject: [PATCH 2/8] Update test --- tests/team.test.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/team.test.js b/tests/team.test.js index 3c37cb95..9d171cf5 100644 --- a/tests/team.test.js +++ b/tests/team.test.js @@ -76,6 +76,12 @@ describe("GET team", function () { res.body.should.have.property("data"); res.body.data.should.have.property("team"); res.body.data.team.name.should.equal("FullTeam"); + res.body.data.team.should.have.property("members"); + res.body.data.team.members[0].should.equal(util.account.hackerAccounts.stored.team[1]._id); + res.body.data.team.members[1].should.equal(util.account.hackerAccounts.stored.team[2]._id); + res.body.data.team.members[2].should.equal(util.account.hackerAccounts.stored.team[3]._id); + res.body.data.team.members[3].should.equal(util.account.hackerAccounts.stored.team[4]._id); + res.body.data.should.have.property("members"); res.body.data.members[0].firstName.should.equal(util.account.hackerAccounts.stored.team[1].firstName); res.body.data.members[0].lastName.should.equal(util.account.hackerAccounts.stored.team[1].lastName); From 3f4b070b7128fe96bc415dd64bf379b4ab859089 Mon Sep 17 00:00:00 2001 From: Pierre Theo Klein Date: Fri, 18 Jan 2019 20:48:50 -0500 Subject: [PATCH 3/8] Update comments --- middlewares/team.middleware.js | 7 ++++--- routes/api/team.js | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/middlewares/team.middleware.js b/middlewares/team.middleware.js index 32c8f4af..8d1741e4 100644 --- a/middlewares/team.middleware.js +++ b/middlewares/team.middleware.js @@ -397,7 +397,7 @@ async function populateMemberAccountsById(req, res, next) { const team = await Services.Team.findById(req.body.id).populate({ path: "members", populate: { - path: "accountId" + path: "accountId _id" } }); @@ -407,13 +407,14 @@ async function populateMemberAccountsById(req, res, next) { data: {} }); } - + let hackerIds = []; let teamMembers = []; for (const member of team.members) { teamMembers.push(member.accountId); + hackerIds.push(member._id); } - + team.members = hackerIds; req.body.team = team; req.body.teamMembers = teamMembers; return next(); diff --git a/routes/api/team.js b/routes/api/team.js index 41b1098e..1a0b872f 100644 --- a/routes/api/team.js +++ b/routes/api/team.js @@ -122,8 +122,23 @@ module.exports = { * @apiSuccess {Object} data Team object * @apiSuccessExample {object} Success-Response: * { - "message": "Successfully retrieved team information", - "data": {...} + "message": "Team retrieval successful", + "data": { + "team": { + "name":"foo", + "members": [ + ObjectId('...') + ], + "devpostURL": "www.devpost.com/foo", + "projectName": "fooey" + }, + "members": [ + { + "firstName": "John", + "lastName": "Doe" + } + ], + } } * @apiError {String} message Error message From 3985c48f3cec7dfc723a3e7282881a2fc193ac77 Mon Sep 17 00:00:00 2001 From: Pierre Theo Klein Date: Fri, 18 Jan 2019 20:50:05 -0500 Subject: [PATCH 4/8] doc updates --- docs/api/api_data.js | 18 +++++++++--------- docs/api/api_data.json | 18 +++++++++--------- docs/api/api_project.js | 30 +++++++++++++++--------------- docs/api/api_project.json | 30 +++++++++++++++--------------- 4 files changed, 48 insertions(+), 48 deletions(-) diff --git a/docs/api/api_data.js b/docs/api/api_data.js index c7806fac..a269aef5 100644 --- a/docs/api/api_data.js +++ b/docs/api/api_data.js @@ -1257,7 +1257,7 @@ define({ }, { "type": "get", - "url": "/hacker/email/:email", + "url": "/hacker/:id", "title": "get a hacker's information", "name": "getHacker", "group": "Hacker", @@ -1268,8 +1268,8 @@ define({ "group": "param", "type": "String", "optional": false, - "field": "email", - "description": "

a hacker's unique email

" + "field": "id", + "description": "

a hacker's unique mongoID

" }] } }, @@ -1324,12 +1324,12 @@ define({ "filename": "routes/api/hacker.js", "groupTitle": "Hacker", "sampleRequest": [{ - "url": "https://api.mchacks.ca/api/hacker/email/:email" + "url": "https://api.mchacks.ca/api/hacker/:id" }] }, { "type": "get", - "url": "/hacker/:id", + "url": "/hacker/email/:email", "title": "get a hacker's information", "name": "getHacker", "group": "Hacker", @@ -1340,8 +1340,8 @@ define({ "group": "param", "type": "String", "optional": false, - "field": "id", - "description": "

a hacker's unique mongoID

" + "field": "email", + "description": "

a hacker's unique email

" }] } }, @@ -1396,7 +1396,7 @@ define({ "filename": "routes/api/hacker.js", "groupTitle": "Hacker", "sampleRequest": [{ - "url": "https://api.mchacks.ca/api/hacker/:id" + "url": "https://api.mchacks.ca/api/hacker/email/:email" }] }, { @@ -2415,7 +2415,7 @@ define({ }, "examples": [{ "title": "Success-Response: ", - "content": "{\n \"message\": \"Successfully retrieved team information\", \n \"data\": {...}\n }", + "content": "{\n \"message\": \"Team retrieval successful\", \n \"data\": { \n \"team\": {\n \"name\":\"foo\",\n \"members\": [\n ObjectId('...')\n ],\n \"devpostURL\": \"www.devpost.com/foo\",\n \"projectName\": \"fooey\"\n },\n \"members\": [\n {\n \"firstName\": \"John\",\n \"lastName\": \"Doe\"\n }\n ],\n }\n }", "type": "object" }] }, diff --git a/docs/api/api_data.json b/docs/api/api_data.json index 51be9836..b0783583 100644 --- a/docs/api/api_data.json +++ b/docs/api/api_data.json @@ -1256,7 +1256,7 @@ }, { "type": "get", - "url": "/hacker/email/:email", + "url": "/hacker/:id", "title": "get a hacker's information", "name": "getHacker", "group": "Hacker", @@ -1267,8 +1267,8 @@ "group": "param", "type": "String", "optional": false, - "field": "email", - "description": "

a hacker's unique email

" + "field": "id", + "description": "

a hacker's unique mongoID

" }] } }, @@ -1323,12 +1323,12 @@ "filename": "routes/api/hacker.js", "groupTitle": "Hacker", "sampleRequest": [{ - "url": "https://api.mchacks.ca/api/hacker/email/:email" + "url": "https://api.mchacks.ca/api/hacker/:id" }] }, { "type": "get", - "url": "/hacker/:id", + "url": "/hacker/email/:email", "title": "get a hacker's information", "name": "getHacker", "group": "Hacker", @@ -1339,8 +1339,8 @@ "group": "param", "type": "String", "optional": false, - "field": "id", - "description": "

a hacker's unique mongoID

" + "field": "email", + "description": "

a hacker's unique email

" }] } }, @@ -1395,7 +1395,7 @@ "filename": "routes/api/hacker.js", "groupTitle": "Hacker", "sampleRequest": [{ - "url": "https://api.mchacks.ca/api/hacker/:id" + "url": "https://api.mchacks.ca/api/hacker/email/:email" }] }, { @@ -2414,7 +2414,7 @@ }, "examples": [{ "title": "Success-Response: ", - "content": "{\n \"message\": \"Successfully retrieved team information\", \n \"data\": {...}\n }", + "content": "{\n \"message\": \"Team retrieval successful\", \n \"data\": { \n \"team\": {\n \"name\":\"foo\",\n \"members\": [\n ObjectId('...')\n ],\n \"devpostURL\": \"www.devpost.com/foo\",\n \"projectName\": \"fooey\"\n },\n \"members\": [\n {\n \"firstName\": \"John\",\n \"lastName\": \"Doe\"\n }\n ],\n }\n }", "type": "object" }] }, diff --git a/docs/api/api_project.js b/docs/api/api_project.js index 0cd83632..a507a7e8 100644 --- a/docs/api/api_project.js +++ b/docs/api/api_project.js @@ -1,16 +1,16 @@ -define({ - "name": "hackerAPI", - "version": "0.0.8", - "description": "Documentation for the API used for mchacks", - "defaultVersion": "0.0.8", - "title": "hackerAPI documentation", - "url": "https://api.mchacks.ca/api", - "sampleUrl": "https://api.mchacks.ca/api", - "apidoc": "0.3.0", - "generator": { - "name": "apidoc", - "time": "2019-01-10T23:24:21.462Z", - "url": "http://apidocjs.com", - "version": "0.17.7" - } +define({ + "name": "hackerAPI", + "version": "0.0.8", + "description": "Documentation for the API used for mchacks", + "defaultVersion": "0.0.8", + "title": "hackerAPI documentation", + "url": "https://api.mchacks.ca/api", + "sampleUrl": "https://api.mchacks.ca/api", + "apidoc": "0.3.0", + "generator": { + "name": "apidoc", + "time": "2019-01-19T01:48:55.120Z", + "url": "http://apidocjs.com", + "version": "0.17.7" + } }); \ No newline at end of file diff --git a/docs/api/api_project.json b/docs/api/api_project.json index 8ad885dc..dfb63621 100644 --- a/docs/api/api_project.json +++ b/docs/api/api_project.json @@ -1,16 +1,16 @@ -{ - "name": "hackerAPI", - "version": "0.0.8", - "description": "Documentation for the API used for mchacks", - "defaultVersion": "0.0.8", - "title": "hackerAPI documentation", - "url": "https://api.mchacks.ca/api", - "sampleUrl": "https://api.mchacks.ca/api", - "apidoc": "0.3.0", - "generator": { - "name": "apidoc", - "time": "2019-01-10T23:24:21.462Z", - "url": "http://apidocjs.com", - "version": "0.17.7" - } +{ + "name": "hackerAPI", + "version": "0.0.8", + "description": "Documentation for the API used for mchacks", + "defaultVersion": "0.0.8", + "title": "hackerAPI documentation", + "url": "https://api.mchacks.ca/api", + "sampleUrl": "https://api.mchacks.ca/api", + "apidoc": "0.3.0", + "generator": { + "name": "apidoc", + "time": "2019-01-19T01:48:55.120Z", + "url": "http://apidocjs.com", + "version": "0.17.7" + } } \ No newline at end of file From 735102b360239f6e6371c42a68e30826be5ce3d0 Mon Sep 17 00:00:00 2001 From: Pierre Theo Klein Date: Fri, 18 Jan 2019 21:27:13 -0500 Subject: [PATCH 5/8] Bug fix --- middlewares/team.middleware.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/middlewares/team.middleware.js b/middlewares/team.middleware.js index 8d1741e4..830866e7 100644 --- a/middlewares/team.middleware.js +++ b/middlewares/team.middleware.js @@ -397,7 +397,7 @@ async function populateMemberAccountsById(req, res, next) { const team = await Services.Team.findById(req.body.id).populate({ path: "members", populate: { - path: "accountId _id" + path: "accountId" } }); From 183dfbef933c48cb50a4fa1f9c6f1249d96396e6 Mon Sep 17 00:00:00 2001 From: Pierre Theo Klein Date: Sat, 19 Jan 2019 23:54:54 -0500 Subject: [PATCH 6/8] ObjectId object -> string --- tests/team.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/team.test.js b/tests/team.test.js index 9d171cf5..02763973 100644 --- a/tests/team.test.js +++ b/tests/team.test.js @@ -77,10 +77,10 @@ describe("GET team", function () { res.body.data.should.have.property("team"); res.body.data.team.name.should.equal("FullTeam"); res.body.data.team.should.have.property("members"); - res.body.data.team.members[0].should.equal(util.account.hackerAccounts.stored.team[1]._id); - res.body.data.team.members[1].should.equal(util.account.hackerAccounts.stored.team[2]._id); - res.body.data.team.members[2].should.equal(util.account.hackerAccounts.stored.team[3]._id); - res.body.data.team.members[3].should.equal(util.account.hackerAccounts.stored.team[4]._id); + res.body.data.team.members[0].should.equal(util.account.hackerAccounts.stored.team[1]._id.toString()); + res.body.data.team.members[1].should.equal(util.account.hackerAccounts.stored.team[2]._id.toString()); + res.body.data.team.members[2].should.equal(util.account.hackerAccounts.stored.team[3]._id.toString()); + res.body.data.team.members[3].should.equal(util.account.hackerAccounts.stored.team[4]._id.toString()); res.body.data.should.have.property("members"); res.body.data.members[0].firstName.should.equal(util.account.hackerAccounts.stored.team[1].firstName); From 0fe953fdbc6ddb32b65ac0c404741238cf9631d1 Mon Sep 17 00:00:00 2001 From: Pierre Theo Klein Date: Sun, 20 Jan 2019 00:29:55 -0500 Subject: [PATCH 7/8] accountId -> hackerId --- tests/team.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/team.test.js b/tests/team.test.js index 02763973..ca0cfa05 100644 --- a/tests/team.test.js +++ b/tests/team.test.js @@ -77,10 +77,10 @@ describe("GET team", function () { res.body.data.should.have.property("team"); res.body.data.team.name.should.equal("FullTeam"); res.body.data.team.should.have.property("members"); - res.body.data.team.members[0].should.equal(util.account.hackerAccounts.stored.team[1]._id.toString()); - res.body.data.team.members[1].should.equal(util.account.hackerAccounts.stored.team[2]._id.toString()); - res.body.data.team.members[2].should.equal(util.account.hackerAccounts.stored.team[3]._id.toString()); - res.body.data.team.members[3].should.equal(util.account.hackerAccounts.stored.team[4]._id.toString()); + res.body.data.team.members[0].should.equal(util.hacker.TeamHacker1); + res.body.data.team.members[1].should.equal(util.hacker.TeamHacker2); + res.body.data.team.members[2].should.equal(util.hacker.TeamHacker3); + res.body.data.team.members[3].should.equal(util.hacker.TeamHacker4); res.body.data.should.have.property("members"); res.body.data.members[0].firstName.should.equal(util.account.hackerAccounts.stored.team[1].firstName); From 3bb4b8dc0eab70d317f6fee3d4a6fea385a14aff Mon Sep 17 00:00:00 2001 From: Pierre Theo Klein Date: Sun, 20 Jan 2019 19:53:49 -0500 Subject: [PATCH 8/8] _id -> .toString() --- tests/team.test.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/team.test.js b/tests/team.test.js index ca0cfa05..931e62ca 100644 --- a/tests/team.test.js +++ b/tests/team.test.js @@ -77,10 +77,10 @@ describe("GET team", function () { res.body.data.should.have.property("team"); res.body.data.team.name.should.equal("FullTeam"); res.body.data.team.should.have.property("members"); - res.body.data.team.members[0].should.equal(util.hacker.TeamHacker1); - res.body.data.team.members[1].should.equal(util.hacker.TeamHacker2); - res.body.data.team.members[2].should.equal(util.hacker.TeamHacker3); - res.body.data.team.members[3].should.equal(util.hacker.TeamHacker4); + res.body.data.team.members[0].should.equal(util.hacker.TeamHacker1._id.toString()); + res.body.data.team.members[1].should.equal(util.hacker.TeamHacker2._id.toString()); + res.body.data.team.members[2].should.equal(util.hacker.TeamHacker3._id.toString()); + res.body.data.team.members[3].should.equal(util.hacker.TeamHacker4._id.toString()); res.body.data.should.have.property("members"); res.body.data.members[0].firstName.should.equal(util.account.hackerAccounts.stored.team[1].firstName);