Skip to content

Commit cec8514

Browse files
YiFeiZhang2pierreTklein
authored andcommitted
Feature/team patch (#277)
* WIP team patch * WIP team patch * docs and tests * fix merge issue * WIP patch * Commenting, fix parsePatch, remove unused function * PR comments * Description and errors * Fix bracket issue
1 parent 9399c95 commit cec8514

16 files changed

Lines changed: 538 additions & 16 deletions

constants/error.constant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const AUTH_401_MESSAGE = "Invalid Authentication";
2727
const AUTH_403_MESSAGE = "Invalid Authorization";
2828
const ACCOUNT_403_MESSAGE = "Account not verified";
2929

30+
const TEAM_READ_500_MESSAGE = "Error while retrieving team";
3031
const TEAM_UPDATE_500_MESSAGE = "Error while updating team";
3132
const HACKER_UPDATE_500_MESSAGE = "Error while updating hacker";
3233
const ACCOUNT_UPDATE_500_MESSAGE = "Error while updating account";
@@ -73,4 +74,5 @@ module.exports = {
7374
ROLE_CREATE_500_MESSAGE: ROLE_CREATE_500_MESSAGE,
7475
TEAM_NAME_409_MESSAGE: TEAM_NAME_409_MESSAGE,
7576
TEAM_JOIN_SAME_409_MESSAGE: TEAM_JOIN_SAME_409_MESSAGE,
77+
TEAM_READ_500_MESSAGE: TEAM_READ_500_MESSAGE,
7678
};

constants/role.constant.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const hackerRole = {
4141
Constants.Routes.hackerRoutes.getSelf,
4242

4343
Constants.Routes.teamRoutes.join,
44+
Constants.Routes.teamRoutes.patchSelfById,
4445
Constants.Routes.teamRoutes.post,
4546
Constants.Routes.teamRoutes.get,
4647
Constants.Routes.teamRoutes.leave

constants/routes.constant.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ const teamRoutes = {
146146
requestType: Constants.REQUEST_TYPES.PATCH,
147147
uri: "/api/team/join/",
148148
},
149+
"patchSelfById": {
150+
requestType: Constants.REQUEST_TYPES.PATCH,
151+
uri: "/api/team/" + Constants.ROLE_CATEGORIES.SELF
152+
},
153+
"patchAnyById": {
154+
requestType: Constants.REQUEST_TYPES.PATCH,
155+
uri: "/api/team/" + Constants.ROLE_CATEGORIES.ALL
156+
},
149157
"leave": {
150158
requestType: Constants.REQUEST_TYPES.PATCH,
151159
uri: "/api/team/leave/",

constants/success.constant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const SPONSOR_CREATE = "Sponsor creation successful.";
3737
const TEAM_GET_BY_ID = "Team found by id.";
3838
const TEAM_CREATE = "Team creation successful.";
3939
const TEAM_JOIN = "Team join successful.";
40+
const TEAM_UPDATE = "Team update successful.";
4041
const TEAM_READ = "Team retrieval successful.";
4142
const TEAM_HACKER_LEAVE = "Removal from team successful.";
4243

@@ -79,6 +80,7 @@ module.exports = {
7980
TEAM_GET_BY_ID: TEAM_GET_BY_ID,
8081
TEAM_CREATE: TEAM_CREATE,
8182
TEAM_JOIN: TEAM_JOIN,
83+
TEAM_UPDATE: TEAM_UPDATE,
8284
TEAM_READ: TEAM_READ,
8385
TEAM_HACKER_LEAVE: TEAM_HACKER_LEAVE,
8486

constants/testMongoId.constant.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
3+
const mongoose = require("mongoose");
4+
5+
const team1Id = mongoose.Types.ObjectId();
6+
const team2Id = mongoose.Types.ObjectId();
7+
const team3Id = mongoose.Types.ObjectId();
8+
9+
const hackerAId = mongoose.Types.ObjectId();
10+
const hackerBId = mongoose.Types.ObjectId();
11+
const hackerCId = mongoose.Types.ObjectId();
12+
const hackerDId = mongoose.Types.ObjectId();
13+
const hackerEId = mongoose.Types.ObjectId();
14+
const hackerFId = mongoose.Types.ObjectId();
15+
const hackerGId = mongoose.Types.ObjectId();
16+
17+
18+
module.exports = {
19+
team1Id: team1Id,
20+
team2Id: team2Id,
21+
team3Id: team3Id,
22+
hackerAId: hackerAId,
23+
hackerBId: hackerBId,
24+
hackerCId: hackerCId,
25+
hackerDId: hackerDId,
26+
hackerEId: hackerEId,
27+
hackerFId: hackerFId,
28+
hackerGId: hackerGId,
29+
};

controllers/team.controller.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ function joinedTeam(req, res) {
5757
});
5858
}
5959

60+
/**
61+
* @function updatedTeam
62+
* @param {{body: {team: {_id: ObjectId, name: string, members: ObjectId[], devpostURL: string, projectName: string}}}} req
63+
* @param {*} res
64+
* @return {JSON} Success status
65+
* @description Display team information and update success status
66+
*/
67+
function updatedTeam(req, res) {
68+
return res.status(200).json({
69+
message: Constants.Success.TEAM_UPDATE,
70+
data: req.body.team.toJSON(),
71+
});
72+
}
73+
6074
/**
6175
* @function createdTeam
6276
* @param {{body: {team: {_id: ObjectId, name: string, members: ObjectId[], devpostURL: string, projectName: string}}}} req
@@ -88,6 +102,7 @@ function leftTeam(req, res) {
88102

89103
module.exports = {
90104
joinedTeam: joinedTeam,
105+
updatedTeam: updatedTeam,
91106
createdTeam: createdTeam,
92107
showTeam: showTeam,
93108
leftTeam: leftTeam,

docs/api/api_data.js

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,7 @@ define({
23302330
"type": "Object",
23312331
"optional": false,
23322332
"field": "data",
2333-
"description": "<p>Sponsor object</p>"
2333+
"description": "<p>Team object</p>"
23342334
}
23352335
]
23362336
},
@@ -2418,6 +2418,78 @@ define({
24182418
"url": "https://api.mchacks.ca/api/team/join/"
24192419
}]
24202420
},
2421+
{
2422+
"type": "patch",
2423+
"url": "/team/:hackerId",
2424+
"title": "Update a team's information. The team is specified by the hacker belonging to it.",
2425+
"name": "patchTeam",
2426+
"group": "Team",
2427+
"version": "0.0.8",
2428+
"parameter": {
2429+
"fields": {
2430+
"param": [{
2431+
"group": "param",
2432+
"type": "ObjectId",
2433+
"optional": false,
2434+
"field": "hackerId",
2435+
"description": "<p>a hacker's unique Id</p>"
2436+
}]
2437+
}
2438+
},
2439+
"success": {
2440+
"fields": {
2441+
"Success 200": [{
2442+
"group": "Success 200",
2443+
"type": "String",
2444+
"optional": false,
2445+
"field": "message",
2446+
"description": "<p>Success message</p>"
2447+
},
2448+
{
2449+
"group": "Success 200",
2450+
"type": "Object",
2451+
"optional": false,
2452+
"field": "data",
2453+
"description": "<p>Team object</p>"
2454+
}
2455+
]
2456+
},
2457+
"examples": [{
2458+
"title": "Success-Response: ",
2459+
"content": "{\n \"message\": \"Team update successful.\", \n \"data\": {...}\n }",
2460+
"type": "object"
2461+
}]
2462+
},
2463+
"error": {
2464+
"fields": {
2465+
"Error 4xx": [{
2466+
"group": "Error 4xx",
2467+
"type": "String",
2468+
"optional": false,
2469+
"field": "message",
2470+
"description": "<p>Error message</p>"
2471+
},
2472+
{
2473+
"group": "Error 4xx",
2474+
"type": "Object",
2475+
"optional": false,
2476+
"field": "data",
2477+
"description": "<p>Query input that caused the error.</p>"
2478+
}
2479+
]
2480+
},
2481+
"examples": [{
2482+
"title": "Error-Response: ",
2483+
"content": "{\"message\": \"Team not found\", \"data\": {teamId}}",
2484+
"type": "object"
2485+
}]
2486+
},
2487+
"filename": "routes/api/team.js",
2488+
"groupTitle": "Team",
2489+
"sampleRequest": [{
2490+
"url": "https://api.mchacks.ca/api/team/:hackerId"
2491+
}]
2492+
},
24212493
{
24222494
"type": "post",
24232495
"url": "/volunteer/",

docs/api/api_data.json

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,7 @@
23292329
"type": "Object",
23302330
"optional": false,
23312331
"field": "data",
2332-
"description": "<p>Sponsor object</p>"
2332+
"description": "<p>Team object</p>"
23332333
}
23342334
]
23352335
},
@@ -2417,6 +2417,78 @@
24172417
"url": "https://api.mchacks.ca/api/team/join/"
24182418
}]
24192419
},
2420+
{
2421+
"type": "patch",
2422+
"url": "/team/:hackerId",
2423+
"title": "Update a team's information. The team is specified by the hacker belonging to it.",
2424+
"name": "patchTeam",
2425+
"group": "Team",
2426+
"version": "0.0.8",
2427+
"parameter": {
2428+
"fields": {
2429+
"param": [{
2430+
"group": "param",
2431+
"type": "ObjectId",
2432+
"optional": false,
2433+
"field": "hackerId",
2434+
"description": "<p>a hacker's unique Id</p>"
2435+
}]
2436+
}
2437+
},
2438+
"success": {
2439+
"fields": {
2440+
"Success 200": [{
2441+
"group": "Success 200",
2442+
"type": "String",
2443+
"optional": false,
2444+
"field": "message",
2445+
"description": "<p>Success message</p>"
2446+
},
2447+
{
2448+
"group": "Success 200",
2449+
"type": "Object",
2450+
"optional": false,
2451+
"field": "data",
2452+
"description": "<p>Team object</p>"
2453+
}
2454+
]
2455+
},
2456+
"examples": [{
2457+
"title": "Success-Response: ",
2458+
"content": "{\n \"message\": \"Team update successful.\", \n \"data\": {...}\n }",
2459+
"type": "object"
2460+
}]
2461+
},
2462+
"error": {
2463+
"fields": {
2464+
"Error 4xx": [{
2465+
"group": "Error 4xx",
2466+
"type": "String",
2467+
"optional": false,
2468+
"field": "message",
2469+
"description": "<p>Error message</p>"
2470+
},
2471+
{
2472+
"group": "Error 4xx",
2473+
"type": "Object",
2474+
"optional": false,
2475+
"field": "data",
2476+
"description": "<p>Query input that caused the error.</p>"
2477+
}
2478+
]
2479+
},
2480+
"examples": [{
2481+
"title": "Error-Response: ",
2482+
"content": "{\"message\": \"Team not found\", \"data\": {teamId}}",
2483+
"type": "object"
2484+
}]
2485+
},
2486+
"filename": "routes/api/team.js",
2487+
"groupTitle": "Team",
2488+
"sampleRequest": [{
2489+
"url": "https://api.mchacks.ca/api/team/:hackerId"
2490+
}]
2491+
},
24202492
{
24212493
"type": "post",
24222494
"url": "/volunteer/",

0 commit comments

Comments
 (0)