Skip to content

Commit

Permalink
Aftral[premieroctet#51]: added comment user data on preprocess get fo…
Browse files Browse the repository at this point in the history
…r feed
  • Loading branch information
SeghirOumo committed Aug 19, 2024
1 parent 045bbbf commit 4a2b1ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
57 changes: 38 additions & 19 deletions backend/web/server/plugins/aftral-lms/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,28 +247,47 @@ const getContacts = user => {
.then(res => res.filter(u => !idEqual(u._id, user._id)))
}

const getFeed = async id => {
const getFeed = async (id) => {
let type, name
if (id==GENERAL_FEED_ID) {
type=FEED_TYPE_GENERAL
name= 'Forum Aftral LMS'

if (id === GENERAL_FEED_ID) {
type = FEED_TYPE_GENERAL
name = 'Forum Aftral LMS'
} else {
const model = await getModel(id, ['session', 'group'])
type = model === 'session' ? FEED_TYPE_SESSION : FEED_TYPE_GROUP
const feed = await mongoose.connection.models[model].findById(id)
name = feed.name
}
else {
const model=await getModel(id, ['session', 'group'])
type=model=='session' ? FEED_TYPE_SESSION : FEED_TYPE_GROUP
const feed=await mongoose.connection.models[model].findById(id)
name=feed.name

let posts = await Post.find({ _feed: id })
.populate('author')
.populate('comments')
.populate('comments_count')

posts = await Promise.all(posts.map(async (post) => {
const comments = await Promise.all(post.comments.map(async (comment) => {
const user = await User.findById(comment.user)
return {
...comment.toObject(),
user,
}
}))

return {
...post.toObject(),
comments,
}
}))

return {
_id: id,
type,
name,
posts,
}
return Post.find({_feed: id}).populate('author').populate('comments').populate('comments_count')
.then(posts => {
return ({
_id: id,
type,
name,
posts
})
})
}
};


const getFeeds = async (user, id) => {
let ids=[]
Expand Down
4 changes: 2 additions & 2 deletions backend/web/tests/aftral-lms/post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Post', () => {
})
it('must return comments on post', async() => {
user = await User.findOne({role:ROLE_APPRENANT})
const posts = await loadFromDb({model:'post', user, fields:['comments', 'likes', 'liked','_feed']})
console.log(posts)
const [feed] = await loadFromDb({model:'feed', id: '66b0f1cc3356935c1fdaa148', user, fields:['posts']})
console.log(feed.posts[0].comments)
})
})

0 comments on commit 4a2b1ee

Please sign in to comment.