From c7822ee14568d97df10afc2d358e740bf279f442 Mon Sep 17 00:00:00 2001 From: SeghirOumo Date: Tue, 20 Aug 2024 10:54:38 +0200 Subject: [PATCH] Aftral[#71]: hid likes from front --- backend/web/server/plugins/aftral-lms/functions.js | 4 ++-- backend/web/server/plugins/aftral-lms/post.js | 2 +- backend/web/server/plugins/aftral-lms/schemas/PostSchema.js | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/web/server/plugins/aftral-lms/functions.js b/backend/web/server/plugins/aftral-lms/functions.js index 055bd1c0af..eefb95202f 100644 --- a/backend/web/server/plugins/aftral-lms/functions.js +++ b/backend/web/server/plugins/aftral-lms/functions.js @@ -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 diff --git a/backend/web/server/plugins/aftral-lms/post.js b/backend/web/server/plugins/aftral-lms/post.js index 99025d06dd..99d08dcaae 100644 --- a/backend/web/server/plugins/aftral-lms/post.js +++ b/backend/web/server/plugins/aftral-lms/post.js @@ -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) } diff --git a/backend/web/server/plugins/aftral-lms/schemas/PostSchema.js b/backend/web/server/plugins/aftral-lms/schemas/PostSchema.js index 2f04909201..369938b350 100644 --- a/backend/web/server/plugins/aftral-lms/schemas/PostSchema.js +++ b/backend/web/server/plugins/aftral-lms/schemas/PostSchema.js @@ -31,7 +31,7 @@ const PostSchema = new Schema({ required: true, enum: Object.keys(FEED_TYPE), }, - likes: [{ + _likes: [{ type: Schema.Types.ObjectId, ref: 'user', }], @@ -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', {