Skip to content

Commit 35abfbd

Browse files
YiFeiZhang2pierreTklein
authored andcommitted
Feature/sponsor patch (#304)
* Create /self route for sponsor * docs and add a authentication test * Fix PR comments * Add roles in post_roles to respect the tiers of sponsors * Add success and error for sponsor patch * Add sponsor patch routes and roles, remove account roles from hacker * create updatedSponsor controller with comments * Create sponsor patch middleware * create update sponsor validator * Create sponsor service * Create sponsor patch route and update docs * sponsor test * Fix merge issue * PR comments
1 parent 1bdfdbb commit 35abfbd

File tree

14 files changed

+463
-40
lines changed

14 files changed

+463
-40
lines changed

constants/error.constant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const HACKER_UPDATE_500_MESSAGE = "Error while updating hacker";
3434
const ACCOUNT_UPDATE_500_MESSAGE = "Error while updating account";
3535
const HACKER_CREATE_500_MESSAGE = "Error while creating hacker";
3636
const SPONSOR_CREATE_500_MESSAGE = "Error while creating sponsor";
37+
const SPONSOR_UPDATE_500_MESSAGE = "Error while updating sponsor";
3738
const TEAM_CREATE_500_MESSAGE = "Error while creating team";
3839
const VOLUNTEER_CREATE_500_MESSAGE = "Error while creating volunteer";
3940
const EMAIL_500_MESSAGE = "Error while generating email";
@@ -77,4 +78,5 @@ module.exports = {
7778
TEAM_JOIN_SAME_409_MESSAGE: TEAM_JOIN_SAME_409_MESSAGE,
7879
TEAM_READ_500_MESSAGE: TEAM_READ_500_MESSAGE,
7980
VOLUNTEER_404_MESSAGE: VOLUNTEER_404_MESSAGE,
81+
SPONSOR_UPDATE_500_MESSAGE: SPONSOR_UPDATE_500_MESSAGE,
8082
};

constants/role.constant.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ const hackerRole = {
2929
"_id": mongoose.Types.ObjectId.createFromTime(2),
3030
"name": Constants.General.HACKER,
3131
"routes": [
32-
Constants.Routes.accountRoutes.getSelf,
33-
Constants.Routes.accountRoutes.getSelfById,
34-
Constants.Routes.accountRoutes.patchSelfById,
35-
3632
Constants.Routes.hackerRoutes.post,
3733
Constants.Routes.hackerRoutes.getSelfById,
3834
Constants.Routes.hackerRoutes.getSelfByEmail,
@@ -70,6 +66,7 @@ const sponsorT1Role = {
7066
Constants.Routes.sponsorRoutes.post,
7167
Constants.Routes.sponsorRoutes.getSelfById,
7268
Constants.Routes.sponsorRoutes.getSelf,
69+
Constants.Routes.sponsorRoutes.patchSelfById,
7370
]
7471
};
7572

@@ -80,6 +77,7 @@ const sponsorT2Role = {
8077
Constants.Routes.sponsorRoutes.post,
8178
Constants.Routes.sponsorRoutes.getSelfById,
8279
Constants.Routes.sponsorRoutes.getSelf,
80+
Constants.Routes.sponsorRoutes.patchSelfById,
8381
]
8482
};
8583

@@ -90,6 +88,7 @@ const sponsorT3Role = {
9088
Constants.Routes.sponsorRoutes.post,
9189
Constants.Routes.sponsorRoutes.getSelfById,
9290
Constants.Routes.sponsorRoutes.getSelf,
91+
Constants.Routes.sponsorRoutes.patchSelfById,
9392
]
9493
};
9594

@@ -100,6 +99,7 @@ const sponsorT4Role = {
10099
Constants.Routes.sponsorRoutes.post,
101100
Constants.Routes.sponsorRoutes.getSelfById,
102101
Constants.Routes.sponsorRoutes.getSelf,
102+
Constants.Routes.sponsorRoutes.patchSelfById,
103103
]
104104
};
105105

