Skip to content

Commit

Permalink
Refactor getBlurtingNo method in BlurtingController and BlurtingService
Browse files Browse the repository at this point in the history
This commit refactors the `getBlurtingNo` method in the `BlurtingController` and `BlurtingService` files. The changes include removing unnecessary code, improving code readability, and fixing a bug related to checking if a user has liked a post.
  • Loading branch information
overthestream committed Jan 9, 2024
1 parent 583f833 commit 306886c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
26 changes: 9 additions & 17 deletions src/blurting/blurting.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Body,
Param,
Put,
NotFoundException,
} from '@nestjs/common';
import { Request, Response } from 'express';
import { BlurtingService } from './blurting.service';
Expand Down Expand Up @@ -273,24 +274,15 @@ export class BlurtingController {
description: '선택 Q&A 정보 반환',
type: BlurtingPageDto,
})
async getBlurtingNo(
@Req() req: Request,
@Param('no') no: number,
@Res() res: Response,
) {
async getBlurtingNo(@Req() req: Request, @Param('no') no: number) {
const { id } = req.user as JwtPayload;
const user = await this.userService.findUserByVal('id', id);
if (user.group == null) return res.sendStatus(404);
try {
const blurtingPage = await this.blurtingService.getBlurting(
id,
user.group,
no,
);
return res.json(blurtingPage);
} catch (error) {
console.log(error);
return res.status(error.status).json(error);
}
if (user.group == null) throw new NotFoundException();
const blurtingPage = await this.blurtingService.getBlurting(
id,
user.group,
no,
);
return blurtingPage;
}
}
5 changes: 1 addition & 4 deletions src/blurting/blurting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,8 @@ export class BlurtingService {
},
},
});

let iLike = false;
if (likes.filter((item) => item.userId === user.id).length > 0)
iLike = true;
if (likes.filter((item) => item.userId === id).length > 0) iLike = true;

if (answerEntity.user == null) {
return BlurtingAnswerDto.ToDto(
Expand Down Expand Up @@ -219,7 +217,6 @@ export class BlurtingService {
);
}),
);

const blurtingPage: BlurtingPageDto = BlurtingPageDto.ToDto(
group,
question,
Expand Down

0 comments on commit 306886c

Please sign in to comment.