-
Notifications
You must be signed in to change notification settings - Fork 14
[임예지] sprint11 #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: express-임예지
Are you sure you want to change the base?
[임예지] sprint11 #33
The head ref may contain hidden characters: "express-\uC784\uC608\uC9C0Sprint11"
Conversation
kimjong95
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typescript로 잘 마이그레이션 해주신것 같아요.
typescript 좀더 활용해본다면 request로 들어온 값들에대한 유효성검사를 할때 (prisma가 해주고 있지만)타입가드를 활용하거나 pagination 옵션으로 공통으로 사용되는 타입을들 구조화해서 사용할 수 있을것 같아요.
또한 typescript에서 interface를 적극적으로 활용해볼수도 있을것 같습니다.
| "skipLibCheck": true, | ||
| "strictNullChecks": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "noImplicitAny": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요구사항에따른 any타입에 대한 경고를위해 해당옵션은 true로 두는게 좋을것 같아요!
| import { diskStorage } from 'multer'; | ||
|
|
||
| // 🔹 req.user를 올바르게 인식하도록 인터페이스 정의 | ||
| interface AuthRequest extends Request { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AuthRequest부분이 여러 파일에 중복되어있는것 같아요.
Auth도메인에서 타입을 export해서 사용해주시면 좋을것 같습니다.
| tags?: string[]; | ||
| } | ||
|
|
||
| export class UpdateProductDto { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모든 필드가 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; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
위함수에서 유저의 검증이필요하고, 이에대한 에러처리를 각 컨트롤러에서 해주고 계실것 같아요.
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
};
}
요구사항
기본 요구사항
공통
Github에 위클리 미션 PR을 만들어 주세요.
React 및 Express를 사용해 진행합니다.
TypeScript를 활용해 프로젝트의 필요한 곳에 타입을 명시해 주세요.
any 타입의 사용은 최소화해 주세요.
복잡한 객체 구조나 배열 구조를 가진 변수에 인터페이스 또는 타입 별칭을 사용하세요.
Union, Intersection, Generics 등 고급 타입을 적극적으로 사용해 주세요.
타입 별칭 또는 유틸리티 타입을 사용해 타입 복잡성을 줄여주세요.
타입스크립트 컴파일러가 에러 없이 정상적으로 작동해야 합니다.
백엔드
멘토에게