diff --git a/backend/web/server/plugins/aftral-lms/block.js b/backend/web/server/plugins/aftral-lms/block.js index ea863da04a..1ecc3fb8e8 100644 --- a/backend/web/server/plugins/aftral-lms/block.js +++ b/backend/web/server/plugins/aftral-lms/block.js @@ -310,9 +310,9 @@ const getBlockLiked = async (userId, params, data) => { const user = await User.findById(userId, {role:1}) const template = await getTemplate(data._id) if(user.role == ROLE_CONCEPTEUR) { - return template.likes.length > 0 + return template._likes.length > 0 } - return template.likes.some(like => idEqual(like, userId)) + return template._likes.some(like => idEqual(like, userId)) } const getBlockDisliked = async (userId, params, data) => { @@ -320,9 +320,9 @@ const getBlockDisliked = async (userId, params, data) => { const template = await getTemplate(data._id) console.log(template) if(user.role == ROLE_CONCEPTEUR) { - return template.dislikes.length > 0 + return template._dislikes.length > 0 } - return template.dislikes.some(dislike => idEqual(dislike, userId)) + return template._dislikes.some(dislike => idEqual(dislike, userId)) } const setBlockLiked = async ({ id, attribute, value, user }) => { @@ -331,17 +331,17 @@ const setBlockLiked = async ({ id, attribute, value, user }) => { return mongoose.models['block'].findByIdAndUpdate(template._id, { $pull: { - dislikes: user._id + _dislikes: user._id }, $addToSet: { - likes: user._id + _likes: user._id } } ) } else{ return mongoose.models['block'].findByIdAndUpdate(template._id, - {$pull: {likes: user._id}}) + {$pull: {_likes: user._id}}) } } @@ -351,25 +351,25 @@ const setBlockDisliked = async ({ id, attribute, value, user }) => { return mongoose.models['block'].findByIdAndUpdate(template._id, { $pull: { - likes: user._id + _likes: user._id }, $addToSet: { - dislikes: user._id + _dislikes: user._id } } ) } else{ return mongoose.models['block'].findByIdAndUpdate(template._id, - {$pull: {dislikes: user._id}}) + {$pull: {_dislikes: user._id}}) } } const getTemplate = async(id) => { - let [currentBlock] = await mongoose.models.block.find({_id:id},{origin:1, likes:1, dislikes:1}) + let [currentBlock] = await mongoose.models.block.find({_id:id},{origin:1, _likes:1, _dislikes:1}) let currentOrigin = currentBlock.origin while(currentOrigin) { - [currentBlock] = await mongoose.models.block.find({_id:currentOrigin},{origin:1, likes:1, dislikes:1}) + [currentBlock] = await mongoose.models.block.find({_id:currentOrigin},{origin:1, _likes:1, _dislikes:1}) currentOrigin = currentBlock.origin } return currentBlock diff --git a/backend/web/server/plugins/aftral-lms/functions.js b/backend/web/server/plugins/aftral-lms/functions.js index c20dfe8642..2f52267bec 100644 --- a/backend/web/server/plugins/aftral-lms/functions.js +++ b/backend/web/server/plugins/aftral-lms/functions.js @@ -78,11 +78,11 @@ BLOCK_MODELS.forEach(model => { declareComputedField({model, field: 'resources_count', getterFn: getResourcesCount}) declareComputedField({model, field: 'session', getterFn: getSession, requires:'parent.parent.parent.parent.parent'}) - declareVirtualField({model, field: 'likes_count', instance: 'Number', requires:'likes'}) - declareVirtualField({model, field: 'dislikes_count', instance: 'Number', requires:'dislikes'}) + declareVirtualField({model, field: 'likes_count', instance: 'Number', requires:'_likes'}) + declareVirtualField({model, field: 'dislikes_count', instance: 'Number', requires:'_dislikes'}) - declareComputedField({model, field: 'liked', getterFn: getBlockLiked, setterFn: setBlockLiked, requires:'likes,origin'}) - declareComputedField({model, field: 'disliked', getterFn: getBlockDisliked, setterFn: setBlockDisliked, requires:'dislikes,origin'}) + declareComputedField({model, field: 'liked', getterFn: getBlockLiked, setterFn: setBlockLiked, requires:'_likes,origin'}) + declareComputedField({model, field: 'disliked', getterFn: getBlockDisliked, setterFn: setBlockDisliked, requires:'_dislikes,origin'}) }) declareEnumField({model: 'homework', field: 'scale', enumValues: SCALE}) diff --git a/backend/web/server/plugins/aftral-lms/schemas/BlockSchema.js b/backend/web/server/plugins/aftral-lms/schemas/BlockSchema.js index 9da3d75d9a..64e3476b07 100644 --- a/backend/web/server/plugins/aftral-lms/schemas/BlockSchema.js +++ b/backend/web/server/plugins/aftral-lms/schemas/BlockSchema.js @@ -191,7 +191,7 @@ const BlockSchema = new Schema({ default: false, required: true, }, - likes:{ + _likes:{ type: [{ type: Schema.Types.ObjectId, ref: 'user', @@ -199,7 +199,7 @@ const BlockSchema = new Schema({ required: true, default: [] }, - dislikes:{ + _dislikes:{ type: [{ type: Schema.Types.ObjectId, ref: 'user', @@ -232,11 +232,11 @@ BlockSchema.virtual('search_text', {localField: 'tagada', foreignField: 'tagada' }) BlockSchema.virtual('likes_count', DUMMY_REF).get(function(){ - return this.likes.length || 0 + return this._likes.length || 0 }) BlockSchema.virtual('dislikes_count', DUMMY_REF).get(function(){ - return this.dislikes.length || 0 + return this._dislikes.length || 0 }) // Validate Succes achievemnt