Feat/public api for moderation actions#407
Conversation
| } | ||
| return getReportCommentRepository(strapi).updateMany({ | ||
| where: { | ||
| id: { $in: reports.map((r) => r.id) }, |
There was a problem hiding this comment.
| 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]); |
| } | ||
| return getReportCommentRepository(strapi).updateMany({ | ||
| where: { | ||
| id: { $in: reports.map((r) => r.id) }, |
There was a problem hiding this comment.
and here it's back to previous style
| if (reports.length === 0) { | ||
| return { count: 0 }; | ||
| } | ||
| return getReportCommentRepository(strapi).updateMany({ |
There was a problem hiding this comment.
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.
| 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)); | ||
| }; |
There was a problem hiding this comment.
Return style is inconsistent. It's not a biggie, but consistency is nice.
| body: unknown | ||
| ) => { | ||
| const bodyPart = | ||
| body && typeof body === 'object' && !Array.isArray(body) | ||
| ? (body as Record<string, unknown>) | ||
| : {}; | ||
| return resolveCommentMultipleAbuseReportsValidator(enabledCollections, { | ||
| ...bodyPart, |
There was a problem hiding this comment.
| 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.
There was a problem hiding this comment.
I reckon there is a zod validator present already.
Ticket
#346
Summary
This PR adds a moderation action to the public client API
Test Plan