-
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
Changes from all commits
429c9bb
e2dc648
ebd101b
f46f10c
4dbc239
58b60da
a046a91
1571920
d40835b
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,7 +1,33 @@ | ||
| // 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 commentThe reason will be displayed to describe this comment to others. Learn more. 💯 |
||
| export enum Status { | ||
| MEMBER = 'MEMBER', | ||
| RECRUITER = 'RECRUITER', | ||
| ADMIN = 'ADMIN', | ||
| ALUMNI = 'ALUMNI', | ||
| APPLICANT = 'APPLICANT', | ||
| MEMBER = 'Member', | ||
| RECRUITER = 'Recruiter', | ||
| ADMIN = 'Admin', | ||
| ALUMNI = 'Alumni', | ||
| APPLICANT = 'Applicant', | ||
| } | ||
|
|
||
| export enum 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. 💭 should we add 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. I added |
||
| SFTT = 'Speak For The Trees', | ||
| CONSTELLATION = 'Constellation', | ||
| JPAL = 'J-PAL', | ||
| BREAKTIME = 'Breaktime', | ||
| GI = 'Green Infrastructure', | ||
| CI = 'Core Infrastructure', | ||
| EBOARD = 'E-Board', | ||
| } | ||
|
|
||
| export enum Role { | ||
| DIRECTOR_OF_ENGINEERING = 'Director of Engineering', | ||
| DIRECTOR_OF_PRODUCT = 'Director of Product', | ||
| DIRECTOR_OF_FINANCE = 'Director of Finance', | ||
| DIRECTOR_OF_MARKETING = 'Director of Marketing', | ||
| DIRECTOR_OF_RECRUITMENT = 'Director of Recruitment', | ||
| DIRECTOR_OF_OPERATIONS = 'Director of Operations', | ||
| DIRECTOR_OF_EVENTS = 'Director of Events', | ||
| DIRECTOR_OF_DESIGN = 'Director of Design', | ||
| PRODUCT_MANAGER = 'Product Manager', | ||
| PRODUCT_DESIGNER = 'Product Designer', | ||
| TECH_LEAD = 'Technical Lead', | ||
| DEVELOPER = 'Developer', | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { Status, Role, Team } from './types'; | ||
| import { | ||
| IsEmail, | ||
| IsOptional, | ||
| IsEnum, | ||
| IsArray, | ||
| ArrayMinSize, | ||
| ArrayUnique, | ||
| IsUrl, | ||
| } from 'class-validator'; | ||
|
|
||
| export class UpdateUserDTO { | ||
| @IsOptional() | ||
| @IsEnum(Status) | ||
| status?: Status; | ||
|
|
||
| @IsOptional() | ||
| @IsEmail() | ||
| email?: string; | ||
|
|
||
| @IsOptional() | ||
| profilePicture?: string; | ||
|
|
||
| @IsOptional() | ||
| @IsUrl({ | ||
| protocols: ['https'], | ||
| require_protocol: true, | ||
| host_whitelist: ['www.linkedin.com'], | ||
| }) | ||
| linkedin?: string; | ||
|
|
||
| @IsOptional() | ||
| @IsUrl({ | ||
| protocols: ['https'], | ||
| require_protocol: true, | ||
| host_whitelist: ['github.com'], | ||
| }) | ||
| github?: string; | ||
|
|
||
| @IsOptional() | ||
| @IsEnum(Team) | ||
| team?: Team; | ||
|
|
||
| @IsOptional() | ||
| @IsArray() | ||
| @ArrayMinSize(1) | ||
| @ArrayUnique() | ||
| @IsEnum(Role, { each: true }) | ||
| role?: Role[]; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| import { Entity, Column, ObjectIdColumn, ObjectId } from 'typeorm'; | ||
| import { Status } from './types'; | ||
| import { Entity, Column } from 'typeorm'; | ||
| import { Status, Role, Team } from './types'; | ||
|
|
||
| @Entity() | ||
| export class User { | ||
| @ObjectIdColumn() // https://github.com/typeorm/typeorm/issues/1584 | ||
| userId: ObjectId; | ||
| @Column({ primary: true }) | ||
| userId: number; | ||
|
|
||
| @Column() | ||
| status: Status; | ||
|
|
@@ -18,7 +19,7 @@ export class User { | |
| email: string; | ||
|
|
||
| @Column() | ||
| profilePicture: string; | ||
| profilePicture: string | null; | ||
|
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. 💭 maybe instead of having a null profilePicture, we could have a placeholder picture? Just an idea, maybe for a future enhancement |
||
|
|
||
| @Column() | ||
| linkedin: string | null; | ||
|
|
@@ -27,8 +28,8 @@ export class User { | |
| github: string | null; | ||
|
|
||
| @Column() | ||
| team: string | null; | ||
| team: Team | null; | ||
|
|
||
| @Column() | ||
| role: string | null; | ||
| role: Role[] | null; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,16 @@ import { | |
| DefaultValuePipe, | ||
| ParseBoolPipe, | ||
| Query, | ||
| Body, | ||
| Controller, | ||
| Get, | ||
| Param, | ||
| Patch, | ||
| ParseIntPipe, | ||
| } from '@nestjs/common'; | ||
|
|
||
| import { UpdateUserDTO } from './update-user.dto'; | ||
| import { UsersService } from './users.service'; | ||
| import { User } from './user.entity'; | ||
|
|
||
| @Controller('users') | ||
|
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. ⛏️ can we put a newline before this line (just to more visually separate the imports from the actual controller code)? |
||
| export class UsersController { | ||
|
|
@@ -19,4 +24,12 @@ export class UsersController { | |
| ) { | ||
| return this.usersService.findAll(getAllMembers); | ||
| } | ||
|
|
||
| @Patch(':userId') | ||
| async updateUser( | ||
| @Body() updateUserDTO: UpdateUserDTO, | ||
| @Param('userId', ParseIntPipe) userId: number, | ||
| ): Promise<User> { | ||
| return this.usersService.updateUser(updateUserDTO, userId); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Status } from './types'; | ||
| import { User } from './user.entity'; | ||
|
|
||
| export const getCurrentUser = (): User => ({ | ||
| userId: 999, | ||
| status: Status.ADMIN, | ||
| firstName: 'jimmy', | ||
| lastName: 'jimmy2', | ||
| email: 'jimmy.jimmy2@mail.com', | ||
| profilePicture: null, | ||
| linkedin: null, | ||
| github: null, | ||
| team: null, | ||
| role: 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.
🔥