Skip to content

Conversation

@subinkim9755
Copy link
Collaborator

요구사항

기본

  • [ o ] 기존 Express.js 프로젝트를 타입스크립트 프로젝트로 마이그레이션 해주세요.
  • [ o ] tsconfig.json 파일을 생성하고, 필요한 컴파일러 옵션을 설정해야 합니다. (예: outDir).
  • [ o ] TypeScript 관련 명령어를 package.json에 설정해 주세요. (예: 빌드 및 개발 서버 실행 명령어).
  • [ o ] ts-node와 nodemon을 사용하여 개발 환경을 구성합니다.
  • [ o ] nodemon과 함께 ts-node를 사용하여 . ts 파일이 변경될 때 서버를 자동으로 재시작하도록 설정합니다.
  • [ o ] Mongoose나 Prisma 등 ORM을 사용하는 경우, 모델에 대한 인터페이스 또는 타입을 정의합니다.
  • [ o ] 필요한 경우, declare를 사용하여 타입을 오버라이드하거나 확장합니다.

심화

  • [x]
  • []

주요 변경사항

스크린샷

image

멘토에게

-기존에 구현하지 않은 기능도 있고 코드가 지저분해서 추후 리펙토링 예정입니다 ㅠ
-타입지정만으로도 힘들어서 이번에는 리펙토링을 하지 못햇습니다.

  • 셀프 코드 리뷰를 통해 질문 이어가겠습니다.

Copy link
Contributor

@basilry basilry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적으로 잘 하셨습니다.

백엔드가 상대적으로 프론트보다 분량이 적긴 하죠^^;

고생하셨습니다.

res.json(articles);
};

// export const createComment = async (req: Request, res: Response) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 개발하다가 잠시 멈추신것이겠죠?

throw new HttpError(400, '리프레시 토큰이 필요합니다');
}

// const result = await authService.refreshAccessToken(refreshToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

보통 pr이나 코드리뷰 전에는 이런 주석처리된 소스들은 설명을 달거나 삭제합니다.


const comment = await commentService.createArticleComment(
userId,
userId!,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 지속적으로 반복되는데, 이건 컴파일러에게 그냥 속이는게 아닌가요?
만약에 실제로 userId가 해당 서비스 함수에서 원하는 값이 안들어오면 어떻게 하죠?
차라리 아래처럼 타입가드를 처리하는게 낫지 않을까요?

if (typeof userId !== "number") {
  throw new HttpError(401, 'Unauthorized');
}

const products = await productService.getProducts({
page: parseInt(page as string, 10),
pageSize: parseInt(pageSize as string, 10),
orderBy: orderBy as string | undefined,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜 as를 이렇게 많이 쓰셨나요.

강제로 타입캐스팅을 하는 것보다 인터페이스, 타입을 써서 객체에 할당하는게 낫지 않을까요?

아니면 로직을 수정해서 page: typeof page === "string" ? Number(page) : page로 하는게 낫지 않나요?

참고로 parseInt보다 Number가 메모리를 덜 먹고, 더 빠릅니다.

@@ -10,8 +10,8 @@ router.get('/', errorHandler(articleController.getArticles));
router.get('/:articleId', errorHandler(articleController.getArticle));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

보아하니 에러핸들링을 개별 라우터마다 모두 달아두었는데,

이러지 마시고 app.ts에서 맨 마지막 부분쯤에

app.use(globalErrorHandler);

처럼 구성하는게 낫지 않을까요??

export const updateArticle = async (id: number, data: Pick<Article, 'title' | 'content'>) => {
const entity = await articleRepository.Update(id, data);
if (!entity) throw new HttpError(404, '게시글이 존재하지 않습니다');
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개발 중인 부분이겠죠?

@basilry basilry merged commit fbeea7b into codeit-sprint-fullstack:express-김수빈 Jun 24, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants