-
카테고리
-
세부 분야
백엔드
-
해결 여부
해결됨
이런 경우에 promise allSettled를 사용해야 할지 궁금합니다.
22.06.22 13:37 작성 조회수 181
0
nest 강좌와 관련된 부분은 아니지만 조현영님께서 await을 연달아 사용하지 말라고 언급하신것이 생각나서 질문드립니다.
아래 함수는 사용자가 회원가입을 했을 때 입력했던 실명과 전화번호를 매치 시켜 email을 찾아내는 코드입니다.
async findEmail(findEmailDto: FindEmailDto): Promise<string> {
const { realName, phoneNumber } = findEmailDto;
const foundWithRealName = await this.authRepositry.isExistUserWithRealName(
realName,
);
const foundWithPhoneNumber =
await this.authRepositry.isExistUserWithPhoneNumber(phoneNumber);
if (!foundWithRealName || !foundWithPhoneNumber) {
throw new UnauthorizedException("올바르지 않은 정보입니다.");
}
if (!(foundWithRealName.id === foundWithPhoneNumber.id)) {
throw new UnauthorizedException("올바르지 않은 정보입니다.");
}
return foundWithRealName.email;
}
실명과 전화번호로 유저 엔티티를 찾아내고 각 정보가 존재하는지 그리고 각 정보가 한 유저의 아이디에서 나온 것인지 확인 한뒤 email을 리턴해줍니다. await이 두번 사용되긴 하였는데 이런 경우에도 await을 연달아 사용하지 않고 promise allSettled로 묶어야 하는지 궁금합니다. 제 생각에는 코드가 하는 작업이 별로 없어서 await을 써도 될거같긴해요.
답변을 작성해보세요.
답변 1