TIL 59일차 (20240320)

박세연·2024년 3월 20일

TIL

목록 보기
49/70


오늘 한 일

  • comment module, controller, service 초안 완성
  • catalog 생성 시 board_id가 null로 되는 에러 수정
  • board_id와 sequence 묶어서 unique로 하도록 entity 수정

🥔 오늘 마주한 에러


위처럼 board_id가 자꾸 null로 되어있던 것... 이 문제는 팀원의 코드를 참고하여 고칠 수 있었다.

😂 원래 코드:

 async createCatalog(title: string, sequence: number, boardId: number) {
    await this.catalogRepository.save({
      title,
      sequence,
      boardId,
    });
    return { message: `${boardId}의 ${title} catalog가 생성되었습니다.` };
  }

😂 수정한 코드:

async createCatalog(title: string, sequence: number, boardId: number) {
    const board = await this.boardRepository.findOneBy({ boardId });

    await this.catalogRepository.save({
      board,
      title,
      sequence,
    });
    console.log(boardId, sequence);
    return { message: `${boardId}의 ${title} catalog가 생성되었습니다.` };
  }

entity에 board:Board;라고 작성했는데 자꾸 typeof board를 쳐봐도 undefined가 나왔었는데 그냥 board 자체를 갖다 붙였어야했구나 깨달았다...

🥔 추가 공부?한 메서드

  • slice와 splice의 차이
    • slice는 삭제만, splice는 삭제와 동시에 교체도 같이 해주는 메서드... 알아도 자꾸 까먹는다.
profile
배워나가는 중

0개의 댓글