[Feature] 마이리스트 상세보기

 

 async getMyListDetail(collectionId: number) {
    try {
      // 컬렉션 이름과 포스트 정보 가져오기
      const myList = await this.collectionRepository.find({
        relations: {
          collectionItems: {
            post: { images: true, restaurant: true },
          },
        },
        where: {
          id: collectionId,
          // user_id: userId,
          deletedAt: null,
          type: 'myList',
        },
        select: {
          id: true,
          name: true,
          visibility: true,
          collectionItems: {
            id: true,
            post: {
              id: true,
              content: true,
              rating: true,
              images: true,
              restaurant: {
                id: true,
                x: true,
                y: true,
                place_name: true,
              },
            },
          },
        },
      });

      return myList.map((myList) => ({
        id: myList.id,
        name: myList.name,
        visibility: myList.visibility,
        post: myList.collectionItems.map((item) => ({
          ...item.post,
          restaurant: item.post.restaurant,
          images: item.post.images,
        })),
      }));
    }

위 기능을 만들기 위해선 쿼리문이 가장 문제였다.

테이블과 테이블간의 관계가 너무 복잡했다.

잘하는 팀원의 도움을 받아서 컬렉션 아이템에 있는 post정보,

또 post안에 있는 restaurant 정보는 어떻게 가져오는지 많이 배웠다. 

 

쿼리문은 많이 익숙해졌으나, 가져오는 값이 대부분 객체 형식이다보니

map함수를 통해 값을 찾아야하는데 익숙해지기 어렵다.

 

 

 

728x90

+ Recent posts