Skip to content

Commit

Permalink
✨ appending author on server on POST /board
Browse files Browse the repository at this point in the history
- 글 수정, 삭제 시 author를 사용자 임의가 아닌 서버에서 정의되도록 수정
  • Loading branch information
qkrwogk committed Nov 22, 2023
1 parent dab384b commit 628ff4c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 9 additions & 1 deletion packages/server/src/board/board.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ export class BoardController {
status: 400,
description: '잘못된 요청으로 게시글 작성 실패',
})
createBoard(@Body() createBoardDto: CreateBoardDto): Promise<Board> {
createBoard(
@Req() req,
@Body() createBoardDto: CreateBoardDto,
): Promise<Board> {
if (req.user && req.user.nickname)
createBoardDto.author = req.user.nickname;
return this.boardService.createBoard(createBoardDto);
}

Expand Down Expand Up @@ -102,9 +107,12 @@ export class BoardController {
description: '잘못된 요청으로 게시글 수정 실패',
})
updateBoard(
@Req() req,
@Param('id', ParseIntPipe) id: number,
@Body() updateBoardDto: UpdateBoardDto,
) {
if (req.user && req.user.nickname)
updateBoardDto.author = req.user.nickname;
return this.boardService.updateBoard(id, updateBoardDto);
}

Expand Down
17 changes: 9 additions & 8 deletions packages/server/src/board/dto/create-board.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ export class CreateBoardDto {
})
content: string;

@IsNotEmpty({ message: '게시글 작성자는 필수 입력입니다.' })
@IsString({ message: '게시글 작성자는 문자열로 입력해야 합니다.' })
@MaxLength(50, { message: '게시글 작성자는 50자 이내로 입력해야 합니다.' })
@ApiProperty({
description: '게시글 작성자',
example: 'test author',
required: true,
})
// 서버에서 직접 삽입해주도록 변경 (validation 제거)
// @IsNotEmpty({ message: '게시글 작성자는 필수 입력입니다.' })
// @IsString({ message: '게시글 작성자는 문자열로 입력해야 합니다.' })
// @MaxLength(50, { message: '게시글 작성자는 50자 이내로 입력해야 합니다.' })
// @ApiProperty({
// description: '게시글 작성자',
// example: 'test author',
// required: true,
// })
author: string;
}

0 comments on commit 628ff4c

Please sign in to comment.