[임예지] sprint11#33
Open
Bluemoon105 wants to merge 2 commits intocodeit-sprint-fullstack:express-임예지from
Hidden character warning
The head ref may contain hidden characters: "express-\uc784\uc608\uc9c0Sprint11"
Open
Conversation
kimjong95
approved these changes
Feb 12, 2025
Collaborator
kimjong95
left a comment
There was a problem hiding this comment.
typescript로 잘 마이그레이션 해주신것 같아요.
typescript 좀더 활용해본다면 request로 들어온 값들에대한 유효성검사를 할때 (prisma가 해주고 있지만)타입가드를 활용하거나 pagination 옵션으로 공통으로 사용되는 타입을들 구조화해서 사용할 수 있을것 같아요.
또한 typescript에서 interface를 적극적으로 활용해볼수도 있을것 같습니다.
| "skipLibCheck": true, | ||
| "strictNullChecks": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "noImplicitAny": false, |
Collaborator
There was a problem hiding this comment.
요구사항에따른 any타입에 대한 경고를위해 해당옵션은 true로 두는게 좋을것 같아요!
| import { diskStorage } from 'multer'; | ||
|
|
||
| // 🔹 req.user를 올바르게 인식하도록 인터페이스 정의 | ||
| interface AuthRequest extends Request { |
Collaborator
There was a problem hiding this comment.
AuthRequest부분이 여러 파일에 중복되어있는것 같아요.
Auth도메인에서 타입을 export해서 사용해주시면 좋을것 같습니다.
| tags?: string[]; | ||
| } | ||
|
|
||
| export class UpdateProductDto { |
Collaborator
There was a problem hiding this comment.
모든 필드가 CreateProductDto의 optional 형태라면 유틸타입을 사용해볼 수도 있을것 같아요
- export class UpdateProductDto {
- @IsOptional()
- @IsString()
- name?: string;
-
- @IsOptional()
- @IsString()
- description?: string;
-
- @IsOptional()
- @IsNumber()
- price?: number;
-
- @IsOptional()
- @IsString({ each: true })
- tags?: string[];
- }
+ export class UpdateProductDto extends PartialType(CreateProductDto) {}| return user; | ||
| } | ||
| return null; | ||
| } |
Collaborator
There was a problem hiding this comment.
위함수에서 유저의 검증이필요하고, 이에대한 에러처리를 각 컨트롤러에서 해주고 계실것 같아요.
result패턴을 조금 경량화해서 활용한다면 좀더 명확한 검사가 가능할것 같아요.
type ValidationResult =
| { isValid: true; user: User }
| { isValid: false; reason: 'USER_NOT_FOUND' | 'INVALID_PASSWORD' };
// reason대신 맞는 Error객체를 상속하여 커스텀하여도 좋을것 같아요
...
async validateUser(email: string, password: string): Promise<ValidationResult> {
const user = await this.prisma.user.findUnique({ where: { email } });
if (!user) {
return {
isValid: false,
reason: 'USER_NOT_FOUND'
};
}
const isPasswordValid = await bcrypt.compare(password, user.password);
if (!isPasswordValid) {
return {
isValid: false,
reason: 'INVALID_PASSWORD'
};
}
return {
isValid: true,
user
};
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
요구사항
기본 요구사항
공통
Github에 위클리 미션 PR을 만들어 주세요.
React 및 Express를 사용해 진행합니다.
TypeScript를 활용해 프로젝트의 필요한 곳에 타입을 명시해 주세요.
any 타입의 사용은 최소화해 주세요.
복잡한 객체 구조나 배열 구조를 가진 변수에 인터페이스 또는 타입 별칭을 사용하세요.
Union, Intersection, Generics 등 고급 타입을 적극적으로 사용해 주세요.
타입 별칭 또는 유틸리티 타입을 사용해 타입 복잡성을 줄여주세요.
타입스크립트 컴파일러가 에러 없이 정상적으로 작동해야 합니다.
백엔드
멘토에게