Skip to content

Commit

Permalink
refactor: Update UpdateUserDTO to allow nullable name field
Browse files Browse the repository at this point in the history
  • Loading branch information
PleBea committed Jul 13, 2024
1 parent 4b0e223 commit c4de1e0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/modules/user/dto/update-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Prisma } from '@prisma/client';
import { IsOptional, IsString } from 'class-validator';

import { ApiProperty } from '@nestjs/swagger';

export class UpdateUserDTO implements Prisma.UserUpdateInput {
@ApiProperty({
required: false,
nullable: true,
})
@IsString()
@IsOptional()
name?: string | null;
}
1 change: 1 addition & 0 deletions src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class UserController {
})
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
async updateUser(@CurrentUser() user: User, @Body() data: UpdateUserDTO): Promise<ResponseDTO<null>> {
console.log(data);
try {
await this.userService.updateUserById(user.id, data);
return { status: 'success', data: null };
Expand Down
1 change: 1 addition & 0 deletions src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class UserService {
async updateUserById(id: string, data: Prisma.UserUpdateInput) {
const user = await this.prisma.user.findUnique({ where: { id } });
if (!user) throw new HttpException('User not found', HttpStatus.NOT_FOUND);
console.log(data);

await this.prisma.user.update({
where: { id },
Expand Down

0 comments on commit c4de1e0

Please sign in to comment.