Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/moderation/dto/analyze-content.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IsEnum, IsString, IsNotEmpty, MaxLength } from 'class-validator';
import { ContentType } from '../enums/moderation.enums';

export class AnalyzeContentDto {
@IsEnum(ContentType)
contentType: ContentType;

@IsString()
@IsNotEmpty()
@MaxLength(10000)
content: string;
}
24 changes: 24 additions & 0 deletions src/moderation/dto/flag-content.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { IsEnum, IsUUID, IsString, IsOptional, MaxLength } from 'class-validator';
import { ContentType, ViolationCategory } from '../enums/moderation.enums';

export class FlagContentDto {
@IsEnum(ContentType)
contentType: ContentType;

@IsUUID()
contentId: string;

@IsOptional()
@IsString()
@MaxLength(2000)
contentSnapshot?: string;

@IsOptional()
@IsEnum(ViolationCategory)
category?: ViolationCategory;

@IsOptional()
@IsString()
@MaxLength(500)
flagReason?: string;
}
38 changes: 38 additions & 0 deletions src/moderation/dto/moderation-filter.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { IsEnum, IsOptional, IsInt, Min, Max, IsDateString } from 'class-validator';
import { Type } from 'class-transformer';
import { ModerationStatus, ContentType, Severity } from '../enums/moderation.enums';

export class ModerationFilterDto {
@IsOptional()
@IsEnum(ModerationStatus)
status?: ModerationStatus;

@IsOptional()
@IsEnum(ContentType)
contentType?: ContentType;

@IsOptional()
@IsEnum(Severity)
severity?: Severity;

@IsOptional()
@IsDateString()
from?: string;

@IsOptional()
@IsDateString()
to?: string;

@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
@Max(100)
limit?: number = 20;

@IsOptional()
@Type(() => Number)
@IsInt()
@Min(0)
offset?: number = 0;
}
12 changes: 12 additions & 0 deletions src/moderation/dto/resolve-appeal.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IsIn, IsString, IsOptional, MaxLength } from 'class-validator';
import { AppealStatus } from '../enums/moderation.enums';

export class ResolveAppealDto {
@IsIn([AppealStatus.ACCEPTED, AppealStatus.REJECTED])
decision: AppealStatus.ACCEPTED | AppealStatus.REJECTED;

@IsOptional()
@IsString()
@MaxLength(1000)
notes?: string;
}
15 changes: 15 additions & 0 deletions src/moderation/dto/review-flag.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { IsEnum, IsUUID, IsString, IsOptional, MaxLength } from 'class-validator';
import { ModerationStatus } from '../enums/moderation.enums';

export class ReviewFlagDto {
@IsUUID()
flagId: string;

@IsEnum(ModerationStatus)
status: ModerationStatus;

@IsOptional()
@IsString()
@MaxLength(1000)
reviewNotes?: string;
}
11 changes: 11 additions & 0 deletions src/moderation/dto/submit-appeal.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IsUUID, IsString, MinLength, MaxLength } from 'class-validator';

export class SubmitAppealDto {
@IsUUID()
flagId: string;

@IsString()
@MinLength(20)
@MaxLength(2000)
reason: string;
}
52 changes: 52 additions & 0 deletions src/moderation/entities/moderation-action.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
Index,
} from 'typeorm';
import { ActionType, Severity } from '../enums/moderation.enums';

@Entity('moderation_actions')
@Index(['userId'])
@Index(['flagId'])
export class ModerationAction {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ type: 'uuid' })
flagId: string;

@Column({ type: 'uuid' })
userId: string;

@Column({ type: 'enum', enum: ActionType })
actionType: ActionType;

@Column({ type: 'enum', enum: Severity })
severity: Severity;

@Column({ type: 'text', nullable: true })
reason: string;

@Column({ type: 'uuid', nullable: true })
issuedById: string;

@Column({ type: 'boolean', default: false })
isAutomatic: boolean;

@Column({ type: 'boolean', default: false })
reverted: boolean;

@Column({ type: 'uuid', nullable: true })
revertedById: string;

@Column({ type: 'timestamp', nullable: true })
revertedAt: Date;

@Column({ type: 'timestamp', nullable: true })
expiresAt: Date;

