Skip to content

Feat/public api for moderation actions#407

Open
mateusz-kleszcz wants to merge 3 commits into
masterfrom
feat/public-api-for-moderation-actions
Open

Feat/public api for moderation actions#407
mateusz-kleszcz wants to merge 3 commits into
masterfrom
feat/public-api-for-moderation-actions

Conversation

@mateusz-kleszcz
Copy link
Copy Markdown
Contributor

Ticket

#346

Summary

This PR adds a moderation action to the public client API

Test Plan

  • Test new endpoints, see if they replicate logic in the admin panel
  • Test the admin panel to see if it works the same as before the changes.

@mateusz-kleszcz mateusz-kleszcz self-assigned this Apr 28, 2026
@mateusz-kleszcz mateusz-kleszcz added the enhancement New feature or request label Apr 28, 2026
@CodeVoyager CodeVoyager self-requested a review May 9, 2026 12:22
}
return getReportCommentRepository(strapi).updateMany({
where: {
id: { $in: reports.map((r) => r.id) },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
id: { $in: reports.map((r) => r.id) },
id: { $in: reports.map(({ id }) => id) },

Not a big fan of one-letter names. They give nothing more then noise. I'd prefer destructing them or giving a full name. You could use something like prop('id') from lodash.

threadOf: commentId,
},
});
const relatedCommentIds = commentsInThread.map(({ id }) => id).concat([commentId]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here you did it right

}
return getReportCommentRepository(strapi).updateMany({
where: {
id: { $in: reports.map((r) => r.id) },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here it's back to previous style

if (reports.length === 0) {
return { count: 0 };
}
return getReportCommentRepository(strapi).updateMany({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this method you pass full DB query with data. Not sure why we need repository in this case. How about updateManyById with that you pass ids and the data. Lower-level stuff is abstracted away. This applies to other instances.

Comment on lines +254 to +265
const getChangeBlockedCommentSchema = (enabledCollections: string[]) =>
z.object({
relation: getRelationValidator(enabledCollections),
commentId: z.union([z.string(), z.number()]),
});

export const changeBlockedCommentValidator = (
enabledCollections: string[],
payload: object
) => {
return validate(getChangeBlockedCommentSchema(enabledCollections).safeParse(payload));
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return style is inconsistent. It's not a biggie, but consistency is nice.

Comment on lines +311 to +318
body: unknown
) => {
const bodyPart =
body && typeof body === 'object' && !Array.isArray(body)
? (body as Record<string, unknown>)
: {};
return resolveCommentMultipleAbuseReportsValidator(enabledCollections, {
...bodyPart,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
body: unknown
) => {
const bodyPart =
body && typeof body === 'object' && !Array.isArray(body)
? (body as Record<string, unknown>)
: {};
return resolveCommentMultipleAbuseReportsValidator(enabledCollections, {
...bodyPart,
bodyRaw: unknown
) => {
const body = isRecord(bodyRaw) ? bodyRaw : {};
return resolveCommentMultipleAbuseReportsValidator(enabledCollections, {
...body,

You could use a type guard here. And remove type-casting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reckon there is a zod validator present already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants