Skip to content

Commit

Permalink
Merge pull request #68 from modern-agile-team/feature/board-user
Browse files Browse the repository at this point in the history
  • Loading branch information
2swo authored Oct 23, 2023
2 parents d0da61f + c8bd796 commit 68f720d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/boards/controllers/Boards.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class BoardsController {
async findPageBoards(
@Query('page') page = 1,
@Query('limit') limit = 30,
): Promise<BoardResponseDTO[]> {
): Promise<{ data: BoardResponseDTO[]; total: number }> {
return await this.boardsService.findPagedBoards(page, limit);
}

Expand All @@ -66,7 +66,6 @@ export class BoardsController {

@Patch('')
async editBoard(
// @Headers('accesstoken')
@Query('boardId') boardId: number,
@Body() boardData: Partial<Board>,
): Promise<Board> {
Expand Down
5 changes: 4 additions & 1 deletion src/boards/repository/boards.repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { EntityManager } from 'typeorm';
import { Board } from '../entities/board.entity';
import { CreateBoardDto } from '../dto/create.board.dto';
// import { User } from 'src/users/entities/user.entity';
import { Injectable } from '@nestjs/common';

@Injectable()
Expand All @@ -18,6 +17,10 @@ export class BoardRepository {
return await this.entityManager.save(Board, board);
}

async findTotalBoards(): Promise<number> {
return this.entityManager.count(Board);
}

async findPagedBoards(skip: number, limit: number): Promise<Board[]> {
return await this.entityManager.find(Board, {
relations: ['user', 'user.userImage', 'boardImages'],
Expand Down
8 changes: 5 additions & 3 deletions src/boards/services/Boards.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ export class BoardsService {
async findPagedBoards(
page: number,
limit: number,
): Promise<BoardResponseDTO[]> {
): Promise<{ data: BoardResponseDTO[]; total: number }> {
const skip = (page - 1) * limit;
const take = limit;
const boards = await this.boardRepository.findPagedBoards(skip, take);
return boards.map((board) => ({
const total = await this.boardRepository.findTotalBoards();
const boardResponse: BoardResponseDTO[] = boards.map((board) => ({
id: board.id,
head: board.head,
body: board.body.substring(0, 30),
Expand All @@ -31,7 +32,6 @@ export class BoardsService {
createAt: board.createAt,
updateAt: board.updateAt,
userId: {
// userid 중복으로 보내지는거 수정해야함.추후 수정예정
id: board.user.id,
name: board.user.name,
userImage: board.user.userImage ? board.user.userImage : [],
Expand All @@ -41,6 +41,8 @@ export class BoardsService {
imageUrl: image.imageUrl,
})),
}));

return { data: boardResponse, total };
}

async findOneBoard(boardId: number): Promise<BoardResponseDTO> {
Expand Down

0 comments on commit 68f720d

Please sign in to comment.