Skip to main content

Reports & Content Moderation

The Ever Works template includes a content reporting and moderation system that enables users to flag inappropriate content and administrators to take action on reported items and comments.

Architecture

Content Types

The system supports reporting two content types:

enum ReportContentType {
ITEM = 'item',
COMMENT = 'comment',
}

ModerationService

Located at lib/services/moderation.service.ts, the service provides moderation actions:

Content Owner Resolution

async function getContentOwner(
contentType: ReportContentTypeValues,
contentId: string
): Promise<ContentOwnerResult>;
// Returns: { success: boolean, userId?: string, error?: string }

Resolves the author of reported content by looking up comments via getCommentById() or items via ItemRepository.findById().

Moderation Actions

ActionDescriptionEffect
Remove contentDelete the reported item or commentContent removed, history recorded
Warn userIncrement warning countWarning counter incremented
Suspend userTemporarily suspend accountAccount access restricted
Ban userPermanently ban accountAccount permanently restricted
Dismiss reportMark report as resolved without actionReport closed

Action Implementation

Each action creates a moderation history entry and may trigger email notifications:

// Example: Remove content
async function removeContent(
contentType: ReportContentTypeValues,
contentId: string,
reportId: string,
adminId: string
): Promise<ModerationResult>;

The service delegates to:

  • deleteComment() -- For comment removal
  • ItemRepository -- For item removal
  • createModerationHistory() -- For audit trail
  • incrementWarningCount() -- For user warnings
  • suspendUserQuery() / banUserQuery() -- For account actions
  • EmailNotificationService -- For user notification emails

Admin Hook

import { useAdminReports } from '@/hooks/use-admin-reports';

const {
reports, // Report[]
total, page, totalPages,
isLoading, isSubmitting,
resolveReport, // (id, action, reason?) => Promise<boolean>
dismissReport, // (id, reason?) => Promise<boolean>
deleteReport, // (id) => Promise<boolean>
refetch, refreshData,
} = useAdminReports({ page: 1, limit: 10 });

Moderation Workflow

  1. User reports content -- Selects a reason and submits via the report API
  2. Admin notification -- NotificationService.createItemReportedNotification() or createCommentReportedNotification() alerts admins
  3. Admin reviews -- Views report details in the admin dashboard
  4. Admin takes action -- Chooses from: remove content, warn user, suspend, ban, or dismiss
  5. History recorded -- createModerationHistory() logs the action with admin ID, timestamp, and reason
  6. User notified -- Email notification sent to the content owner about the action taken

Moderation Actions Enum

enum ModerationAction {
REMOVE_CONTENT = 'remove_content',
WARN_USER = 'warn_user',
SUSPEND_USER = 'suspend_user',
BAN_USER = 'ban_user',
DISMISS = 'dismiss',
}

API Endpoints

MethodEndpointDescription
POST/api/reportsSubmit a new report
GET/api/admin/reportsList reports (admin, paginated)
POST/api/admin/reports/:id/resolveResolve a report with action
POST/api/admin/reports/:id/dismissDismiss a report
DELETE/api/admin/reports/:idDelete a report