@CreateDateColumn()
createdAt: Date;
}
48 changes: 48 additions & 0 deletions src/moderation/entities/moderation-appeal.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
Index,
} from 'typeorm';
import { AppealStatus } from '../enums/moderation.enums';

@Entity('moderation_appeals')
@Index(['flagId'])
@Index(['userId'])
@Index(['status'])
export class ModerationAppeal {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ type: 'uuid' })
flagId: string;

@Column({ type: 'uuid' })
userId: string;

@Column({ type: 'text' })
reason: string;

@Column({ type: 'enum', enum: AppealStatus, default: AppealStatus.PENDING })
status: AppealStatus;

@Column({ type: 'uuid', nullable: true })
reviewerId: string;

@Column({ type: 'text', nullable: true })
reviewerDecision: string;

@Column({ type: 'text', nullable: true })
reviewerNotes: string;

@Column({ type: 'timestamp', nullable: true })
resolvedAt: Date;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;
}
38 changes: 38 additions & 0 deletions src/moderation/entities/moderation-audit.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
Index,
} from 'typeorm';
import { AuditAction } from '../enums/moderation.enums';

@Entity('moderation_audit_logs')
@Index(['flagId'])
@Index(['userId'])
@Index(['actorId'])
export class ModerationAudit {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ type: 'uuid', nullable: true })
flagId: string;

@Column({ type: 'uuid', nullable: true })
userId: string;

@Column({ type: 'uuid', nullable: true })
actorId: string;

@Column({ type: 'enum', enum: AuditAction })
action: AuditAction;

@Column({ type: 'jsonb', nullable: true })
metadata: Record<string, unknown>;

@Column({ type: 'text', nullable: true })
notes: string;

@CreateDateColumn()
createdAt: Date;
}
79 changes: 79 additions & 0 deletions src/moderation/entities/moderation-flag.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
Index,
} from 'typeorm';
import {
ContentType,
ModerationStatus,
ViolationCategory,
Severity,
} from '../enums/moderation.enums';

@Entity('moderation_flags')
@Index(['contentType', 'contentId'])
@Index(['status'])
@Index(['userId'])
export class ModerationFlag {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ type: 'uuid' })
userId: string;

@Column({ type: 'enum', enum: ContentType })
contentType: ContentType;

@Column({ type: 'uuid' })
contentId: string;

@Column({ type: 'text', nullable: true })
contentSnapshot: string;

@Column({
type: 'enum',
enum: ModerationStatus,
default: ModerationStatus.PENDING,
})
status: ModerationStatus;

@Column({
type: 'enum',
enum: ViolationCategory,
default: ViolationCategory.NONE,
})
category: ViolationCategory;

@Column({ type: 'enum', enum: Severity, default: Severity.LOW })
severity: Severity;

@Column({ type: 'float', default: 0 })
toxicityScore: number;

@Column({ type: 'jsonb', nullable: true })
mlClassification: Record<string, unknown>;

@Column({ type: 'text', nullable: true })
flagReason: string;

@Column({ type: 'uuid', nullable: true })
reviewerId: string;

@Column({ type: 'text', nullable: true })
reviewNotes: string;

@Column({ type: 'timestamp', nullable: true })
reviewedAt: Date;

@Column({ type: 'boolean', default: false })
isAutoModerated: boolean;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;
}
39 changes: 39 additions & 0 deletions src/moderation/entities/moderation-queue-item.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
Index,
} from 'typeorm';
import { QueuePriority } from '../enums/moderation.enums';

@Entity('moderation_queue')
@Index(['priority', 'createdAt'])
@Index(['flagId'])
@Index(['assignedTo'])
export class ModerationQueueItem {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ type: 'uuid' })
flagId: string;

@Column({ type: 'int', default: QueuePriority.NORMAL })
priority: number;

@Column({ type: 'uuid', nullable: true })
assignedTo: string;

@Column({ type: 'boolean', default: false })
isProcessed: boolean;

@Column({ type: 'timestamp', nullable: true })
processedAt: Date;

@CreateDateColumn()
createdAt: Date;

@UpdateDateColumn()
updatedAt: Date;
}
Loading