# 원티드 프리온보딩 백엔드 인턴십 7th : 231030 TIL

- Author: @laetipark
- Published: 2023-11-04
- Updated: 2023-12-31
- Source: http://blex.me/@laetipark/%EC%9B%90%ED%8B%B0%EB%93%9C-%ED%94%84%EB%A6%AC%EC%98%A8%EB%B3%B4%EB%94%A9-%EB%B0%B1%EC%97%94%EB%93%9C-%EC%9D%B8%ED%84%B4%EC%8B%AD-7th-231030-til
- Tags: 백엔드, til, nodejs, nestjs, 원티드, github, 프리온보딩, bcrypt

---

### 1️⃣ 할당된 업무에 대한 진행상황.
`Done` : 사용자 회원가입 API 코드 작성 완료  
`In Progress` : 사용자 회원가입 API 코드 수정 및 프로젝트 마무리
- 남아있는 `repository` 폴더 삭제
- 사용자 회원가입 및 로그인 관련 기능 `auth` 모듈로 통일
- `auth` 모듈 `feature` 폴더로 이동
- `getStatisticsByHour` 메서드에 `hour` 변수 코드 수정
	```typescript
	const [hour, _] = time.split(':'); // 변경 전
	const hour = time.split(':')[0]; // 변경 후
	```

### 2️⃣ 진행한 작업에 대한 리뷰 및 커밋한 내용 리뷰
- PR을 통해 사용자 회원가입 API 코드를 개선하면서, 코드의 직관성을 향상시키는데 주력했었고, 코드를 수정하면서 좀 더 직관적인 코드 작성에 대해 생각해볼 수 있는 시간이었습니다. 🤔
	```typescript
	// 변경 전
	@Post('/signup')
	async signUpUser(@Body() createUserDto: CreateUserDto) {
		const { username, email, password } = createUserDto;
		const passwordValid =
			await this.userService.checkPasswordValidate(password);
		if (!passwordValid) {
			throw new BadRequestException(`적절하지 않은 패스워드 입니다.`);
		}

		await this.authService.createAuthCode(email);
		await this.userService.createUser(createUserDto);
	...
	}
	```
	```
	// 변경 후, error throw는 service 내부에 진행하였다.
	@Post('/signup')
	async signUpUser(@Body() createUserDto: CreateUserDto) {
		await this.userService.checkUserExists(createUserDto.username);
		await this.userService.checkPasswordValidate(
			createUserDto.password,
			createUserDto.confirmPassword,
		);
		// 인증 코드와 사용자 생성 진행
		const authCode = await this.userService.createUser(createUserDto);
	...
	}
	```

- 테스트 해보니 연속되는 특수문자 사용을 정규식에 포함하지 못해서 추가했습니다. 😅
  ```typescript
	// 변경 전
	/(\w)\1\1/.test(password)	
	```
	```typescript
	// 변경 후
	// 3회 이상 연속되는 문자 또는 특수문자 사용을 확인할 수 있다.
	/([!@#$%^&*()+\-=\[\]{}|;:'",.<>/?\w])\1\1/.test(password)
	```

### 3️⃣ Today I Learned
- **bcrypt 모듈**에서 `bcrypt.hash()` 함수로 생성된 `hash`는 생성할 때마다 매번 다른 값이 생성되는데, 서로 다른 값이여도 동일한 평문 값을 찾아줄 수 있는 것을 보고 이에 대해서도 공부해보고 싶었습니다.
- [NestJS/Typescript : Bcrypt 모듈을 통한 비밀번호 암호화, laetipark, blex.me](https://blex.me/@laetipark/nestjstypescript-bcrypt-%EB%AA%A8%EB%93%88%EC%9D%84-%ED%86%B5%ED%95%9C-%EB%B9%84%EB%B0%80%EB%B2%88%ED%98%B8-%EC%95%94%ED%98%B8%ED%99%94)

### 📁 수행 기업 과제 Repository
- [[ FeedMoa ] 소셜 미디어 통합 Feed 서비스 RESTful API 서버, laetipark, github](https://github.com/laetipark/feed-moa)
