Skip to content

Commit

Permalink
Aftral[premieroctet#71]: hid likes from front
Browse files Browse the repository at this point in the history
  • Loading branch information
SeghirOumo committed Aug 20, 2024
1 parent 4a2b1ee commit c7822ee
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions backend/web/server/plugins/aftral-lms/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ declareVirtualField({model:'post', field: 'comments_count', instance: 'Number',
instance: 'ObjectID',
options: {ref: 'block'}},
})
declareVirtualField({model:'post', field: 'likes_count', instance: 'Number', requires:'likes'})
declareComputedField({model: 'post', field: 'liked', getterFn: isLiked, requires:'likes'})
declareVirtualField({model:'post', field: 'likes_count', instance: 'Number', requires:'_likes'})
declareComputedField({model: 'post', field: 'liked', getterFn: isLiked, requires:'_likes'})

const preCreate = async ({model, params, user}) => {
params.creator=params.creator || user._id
Expand Down
2 changes: 1 addition & 1 deletion backend/web/server/plugins/aftral-lms/post.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const isLiked = async(userId, params, data) => {
const likes = data.likes.map(l=> l._id)
const likes = data._likes.map(l=> l._id)
return likes.includes(userId)
}

Expand Down
4 changes: 2 additions & 2 deletions backend/web/server/plugins/aftral-lms/schemas/PostSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const PostSchema = new Schema({
required: true,
enum: Object.keys(FEED_TYPE),
},
likes: [{
_likes: [{
type: Schema.Types.ObjectId,
ref: 'user',
}],
Expand All @@ -43,7 +43,7 @@ const PostSchema = new Schema({
}, schemaOptions)

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

PostSchema.virtual('comments', {
Expand Down

0 comments on commit c7822ee

Please sign in to comment.