From cc6d8cf7530f360c66929ee4c8c9d8bbb9185233 Mon Sep 17 00:00:00 2001 From: Guillermo Gonzalez Date: Tue, 2 Apr 2024 01:22:00 +0200 Subject: [PATCH] Fix issue with new comments policy (#490) --- src/api/comment/policies/canComment.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/api/comment/policies/canComment.js b/src/api/comment/policies/canComment.js index 18be709..f4cc484 100644 --- a/src/api/comment/policies/canComment.js +++ b/src/api/comment/policies/canComment.js @@ -1,6 +1,6 @@ 'use strict'; -module.exports = async (ctx, config, { strapi }) => { +module.exports = async (ctx, config, {strapi}) => { if (!(ctx && ctx.state && ctx.state.user)) { return false; } @@ -8,11 +8,13 @@ module.exports = async (ctx, config, { strapi }) => { const startOfDay = strapi.config.functions.dateUtil.getStartDay(); const nextDay = strapi.config.functions.dateUtil.getEndDay(); const commentsCount = await strapi.query('api::comment.comment').count({ - $and: [ - {createdAt: {$lte: nextDay}}, - {createdAt: {$gte: startOfDay}} - ], - user: ctx.state.user.id + where: { + $and: [ + {createdAt: {$lte: nextDay}}, + {createdAt: {$gte: startOfDay}} + ], + user: ctx.state.user.id + } }); if (commentsCount >= strapi.config.custom.maxNumberOfCommentsPerDay) { console.log('Limit of comments by post');