강의

멘토링

커뮤니티

Inflearn Community Q&A

nan84203857's profile image
nan84203857

asked

[Renewal] Creating NodeBird SNS with React

Get only the posts you follow

안녕하세요 제로초님

Written on

·

153

0

posts/related하면 정상적으로 데이터가 api에 보여지는데요

posts/unrelated하면  

이렇게 빈 배열이 들어오더라구요..

그래서 다시 코드를 지우고 따라쳐봤는데도 그러네요 뭐가문제일까용... 

밑에 코드첨부 드립니다.

router.get('/unrelated'async (reqresnext=> {
  try {
    const followings = await User.findAll({
      attributes: ['id'],
      include: [{
        model: User,
        as: 'Followers',
        where: {id: req.user.id}
      }]
    });
    
    const where = {
      UserId: { [Op.notin]: followings.map((v=> v.id).concat(req.user.id)}
    };
    if (parseInt(req.query.lastId10)) { // 초기 로딩이 아닐 때
      where.id = { [Op.lt]: parseInt(req.query.lastId10)}
    } // 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
    const posts = await Post.findAll({
      where,
      limit: 10,
      order: [
        ['createdAt''DESC'],
        [Comment'createdAt''DESC'],
      ],
      include: [{
        model: User,
        attributes: ['id''nickname'],
      }, {
        model: Image,
      }, {
        model: Comment,
        include: [{
          model: User,
          attributes: ['id''nickname'],
        }],
      }, {
        model: User// 좋아요 누른 사람
        as: 'Likers',
        attributes: ['id'],
      }, {
        model: Post,
        as: 'Retweet',
        include: [{
          model: User,
          attributes: ['id''nickname'],
        }, {
          model: Image,
        }]
      }],
    });
    res.status(200).json(posts);
  } catch (error) {
    console.error(error);
    next(error);
  }
});

reactreduxnodejsexpressNext.js

Answer 2

0

nan84203857님의 프로필 이미지
nan84203857
Questioner

아... 대문자 소문자를 무조건 구분해야하는군요 ... 감사합니다

0

zerocho님의 프로필 이미지
zerocho
Instructor

Op.notIn 아닌가요? I 대문자

nan84203857's profile image
nan84203857

asked

Ask a question