Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add teamId to expansion of query result, and keep team member ids in … #300

Merged
merged 15 commits into from
Jan 22, 2019
Merged
1 change: 0 additions & 1 deletion controllers/team.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 9 additions & 9 deletions docs/api/api_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ define({
},
{
"type": "get",
"url": "/hacker/email/:email",
"url": "/hacker/:id",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused as to where these changes are coming from. Was this from a previous PR where docs wasn't updated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea, probably just ordering of the items in the list

"title": "get a hacker's information",
"name": "getHacker",
"group": "Hacker",
Expand All @@ -1268,8 +1268,8 @@ define({
"group": "param",
"type": "String",
"optional": false,
"field": "email",
"description": "<p>a hacker's unique email</p>"
"field": "id",
"description": "<p>a hacker's unique mongoID</p>"
}]
}
},
Expand Down Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also kind of weird that in some cases we remove :id to add email/:email, and above we removed email/:email to add :id

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above

"title": "get a hacker's information",
"name": "getHacker",
"group": "Hacker",
Expand All @@ -1340,8 +1340,8 @@ define({
"group": "param",
"type": "String",
"optional": false,
"field": "id",
"description": "<p>a hacker's unique mongoID</p>"
"field": "email",
"description": "<p>a hacker's unique email</p>"
}]
}
},
Expand Down Expand Up @@ -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"
}]
},
{
Expand Down Expand Up @@ -2573,7 +2573,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"
}]
},
Expand Down
18 changes: 9 additions & 9 deletions docs/api/api_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@
},
{
"type": "get",
"url": "/hacker/email/:email",
"url": "/hacker/:id",
"title": "get a hacker's information",
"name": "getHacker",
"group": "Hacker",
Expand All @@ -1267,8 +1267,8 @@
"group": "param",
"type": "String",
"optional": false,
"field": "email",
"description": "<p>a hacker's unique email</p>"
"field": "id",
"description": "<p>a hacker's unique mongoID</p>"
}]
}
},
Expand Down Expand Up @@ -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",
Expand All @@ -1339,8 +1339,8 @@
"group": "param",
"type": "String",
"optional": false,
"field": "id",
"description": "<p>a hacker's unique mongoID</p>"
"field": "email",
"description": "<p>a hacker's unique email</p>"
}]
}
},
Expand Down Expand Up @@ -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"
}]
},
{
Expand Down Expand Up @@ -2571,7 +2571,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"
}]
},
Expand Down
30 changes: 15 additions & 15 deletions docs/api/api_project.js
Original file line number Diff line number Diff line change
@@ -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-21T04:13:36.482Z",
"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"
}
});
30 changes: 15 additions & 15 deletions docs/api/api_project.json
Original file line number Diff line number Diff line change
@@ -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-21T04:13:36.482Z",
"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"
}
}
5 changes: 3 additions & 2 deletions middlewares/team.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 17 additions & 2 deletions routes/api/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions services/search.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand Down
6 changes: 6 additions & 0 deletions tests/team.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.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);
res.body.data.members[0].lastName.should.equal(util.account.hackerAccounts.stored.team[1].lastName);
Expand Down