Skip to content

Commit

Permalink
Merge branch 'aftral-lms-post' into aftral-lms-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
SeghirOumo committed Aug 14, 2024
2 parents 36507c1 + d97ea8c commit e978c12
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions backend/web/server/plugins/aftral-lms/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ declareComputedField({model: 'message', field: 'mine', getterFn:isMine})
// Message end

// Post start
declareVirtualField({model:'post', field: 'comments', instance: 'Array', multiple: true,
declareVirtualField({model:'post', field: 'comments', instance: 'Array',
multiple: true,
caster: {
instance: 'ObjectID',
options: {ref: 'comment'}},
Expand All @@ -127,7 +128,7 @@ declareVirtualField({model:'post', field: 'comments_count', instance: 'Number',
options: {ref: 'comment'}},
})
declareVirtualField({model:'post', field: 'likes_count', instance: 'Number', requires:'likes'})
declareComputedField({model: 'post', field: 'liked', getterFn: isLiked})
declareComputedField({model: 'post', field: 'liked', getterFn: isLiked, requires:'likes'})

// Resource start
declareVirtualField({model:'resource', field: 'likes_count', instance: 'Number', requires:'likes'})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const PostSchema = new Schema({
}, schemaOptions)

PostSchema.virtual('likes_count', DUMMY_REF).get(function(){
return this.liked.length || 0
return this.likes.length || 0
})

PostSchema.virtual('comments', {
Expand Down
8 changes: 8 additions & 0 deletions backend/web/tests/aftral-lms/db.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ describe('User', () => {
console.log(resources[0].likes[0]._id, resources)
console.log(user._id)
})
it.only('must return comments on post', async() => {
const id='66b0f1cc3356935c1fdaa148'
const user = await User.find({role: ROLE_APPRENANT})
const feed = await loadFromDb({model:'feed', id, user, fields:['posts.comments', 'posts.likes', 'posts.liked']})
const post = await loadFromDb({model:'post', id:'66bc866949ffa43e7b746755', user, fields:['comments']})
console.log(JSON.stringify(feed, null, 2))
console.log(JSON.stringify(post, null, 2))
})
})

0 comments on commit e978c12

Please sign in to comment.