-
Notifications
You must be signed in to change notification settings - Fork 8
Feature/278 team leave #279
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
Changes from all commits
d1d03df
e3efbbe
a73f9cf
ea6cf77
1d3d8b3
92834d8
a21ed81
2aefcac
02a1962
a989af3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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-07T03:26:47.443Z", | ||
| "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-08T22:07:07.661Z", | ||
| "url": "http://apidocjs.com", | ||
| "version": "0.17.7" | ||
| } | ||
| }); |
| 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-07T03:26:47.443Z", | ||
| "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-08T22:07:07.661Z", | ||
| "url": "http://apidocjs.com", | ||
| "version": "0.17.7" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,34 @@ async function findById(req, res, next) { | |
| return next(); | ||
| } | ||
|
|
||
| /** | ||
| * @async | ||
| * @function deleteUserFromTeam | ||
| * @param {{user: {id: ObjectId}} req | ||
| * @param {*} res | ||
| * @return {JSON} Success or error status | ||
| * @description Removes the hacker associated with req.user.id from the team under teamId. If hacker is not part of a team, it does nothing. | ||
| */ | ||
| async function deleteUserFromTeam(req, res, next) { | ||
| const hacker = await Services.Hacker.findByAccountId(req.user.id); | ||
|
|
||
| if (!hacker) { | ||
| return next({ | ||
| status: 404, | ||
| message: Constants.Error.HACKER_404_MESSAGE, | ||
| data: { | ||
| id: req.user.id | ||
| } | ||
| }); | ||
| } | ||
| const oldTeamId = hacker.teamId; | ||
| if (oldTeamId) { | ||
| await Services.Team.removeMember(oldTeamId, hacker._id); | ||
| await Services.Team.removeTeamIfEmpty(oldTeamId); | ||
| } | ||
| next(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we put in some kind of error if oldTeamId doesn't exist? What do you think should be the output if the hacker was never part of a team? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the resulting database state is the same, returning success should be fine. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good |
||
| } | ||
|
|
||
| /** | ||
| * @async | ||
| * @function updateHackerTeam | ||
|
|
@@ -343,7 +371,7 @@ async function parseNewTeam(req, res, next) { | |
| } | ||
|
|
||
| // hacker should not be in another team | ||
| if (hacker.teamId !== undefined) { | ||
| if (hacker.teamId !== undefined && hacker.teamId !== null) { | ||
| return next({ | ||
| status: 409, | ||
| message: Constants.Error.TEAM_MEMBER_409_MESSAGE, | ||
|
|
@@ -366,4 +394,5 @@ module.exports = { | |
| parseNewTeam: Util.asyncMiddleware(parseNewTeam), | ||
| ensureFreeTeamName: Util.asyncMiddleware(ensureFreeTeamName), | ||
| populateMemberAccountsById: Util.asyncMiddleware(populateMemberAccountsById), | ||
| deleteUserFromTeam: Util.asyncMiddleware(deleteUserFromTeam), | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.