강의

멘토링

로드맵

Inflearn Community Q&A

shere17652294's profile image
shere17652294

asked

Slack Clone Coding [Backend with NestJS + TypeORM]

이런 경우에 promise allSettled를 사용해야 할지 궁금합니다.

Resolved

Written on

·

253

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을 써도 될거같긴해요.

NestJSTypeORMnodejsexpress

Answer 1

0

zerocho님의 프로필 이미지
zerocho
Instructor

네 allSettled가 성능은 더 빠르나 워낙 간단한 쿼리라서 체감은 되지 않을 겁니다.

shere17652294님의 프로필 이미지
shere17652294
Questioner

감사합니다!

shere17652294's profile image
shere17652294

asked

Ask a question