Skip to content

Commit

Permalink
🔨 fix(user) : user entity eager false null 타입 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ImNM committed Aug 6, 2022
1 parent fd3f2c1 commit 8ca0572
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/database/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ export class User {
public role: Role;

@OneToMany(type => Comment, comment => comment.user, { eager: false })
public comments: Comment[];
public comments: Comment[] | null;

@ApiProperty({
description: '유저의 주문목록',
type: () => [Order]
})
@Expose()
@OneToMany(type => Order, order => order.user, { eager: false })
public order: Order[];
public order: Order[] | null;

@ApiProperty({
description: '유저의 티켓목록',
type: () => [Ticket]
})
@Expose()
@OneToMany(type => Ticket, ticket => ticket.user, { eager: false })
public ticket: Ticket[];
public ticket: Ticket[] | null;

@ApiProperty({
description: '유저 생성 일자',
Expand Down
17 changes: 8 additions & 9 deletions src/database/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class UserRepository {
) {}

async getMyInfo(user: User) {
return await this.userRepository.findOne({ where : {id: user.id}});
return await this.userRepository.findOne({ where: { id: user.id } });
}

async findByPhoneNumber(phoneNumber: string): Promise<User | null> {
Expand Down Expand Up @@ -57,7 +57,7 @@ export class UserRepository {

// 유저 정보 조회(관리자용) 전체 정보 조회
async getAllUserInfo(
userFindDto: UserFindDto,
userFindDto: UserFindDto,
pageOptionsDto: PageOptionsDto
) {
const { searchName, phoneNumber } = userFindDto;
Expand All @@ -82,18 +82,18 @@ export class UserRepository {
.addSelect('ticket')
.skip(pageOptionsDto.skip)
.take(pageOptionsDto.take);

const itemCount = await queryBuilder.getCount();
const { entities } = await queryBuilder.getRawAndEntities();

const pageMetaDto = new PageMetaDto({ itemCount, pageOptionsDto })
return new PageDto(entities, pageMetaDto);
const pageMetaDto = new PageMetaDto({ itemCount, pageOptionsDto });

return new PageDto(entities, pageMetaDto);
}

// 입금자명 수정
async changeName(id: number, requestUserNameDto: RequestUserNameDto) {
const found = await this.userRepository.findOne({ where: {id: id}});
const found = await this.userRepository.findOne({ where: { id: id } });

if (!found) {
throw new NotFoundException('해당 유저가 존재하지 않습니다.');
Expand All @@ -105,5 +105,4 @@ export class UserRepository {
await this.userRepository.save(found);
return plainToInstance(UserProfileDto, found);
}

}
}
48 changes: 30 additions & 18 deletions src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,31 @@ export class UsersService {
async findUserById(id: number): Promise<User | null> {
return await this.userRepository.findUserById(id);
}

// 유저 정보 조회(관리자용) 전체 정보 조회
async getAllUserInfo(userFindDto: UserFindDto, pageOptionsDto: PageOptionsDto) {
const pageDto = await this.userRepository.getAllUserInfo(userFindDto, pageOptionsDto);
async getAllUserInfo(
userFindDto: UserFindDto,
pageOptionsDto: PageOptionsDto
) {
const pageDto = await this.userRepository.getAllUserInfo(
userFindDto,
pageOptionsDto
);
const pageMetaData = pageDto.meta;
const users = pageDto.data;
const ret_users = users.map(function(user) {
const ret_users = users.map(function (user) {
const userProfile = {
id: user.id,
name: user.name,
phoneNumber: user.phoneNumber,
role: user.role,
createAt: user.createdAt,
ticketNum: user.ticket.length
}
ticketNum: user.ticket?.length
};
return userProfile;
})
const entities = plainToInstance(ResponseUserTicketNumDto, ret_users)
});
const entities = plainToInstance(ResponseUserTicketNumDto, ret_users);

return new PageDto(entities, pageMetaData);
}

Expand All @@ -69,28 +75,34 @@ export class UsersService {

// 모든 댓글 조회
async getAllComment(userId: number, scrollOptionsDto: ScrollOptionsDto) {
const responseScrollCommentDto = await this.commentRepository.getAllComment(userId, scrollOptionsDto);
const responseScrollCommentDto = await this.commentRepository.getAllComment(
userId,
scrollOptionsDto
);
const comments = responseScrollCommentDto.list;
const ret_comments = comments.map(function(comment) {
const ret_comments = comments.map(function (comment) {
const responseCommentDto = {
...comment,
iUserId: userId
}
return responseCommentDto;
}
)
};
return responseCommentDto;
});
const final_comments = plainToInstance(ResponseCommentDto, ret_comments);
return new ResponseScrollCommentsDto(final_comments, responseScrollCommentDto.meta);
return new ResponseScrollCommentsDto(
final_comments,
responseScrollCommentDto.meta
);
}

// 댓글 랜덤 조회
async getRandomComment(requestRandomCommentDto: RequestRandomCommentDto) {
return await this.commentRepository.getRandomComment(requestRandomCommentDto);
return await this.commentRepository.getRandomComment(
requestRandomCommentDto
);
}

// 댓글 삭제
async deleteComment(id: number) {
return await this.commentRepository.deleteComment(id);
}

}

0 comments on commit 8ca0572

Please sign in to comment.