-
Notifications
You must be signed in to change notification settings - Fork 2
Teams leave #136
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
base: dev
Are you sure you want to change the base?
Teams leave #136
Changes from 3 commits
aa7b964
45e8dbe
e1245ae
78e0bc6
2f9e603
1f5b2b0
e4f7ba8
a60009d
c41193a
79ad216
05eaa6b
b2c44ac
6b4f24c
7318757
b2d6008
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 | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,131 @@ | ||||||
| import type { ValidatedEventAPIGatewayProxyEvent } from '@libs/api-gateway'; | ||||||
| import { middyfy } from '@libs/lambda'; | ||||||
| import schema from './schema'; | ||||||
| import { MongoDB, validateToken, UserDoc, TeamDoc, teamsDisband } from '../../../util'; //change to actual disband | ||||||
| import * as path from 'path'; | ||||||
| import * as dotenv from 'dotenv'; | ||||||
|
|
||||||
| //import fetch from 'node-fetch'; | ||||||
|
|
||||||
| dotenv.config({ path: path.resolve(process.cwd(), '.env') }); | ||||||
|
|
||||||
|
|
||||||
| const teamLeave: ValidatedEventAPIGatewayProxyEvent<typeof schema> = async (event) => { | ||||||
| try{ | ||||||
|
|
||||||
| const {auth_token, auth_email, team_id} = event.body; | ||||||
|
Check failure on line 16 in src/functions/teams/leave/handler.ts
|
||||||
|
|
||||||
| // 1. Validate auth token | ||||||
| const tokenValid = validateToken(auth_token, process.env.JWT_SECRET, auth_email); | ||||||
| if(!tokenValid){ | ||||||
| return{ | ||||||
| statusCode:401, | ||||||
| body: JSON.stringify({statusCode:401, message: 'Unauthorized'}) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // 2. connect to mongoDB | ||||||
| const db = MongoDB.getInstance(process.env.MONGO_URI); | ||||||
| await db.connect(); | ||||||
| const users = db.getCollection<UserDoc>('users'); | ||||||
| const teams = db.getCollection<TeamDoc>('teams'); | ||||||
|
|
||||||
| // 3. check if user exisits | ||||||
| const authUser = await users.findOne({email:auth_email}) | ||||||
| if(!authUser){ | ||||||
| return{ | ||||||
| statusCode: 404, | ||||||
| body: JSON.stringify({statusCode:404, message: 'Auth user not found'}) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // 4. check if team exisits | ||||||
| const team = await teams.findOne({team_id:team_id}) | ||||||
| if(!team){ | ||||||
| return{ | ||||||
| statusCode:404, | ||||||
| body: JSON.stringify({statusCode:404, message: 'Team not found'}) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // 5. Check if team is disbanded | ||||||
| if(team.status == "Disbanded"){ | ||||||
| return{ | ||||||
| statusCode:400, | ||||||
| body: JSON.stringify({statusCode:400, message: "Team already disbanded"}) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
Collaborator
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. Do a validation check on leader email. Simple
Collaborator
Author
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. Do you want this check to be done if the leader wants to leave the team or always when running this endpoint
Collaborator
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. Either or is fine. I think they are functionally equal so I'll leave it to your best judgement. |
||||||
| // 6. No team members | ||||||
| if(team.members.length == 0){ | ||||||
| return{ | ||||||
| statusCode: 400, | ||||||
| body: JSON.stringify({statusCode:400, message: 'Empty team member list'}) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // 7. Check if user is in team | ||||||
| if (!team.members.includes(auth_email)) { | ||||||
| return{ | ||||||
| statusCode: 400, | ||||||
| body: JSON.stringify({statusCode:400, message: 'User not in team'}) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| //grabs team info object | ||||||
| const teamInfo = authUser.team_info | ||||||
|
|
||||||
| // 8. Check if user is team lead | ||||||
| if(teamInfo.role == "leader"){ | ||||||
| return await teamsDisband(auth_token, auth_email, team_id); //mocked function replace with right funtion name | ||||||
|
||||||
| return await teamsDisband(auth_token, auth_email, team_id); //mocked function replace with right funtion name | |
| return await teamsDisband(auth_token, auth_email, team_id); //mocked function replace with right function name |
Copilot
AI
Aug 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a typo in the comment: 'mondoDB' should be 'MongoDB'.
| // 11. update the mondoDB user | |
| // 11. update the MongoDB user |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { handlerPath } from '@libs/handler-resolver'; | ||
| import schema from './schema'; | ||
|
|
||
| export default { | ||
| handler: `${handlerPath(__dirname)}/handler.main`, | ||
| events: [ | ||
| { | ||
| http: { | ||
| method: 'post', | ||
| path: 'teams/leave', | ||
| cors: true, | ||
| request: { | ||
| schemas: { | ||
| 'application/json': schema, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export default { | ||
| type: 'object', | ||
| properties: { | ||
| auth_token: { type: 'string' }, | ||
| auth_email: { type: 'string', format: 'email' }, | ||
| team_id: {type:"string"} | ||
| }, | ||
| required: ['auth_token', 'auth_email', 'team_id'], | ||
| } as const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The comment indicates this is temporary code that needs to be replaced. Consider using a proper TODO comment format like
// TODO: Replace teamsDisband with actual implementation.