카테고리 없음

14주차 (5)

jaeoun0238 2025. 1. 31. 21:23

function solution(left, right) {
    let answer = 0;

    for (let i = left; i <= right; i++) {
        let count = 0;

        // 약수의 개수 세기
        for (let j = 1; j <= Math.sqrt(i); j++) {
            if (i % j === 0) {
                count++; // j가 약수인 경우
                if (j !== i / j) {
                    count++; // 쌍의 약수 추가
                }
            }
        }

        // 약수의 개수가 짝수인지 홀수인지에 따라 더하거나 뺌
        if (count % 2 === 0) {
            answer += i; // 짝수인 경우 더함
        } else {
            answer -= i; // 홀수인 경우 뺌
        }
    }
    
    return answer;
}

카드 수정 부분이 제대로 작동하지 않는 오류가 생겼습니다.

알고 보니 순서의 문제였던 것..!

@ApiOperation({ summary: '카드 수정' })
  @Patch(':cardId')
  update(
    @Param('columnId', ParseIntPipe) columnId: number,
    @Param('cardId', ParseIntPipe) cardId: number,
    @Body() updateCardDto: UpdateCardDto,
  ): Promise<Card> {
    return this.cardService.updateCard(cardId, columnId, updateCardDto);
  }
// 카드 업데이트 메서드
  async updateCard(
    cardId: number, // 수정할 카드의 ID
    columnId: number, // 카드가 속할 열의 ID
    updateCardDto: UpdateCardDto, // 카드 업데이트에 필요한 데이터
  ): Promise<Card> {
    // 카드 정보를 업데이트 합니다.
    await this.cardRepository.update({ id: cardId, columnId }, updateCardDto);
    console.log(cardId, columnId);
    // 업데이트 후, 수정된 카드를 다시 조회하여 반환합니다.
    const card = await this.cardRepository.findOne({
      // findOne 에러만들어주기
      where: { id: cardId, columnId }, // 조건: cardId와 columnId
    });
    if (!cardId) {
      throw new BadRequestException('카드를 찾지 못했습니다');
    }
    return card;
  }
return this.cardService.updateCard(cardId, columnId, updateCardDto);
where: { id: cardId, columnId }, // 조건: cardId와 columnId

 

순서가 같아야지 제대로 where로 cardId와 columnId를 받아올 수 있었습니다..!