Moderation Service
Overview
The Moderation Service implements the complete content moderation pipeline for the platform, handling content removal, user warnings, suspensions, and bans. It integrates with the reporting system, audit trail, and email notification services to provide a comprehensive moderation workflow. Every moderation action is logged to a history table and triggers an email notification to the affected user.
Architecture
The Moderation Service operates as the central orchestrator for admin-initiated moderation actions. It coordinates between content repositories (items and comments), user profiles, moderation history logging, and email notifications. All actions require an admin user ID and a report ID for traceability.
Admin Dashboard / API Route
|
moderation.service.ts (orchestration)
|
+----------+----------+-----------+
| Comment | Item | Client |
| Queries | Repo | Profile |
+----------+----------+-----------+
| |
moderation.queries email-notification.service
|
Database (moderation_history, client_profiles, comments, items)
API Reference
Types
ModerationResult
Standard result type for all moderation operations.
interface ModerationResult {
success: boolean;
message: string;
error?: string; // Error code: 'NOT_FOUND', 'ALREADY_BANNED', 'INVALID_TYPE', etc.
}
ContentOwnerResult
Result of looking up the owner of reported content.
interface ContentOwnerResult {
success: boolean;
userId?: string;
error?: string;
}
Functions
getContentOwner(contentType: ReportContentTypeValues, contentId: string): Promise<ContentOwnerResult>
Resolves the owner (author) of reported content. For comments, it looks up the comment's userId. For items, it looks up the item's submitted_by field via the ItemRepository.
Parameters:
| Parameter | Type | Description |
|---|---|---|
contentType | ReportContentTypeValues | 'comment' or 'item' |
contentId | string | ID of the content |
Returns: ContentOwnerResult -- Contains userId on success, or error on failure.
removeContent(contentType: ReportContentTypeValues, contentId: string, reportId: string, adminId: string): Promise<ModerationResult>
Removes reported content (deletes a comment or item) and logs the moderation action. Sends an email notification to the content owner.
Parameters:
| Parameter | Type | Description |
|---|---|---|
contentType | ReportContentTypeValues | 'comment' or 'item' |
contentId | string | ID of the content to remove |
reportId | string | Associated report ID for audit trail |
adminId | string | Admin user performing the action |
Behavior by content type:
- Comment: Soft-deletes the comment via
deleteComment, logs to moderation history, sends content-removed email - Item: Deletes the item via
ItemRepository.delete(), logs with item name and slug metadata, sends email
warnUser(userId: string, reason: string, reportId: string, adminId: string): Promise<ModerationResult>
Issues a warning to a user. Increments their warning count, logs the action, and sends a warning email.
Parameters:
| Parameter | Type | Description |
|---|---|---|
userId | string | Client profile ID of the user |
reason | string | Reason for the warning |
reportId | string | Associated report ID |
adminId | string | Admin performing the action |
Guards:
- Returns error if user not found
- Returns error if user is already banned (cannot warn a banned user)
suspendUser(userId: string, reason: string, reportId: string, adminId: string): Promise<ModerationResult>
Suspends a user account. Updates the user's status to 'suspended', logs the action, and sends a suspension email.
Parameters: Same as warnUser.
Guards:
- Returns error if user not found
- Returns error if user is already suspended
- Returns error if user is already banned