@@ -110,6 +110,7 @@ const sponsorT5Role = {
110110
Constants.Routes.sponsorRoutes.post,
111111
Constants.Routes.sponsorRoutes.getSelfById,
112112
Constants.Routes.sponsorRoutes.getSelf,
113+
Constants.Routes.sponsorRoutes.patchSelfById,
113114
]
114115
};
115116

constants/routes.constant.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ const sponsorRoutes = {
143143
requestType: Constants.REQUEST_TYPES.POST,
144144
uri: "/api/sponsor/",
145145
},
146+
"patchSelfById": {
147+
requestType: Constants.REQUEST_TYPES.PATCH,
148+
uri: "/api/sponsor/" + Constants.ROLE_CATEGORIES.SELF,
149+
},
150+
"patchAnyById": {
151+
requestType: Constants.REQUEST_TYPES.PATCH,
152+
uri: "/api/sponsor/" + Constants.ROLE_CATEGORIES.ALL,
153+
}
146154
};
147155

148156
const teamRoutes = {

constants/success.constant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const SEARCH_NO_RESULTS = "Query search successful. No results found.";
3333
const SPONSOR_GET_BY_ID = "Sponsor found by id.";
3434
const SPONSOR_READ = "Sponsor retrieval successful.";
3535
const SPONSOR_CREATE = "Sponsor creation successful.";
36+
const SPONSOR_UPDATE = "Sponsor update successful.";
3637

3738
const TEAM_GET_BY_ID = "Team found by id.";
3839
const TEAM_CREATE = "Team creation successful.";
@@ -77,6 +78,7 @@ module.exports = {
7778
SPONSOR_GET_BY_ID: SPONSOR_GET_BY_ID,
7879
SPONSOR_CREATE: SPONSOR_CREATE,
7980
SPONSOR_READ: SPONSOR_READ,
81+
SPONSOR_UPDATE: SPONSOR_UPDATE,
8082

8183
TEAM_GET_BY_ID: TEAM_GET_BY_ID,
8284
TEAM_CREATE: TEAM_CREATE,

controllers/sponsor.controller.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,35 @@ function showSponsor(req, res) {
2424
}
2525

2626
/**
27-
* @function createdHacker
27+
* @function createdSponsor
2828
* @param {{body: {sponsor: {_id: ObjectId, accountId: ObjectId, tier: number, company: string, contractURL: string, nominees: ObjectId[]}}}} req
2929
* @param {*} res
3030
* @return {JSON} Success status
3131
* @description returns success message
3232
*/
33-
async function createdSponsor(req, res) {
33+
function createdSponsor(req, res) {
3434
return res.status(200).json({
3535
message: Constants.Success.SPONSOR_CREATE,
3636
data: req.body.sponsor.toJSON()
3737
});
3838
}
3939

40+
/**
41+
* @function updatedSponsor
42+
* @param {{body: {sponsor: {_id: ObjectId, accountId: ObjectId, tier: number, company: string, contractURL: string, nominees: ObjectId[]}}}} req
43+
* @param {*} res
44+
* @return {JSON} Success status
45+
* @description returns success message
46+
*/
47+
function updatedSponsor(req, res) {
48+
return res.status(200).json({
49+
message: Constants.Success.SPONSOR_UPDATE,
50+
data: req.body.sponsor.toJSON()
51+
});
52+
}
53+
4054
module.exports = {
4155
createdSponsor: createdSponsor,
4256
showSponsor: showSponsor,
57+
updatedSponsor: updatedSponsor,
4358
};

docs/api/api_data.js

Lines changed: 98 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@ define({
18241824
},
18251825
"examples": [{
18261826
"title": "Success-Response: ",
1827-
"content": "{\n \"message\": \"Successfully retrieved sponsor information\", \n \"data\": {...}\n }",
1827+
"content": "{\n \"message\": \"Successfully retrieved sponsor information\", \n \"data\": {\n \"id\": \"5bff4d736f86be0a41badb91\",\n \"accountId\": \"5bff4d736f86be0a41badb99\",\n \"tier\": 3,\n \"company\": \"companyName\",\n \"contractURL\": \"https://www.contractHere.com\",\n \"nominees\": [\"5bff4d736f86be0a41badb93\",\"5bff4d736f86be0a41badb94\"]\n }\n }",
18281828
"type": "object"
18291829
}]
18301830
},
@@ -1852,6 +1852,9 @@ define({
18521852
"type": "object"
18531853
}]
18541854
},
1855+
"permission": [{
1856+
"name": ": Sponsor"
1857+
}],
18551858
"filename": "routes/api/sponsor.js",
18561859
"groupTitle": "Hacker",
18571860
"sampleRequest": [{
@@ -2314,6 +2317,100 @@ define({
23142317
"url": "https://api.mchacks.ca/api/sponsor/:id"
23152318
}]
23162319
},
2320+
{
2321+
"type": "patch",
2322+
"url": "/sponsor/",
2323+
"title": "update a sponsor",
2324+
"name": "patchSponsor",
2325+
"group": "Sponsor",
2326+
"version": "1.3.0",
2327+
"parameter": {
2328+
"fields": {
2329+
"param": [{
2330+
"group": "param",
2331+
"type": "ObjectId",
2332+
"optional": false,
2333+
"field": "id",
2334+
"description": "<p>ObjectID of the sponsor</p>"
2335+
}],
2336+
"body": [{
2337+
"group": "body",
2338+
"type": "String",
2339+
"optional": false,
2340+
"field": "company",
2341+
"description": "<p>Name of the company.</p>"
2342+
},
2343+
{
2344+
"group": "body",
2345+
"type": "String",
2346+
"optional": false,
2347+
"field": "contractURL",
2348+
"description": "<p>URL link to the contract with the company.</p>"
2349+
},
2350+
{
2351+
"group": "body",
2352+
"type": "ObjectId[]",
2353+
"optional": false,
2354+
"field": "nominees",
2355+
"description": "<p>Array of accounts that the company wish to nominate as hackers.</p>"
2356+
}
2357+
]
2358+
}
2359+
},
2360+
"success": {
2361+
"fields": {
2362+
"Success 200": [{
2363+
"group": "Success 200",
2364+
"type": "String",
2365+
"optional": false,
2366+
"field": "message",
2367+
"description": "<p>Success message</p>"
2368+
},
2369+
{
2370+
"group": "Success 200",
2371+
"type": "Object",
2372+
"optional": false,
2373+
"field": "data",
2374+
"description": "<p>Sponsor object</p>"
2375+
}
2376+
]
2377+
},
2378+
"examples": [{
2379+
"title": "Success-Response: ",
2380+
"content": "{\n \"message\": \"Sponsor update successful\", \n \"data\": {...}\n }",
2381+
"type": "object"
2382+
}]
2383+
},
2384+
"error": {
2385+
"fields": {
2386+
"Error 4xx": [{
2387+
"group": "Error 4xx",
2388+
"type": "String",
2389+
"optional": false,
2390+
"field": "message",
2391+
"description": "<p>Error message</p>"
2392+
},
2393+
{
2394+
"group": "Error 4xx",
2395+
"type": "Object",
2396+
"optional": false,
2397+
"field": "data",
2398+
"description": "<p>empty</p>"
2399+
}
2400+
]
2401+
},
2402+
"examples": [{
2403+
"title": "Error-Response: ",
2404+
"content": "{\"message\": \"Error while updating sponsor\", \"data\": {}}",
2405+
"type": "object"
2406+
}]
2407+
},
2408+
"filename": "routes/api/sponsor.js",
2409+
"groupTitle": "Sponsor",
2410+
"sampleRequest": [{
2411+
"url": "https://api.mchacks.ca/api/sponsor/"
2412+
}]
2413+
},
23172414
{
23182415
"type": "post",
23192416
"url": "/team/",

docs/api/api_data.json

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,8 +1823,7 @@
18231823
},
18241824
"examples": [{
18251825
"title": "Success-Response: ",
1826-
"content": "{\n \"message\": \"Successfully retrieved sponsor information\", \n \"data\": {...}\n }",
1827-
"type": "object"
1826+
"content": "{\n \"message\": \"Successfully retrieved sponsor information\", \n \"data\": {\n \"id\": \"5bff4d736f86be0a41badb91\",\n \"accountId\": \"5bff4d736f86be0a41badb99\",\n \"tier\": 3,\n \"company\": \"companyName\",\n \"contractURL\": \"https://www.contractHere.com\",\n \"nominees\": [\"5bff4d736f86be0a41badb93\",\"5bff4d736f86be0a41badb94\"]\n }\n }"
18281827
}]
18291828
},
18301829
"error": {
@@ -1851,6 +1850,9 @@
18511850
"type": "object"
18521851
}]
18531852
},
1853+
"permission": [{
1854+
"name": ": Sponsor"
1855+
}],
18541856
"filename": "routes/api/sponsor.js",
18551857
"groupTitle": "Hacker",
18561858
"sampleRequest": [{
@@ -2313,6 +2315,100 @@
23132315
"url": "https://api.mchacks.ca/api/sponsor/:id"
23142316
}]
23152317
},
2318+
{
2319+
"type": "patch",
2320+
"url": "/sponsor/",
2321+
"title": "update a sponsor",
2322+
"name": "patchSponsor",
2323+
"group": "Sponsor",
2324+
"version": "1.3.0",
2325+
"parameter": {
2326+
"fields": {
2327+
"param": [{
2328+
"group": "param",
2329+
"type": "ObjectId",
2330+
"optional": false,
2331+
"field": "id",
2332+
"description": "<p>ObjectID of the sponsor</p>"
2333+
}],
2334+
"body": [{
2335+
"group": "body",
2336+
"type": "String",
2337+
"optional": false,
2338+
"field": "company",
2339+
"description": "<p>Name of the company.</p>"
2340+
},
2341+
{
2342+
"group": "body",
2343+
"type": "String",
2344+
"optional": false,
2345+
"field": "contractURL",
2346+
"description": "<p>URL link to the contract with the company.</p>"
2347+
},
2348+
{
2349+
"group": "body",
2350+
"type": "ObjectId[]",
2351+
"optional": false,
2352+
"field": "nominees",
2353+
"description": "<p>Array of accounts that the company wish to nominate as hackers.</p>"
2354+
}
2355+
]
2356+
}
2357+
},
2358+
"success": {
2359+
"fields": {
2360+
"Success 200": [{
2361+
"group": "Success 200",
2362+
"type": "String",
2363+
"optional": false,
2364+
"field": "message",
2365+
"description": "<p>Success message</p>"
2366+
},
2367+
{
2368+
"group": "Success 200",
2369+
"type": "Object",
2370+
"optional": false,
2371+
"field": "data",
2372+
"description": "<p>Sponsor object</p>"
2373+
}
2374+
]
2375+
},
2376+
"examples": [{
2377+
"title": "Success-Response: ",
2378+
"content": "{\n \"message\": \"Sponsor update successful\", \n \"data\": {...}\n }",
2379+
"type": "object"
2380+
}]
2381+
},
2382+
"error": {
2383+
"fields": {
2384+
"Error 4xx": [{
2385+
"group": "Error 4xx",
2386+
"type": "String",
2387+
"optional": false,
2388+
"field": "message",
2389+
"description": "<p>Error message</p>"
2390+
},
2391+
{
2392+
"group": "Error 4xx",
2393+
"type": "Object",
2394+
"optional": false,
2395+
"field": "data",
2396+
"description": "<p>empty</p>"
2397+
}
2398+
]
2399+
},
2400+
"examples": [{
2401+
"title": "Error-Response: ",
2402+
"content": "{\"message\": \"Error while updating sponsor\", \"data\": {}}",
2403+
"type": "object"
2404+
}]
2405+
},
2406+
"filename": "routes/api/sponsor.js",
2407+
"groupTitle": "Sponsor",
2408+
"sampleRequest": [{
2409+
"url": "https://api.mchacks.ca/api/sponsor/"
2410+
}]
2411+
},
23162412
{
23172413
"type": "post",
23182414
"url": "/team/",

0 commit comments

Comments
 (0)