📝 Day 83(57)일차 WE_MOTIVATION_DIARY

김민재·2021년 10월 14일
0

빡코딩 다이어리

목록 보기
80/87
post-thumbnail

- 프로젝트 진행현황

  • 백엔드 + 프론트 붙여보기
  • 붙여본 결과물을 토대로 프론트 및 벡엔드를 수정

- TODAY I LEARN ERROR 🦠

  • 키에러와 키의 값이 비어있는 경우를 다음과 같이
    조건문을 써서 에러를 발생하기 쉬운 코드를 작성하였음

- HOW TO FIX MY ERROR 💊

  • ERROR를 해결한 키에러와 키의값이 비어져있는지를 확인해주는 함수를 모듈화여 운영🔑
  • checkvalidation.js 모듈
<script>
// 키의 값이 비어져있는지를 확인하는 함수
export const checkEmptyKeyOfValue = (userInfo) => {
  const userInputData = Object.entries(userInfo);
  const userInputInfo = new Map(userInputData);
  for (let data of userInputInfo) {
    if (data[1] === '') return data[0];
  }
};
// 키가 비여져있는지를 확인하는 함수
export const checkEmptyKey = (KeyList, userInfo) => {
  const keyArr = [];
  let emptyKeyArr = [];
  const userInputData = Object.entries(userInfo);
  const userInputInfo = new Map(userInputData);
  for (let key of userInputInfo.keys()) {
    if (KeyList.includes(key)) {
      keyArr.push(key);
      const InputKeyAndListArr = keyArr.concat(KeyList);
      const emptyKey = InputKeyAndListArr.filter((e) => !keyArr.includes(e));
      emptyKeyArr = [...emptyKey];
    }
  }
  return emptyKeyArr;
};
</script>
  • signInController.js에서 에러 캐치
<script>
// 비어져있는 키의 길이가 0이 아니라면, 하나라도 비어져있다면
  if (emptyKey.length !== 0) {
    next(new AppError.keyError(`${emptyKey} 키가 비어있습니다`));
    return;
  }
  const emptyKeyOfValue = checkEmptyKeyOfValue(userInfo);
 // 비어져있는 키의 값이 존재한다면 
 if (emptyKeyOfValue) {
    next(
      new AppError.valueOfKeyError(`키의 ${emptyKeyOfValue} 값이 비어있습니다`)
    );
    return;
  }
</script>

- 모르는 점

  • 키와 키의 값을 가지고 로직을 만들기위해서 map과 sep 개념에 대해서 알아봄

- 배운점

  • new Map()를 생성하면 keys(), values(), entry 등 다양하게 키와 키의 값 쌍을 뽑아낼 수 있는 메서드들이 존재한다는 것

- 잘한 점과 개선할 점

  • 늦게라도 회고록을 끝까지 적은 점~
  • 너무 회고록을 늦게 올린점~

- 목표와 마감기한: 2021-10-14

  1. 벡엔드 프론트 합쳐서 기능구현은 마무리짓기
  2. 백엔드 리팩토링 진행하기
profile
자기 신뢰의 힘을 믿고 실천하는 개발자가 되고자합니다.

1개의 댓글

comment-user-thumbnail
2021년 10월 18일

그런 점~ 대단한 점~

답글 달기