Skip to content

Commit

Permalink
feat: 스노우볼 아이디로 유저 조회하여 메세지 카운트 하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
yunuo46 committed Dec 11, 2023
1 parent ffc4610 commit 575d694
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion back/src/modules/snowball/snowball.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export class SnowballController {
@Param('snowball_id') snowball_id: number
) {
const resGetSnowballDto = await this.snowballService.getResGetSnowballDto(
req.user.id,
snowball_id,
req.hasToken
);
Expand Down
12 changes: 11 additions & 1 deletion back/src/modules/snowball/snowball.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,29 @@ export class SnowballService {
}

async getResGetSnowballDto(
user_id: number,
snowball_id: number,
hasToken: boolean
): Promise<ResGetSnowballDto> {
const snowball = await this.getSnowball(snowball_id, hasToken);
if (!snowball) throw new NotFoundException('스노우볼을 찾을 수 없습니다.');
const user_id = await this.getUserId(snowball_id);
const resGetSnowball = {
message_count: await this.messageService.getMessageCount(user_id),
snowball
};
return plainToInstance(ResGetSnowballDto, resGetSnowball);
}

async getUserId(snowball_id: number): Promise<number> {
const user = await this.snowballRepository.findOne({
where: { id: snowball_id },
select: ['user_id']
});
if (!user)
throw new NotFoundException('스노우볼을 소유한 유저를 찾을 수 없습니다.');
return user.id;
}

async doesDecorationExist(decoration_id: number): Promise<boolean> {
const decoration = await this.snowballDecoRepository.findOne({
where: { id: decoration_id, active: true }
Expand Down

0 comments on commit 575d694

Please sign in to comment.