- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Ojn03/feat update user #12
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
Conversation
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.
💯 great job on this! Just a couple notes here and there
| @@ -0,0 +1,31 @@ | |||
| // TODO: Probably want these types to be available to both the frontend and backend in a "common" folder | |||
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.
💯
| APPLICANT = 'Applicant', | ||
| } | ||
|  | ||
| export enum Team { | 
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.
💭 should we add EBOARD as one of the possible values for this enum since the roles also contain all of the eboard positions? I think this will depend on what the purpose of the team property is (which we should follow up with product about)
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.
Im not too familiar with how the org's structure should be represented here but this does sound sensible. I think once we get clearer specifications, we can make a quick change here
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.
I added EBOARD to the types. We can see what the purpose of the team property is and remove it if necessary
        
          
                apps/backend/src/users/types.ts
              
                Outdated
          
        
      | DIRECTOR_OF_FINANCE = 'Director of Finance', | ||
| DIRECTOR_OF_MARKETING = 'Director of Marketing', | ||
| DIRECTOR_OF_RECRUITMENT = 'Director of Recruitment', | ||
| CO_DIRECTOR_OF_OPERATIONS = 'Co-Director of Operations', | 
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.
🔧 can we take out the CO_ prefix from ops and events? It's only fairly recent that we started having co-directors (so that we'll probably have just one co-director of ops in a year or two again) and we could theoretically have multiple people with the same position for most of the other director-level positions as well. And some teams have co-tech leads too so I think it'll be better to just ignore the "co-" part and we'll know if there are co-directors if there are multiple people with the same role
| export class User { | ||
| @PrimaryGeneratedColumn() | ||
| id: number; | ||
| @ObjectIdColumn() | 
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.
🔧 just to make our lives easier, I think we should have this column be a number column instead so we're not dealing with too many ObjectIds (which can get a little tedious):
  @Column({ primary: true })
  userId: number;| return this.usersService.findAll(); | ||
| } | ||
|  | ||
| @Put(':userId') | 
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.
⛏️ should this be a patch route?
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.
⛏️ could we be able to update the name of this file to update-user.dto.ts? Generally, for a dto, we want the name to be name-of-the-dto.dto.ts so that it's easier to tell which file contains which dto
        
          
                apps/backend/src/users/users.dto.ts
              
                Outdated
          
        
      | profilePicture?: string; | ||
|  | ||
| @IsOptional() | ||
| linkedIn?: string; | 
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.
⛏️ for linkedIn and github properties, can we also make sure that they're links (i.e. @IsUrl())?
| } | ||
|  | ||
| async updateUser( | ||
| UpdateUserDTO: UpdateUserDTO, | 
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.
⛏️ can we make UpdateUserDTO camelCase?
| UpdateUserDTO: UpdateUserDTO, | |
| updateUserDTO: UpdateUserDTO, | 
| await this.usersRepository.update(id, UpdateUserDTO); | ||
| return await this.usersRepository.findOne({ | ||
| where: { | ||
| _id: { $eq: id }, | ||
| }, | ||
| }); | 
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.
⛏️ does something like this also work?
| await this.usersRepository.update(id, UpdateUserDTO); | |
| return await this.usersRepository.findOne({ | |
| where: { | |
| _id: { $eq: id }, | |
| }, | |
| }); | |
| return await this.usersRepository.save(id, UpdateUserDTO); | 
| ); | ||
| } | ||
|  | ||
| if ( | 
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.
❓ does this mean that only admins can update other people's info? If so, do the two checks above (on lines 63 and 72) check anything that this check misses (in other words, is it possible for someone to change someone's info such that it triggers the checks on either 63 or 72 but not the check on line 82)?
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.
👍 Just two small nitpicks but looks great overall!
| if (exampleUser.status == Status.APPLICANT) { | ||
| const currentUser = getCurrentUser(); | ||
|  | ||
| if (currentUser.status == Status.APPLICANT) { | 
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.
⛏️
| if (currentUser.status == Status.APPLICANT) { | |
| if (currentUser.status === Status.APPLICANT) { | 
|  | ||
| @IsOptional() | ||
| @IsUrl({ | ||
| protocols: ['http', 'https'], | 
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.
⛏️ Very cool! If we do this, I think we should restrict the protocol to just https. Linkedin and github both support https and there's no reason to prefer http over https
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.
Great Job!
|  | ||
| @Column() | ||
| profilePicture: string; | ||
| profilePicture: string | null; | 
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.
💭 maybe instead of having a null profilePicture, we could have a placeholder picture? Just an idea, maybe for a future enhancement
* feat: completed updateUser endpoint resolves #5 * style: used strict comparison operators and modified error messages * added error handling for objectID * feat: added input validation to UpdateUserDTO * fix: applied suggestions from PR review * fix: added domain specific URL validators for DTO * fix: converted ObjectId primary column to numbers and finalized PR suggestions * fix: strict equality and https restricted protocol --------- Co-authored-by: Harrison Kim <kim.harr@northeastern.edu>
ℹ️
Closes #5
📝 Description
Added an endpoint that allows users to update information in the database so that:
Briefly list the changes made to the code:
✔️ Verification
Created an exampleUser (lets call him Bob) to simulate endpoint callers. Created a local MongoDB database "c4cOpsTest" with multiple users and updated Bob to check for expected behavior in the following scenarios:
🏕️ (Optional) Future Work / Notes