-
Notifications
You must be signed in to change notification settings - Fork 0
[SSF-102] Add endpoints to update user info #79
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: main
Are you sure you want to change the base?
Changes from all commits
b968ae0
5830938
bd3f846
061c4a8
8a8420c
6411d03
dc91943
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,24 @@ | ||
| import { IsString, IsPhoneNumber, IsOptional, IsNotEmpty, MaxLength } from 'class-validator'; | ||
|
|
||
| export class updateUserInfo { | ||
| @IsOptional() | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| @MaxLength(255) | ||
| firstName?: string; | ||
|
|
||
| @IsOptional() | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| @MaxLength(255) | ||
| lastName?: string; | ||
|
|
||
| @IsOptional() | ||
| @IsString() | ||
swarkewalia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @IsNotEmpty() | ||
| @IsPhoneNumber('US', { | ||
| message: | ||
| 'phone must be a valid phone number (make sure all the digits are correct)', | ||
| }) | ||
| phone?: string; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import { UsersService } from './users.service'; | |
| import { User } from './user.entity'; | ||
| import { Role } from './types'; | ||
| import { userSchemaDto } from './dtos/userSchema.dto'; | ||
| import { updateUserInfo } from './dtos/updateUserInfo.dto'; | ||
| import { Pantry } from '../pantries/pantries.entity'; | ||
|
|
||
| @Controller('users') | ||
|
|
@@ -54,6 +55,21 @@ export class UsersController { | |
| return this.usersService.update(id, { role: role as Role }); | ||
| } | ||
|
|
||
| @Put(':id/info') | ||
| async updateInfo( | ||
| @Param('id', ParseIntPipe) id: number, | ||
| @Body() updateUserInfo: updateUserInfo, | ||
|
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. Thoughts on making this change here: We already have an update user role, and are now maing an update info endpoint. Would we rather have two separate updates, or just abstract this
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. If we needed both endpoints I would suggest keeping them separate for the sake of letting any user type call this endpoint, but limiting the update role endpoint to admins. But now that we have combined standard and lead volunteers, there is no longer any use case for updating a user's role, so we should just remove that endpoint. |
||
| ): Promise<User> { | ||
| const { firstName, lastName, phone } = updateUserInfo; | ||
|
|
||
| const updateData: Partial<User> = {}; | ||
|
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. Due to Sam's comment above, can we just make it so tha |
||
| if (firstName !== undefined) updateData.firstName = firstName; | ||
| if (lastName !== undefined) updateData.lastName = lastName; | ||
| if (phone !== undefined) updateData.phone = phone; | ||
|
|
||
| return this.usersService.update(id, updateData); | ||
| } | ||
|
|
||
| @Post('/') | ||
| async createUser(@Body() createUserDto: userSchemaDto): Promise<User> { | ||
| const { email, firstName, lastName, phone, role } = createUserDto; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.