개발일지

개발일지 72일차

index.ys 2023. 6. 16. 19:14

내가 작성한 푸박스 모두 조회 추가

controller

   getMyPoo = async (req, res, next) => {
        const { userId } = res.locals.user
        const getMyPooData = await this.mypagesService.getMyPoo(userId, next)
        return res.status(201).json({ getMyPooData })
    };

service

- 전달받은 userId를 repository로 전달

 getMyPoo = async (userId) => {
        try {
            const getMyPoo = await this.mypageRepository.getMyPoo(userId)
            if (!userId) {
                throw new Error("403/마이페이지 권한이 없습니다.")
            }
            if (getMyPoo.length === 0) {
                throw new Error("400/작성한 푸박스가 없습니다.")
            }
            return getMyPoo
        } catch (error) {
            error.failedApi = "에러처리";
            throw error
        }
    };

repository

- userId에 해당하는 북마크 글들을 전체조회함

   getMyPoo = async (userId) => {
        const getMyPooData = await this.Poos.findAll({
            where: { UserId: userId }

        })
        return getMyPooData
    };

북마크 여부 추가

- 모델 파일에 북마크 여부를 추가하여 사용자가 북마크한 게시글인지 아닌지 기억하도록 함

 isBookmarked: {
        allowNull: false,
        type: Sequelize.BOOLEAN,
        defaultValue: true,
      },