first commit
This commit is contained in:
17
src/modules/reports/dto/create-report.dto.ts
Normal file
17
src/modules/reports/dto/create-report.dto.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { IsEnum, IsOptional, IsString, IsUUID } from 'class-validator';
|
||||
|
||||
export class CreateReportDto {
|
||||
@ApiProperty()
|
||||
@IsUUID()
|
||||
entityId: string;
|
||||
|
||||
@ApiProperty({ enum: ['profile', 'message'] })
|
||||
@IsEnum(['profile', 'message'])
|
||||
entityType: 'profile' | 'message';
|
||||
|
||||
@ApiPropertyOptional()
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
description?: string;
|
||||
}
|
||||
33
src/modules/reports/reports.controller.ts
Normal file
33
src/modules/reports/reports.controller.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
||||
import { Roles } from '../../common/decorators/roles.decorator';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import { RolesGuard } from '../../common/guards/roles.guard';
|
||||
import { CreateReportDto } from './dto/create-report.dto';
|
||||
import { ReportsService } from './reports.service';
|
||||
|
||||
@ApiTags('reports')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('reports')
|
||||
export class ReportsController {
|
||||
constructor(private readonly reportsService: ReportsService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Submit a report' })
|
||||
create(
|
||||
@CurrentUser('id') userId: string,
|
||||
@Body() dto: CreateReportDto,
|
||||
) {
|
||||
return this.reportsService.create(userId, dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@Roles('admin', 'moderator')
|
||||
@UseGuards(RolesGuard)
|
||||
@ApiOperation({ summary: 'Get all reports (admin/moderator)' })
|
||||
getAll() {
|
||||
return this.reportsService.getAll();
|
||||
}
|
||||
}
|
||||
9
src/modules/reports/reports.module.ts
Normal file
9
src/modules/reports/reports.module.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ReportsController } from './reports.controller';
|
||||
import { ReportsService } from './reports.service';
|
||||
|
||||
@Module({
|
||||
controllers: [ReportsController],
|
||||
providers: [ReportsService],
|
||||
})
|
||||
export class ReportsModule {}
|
||||
34
src/modules/reports/reports.service.ts
Normal file
34
src/modules/reports/reports.service.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DrizzleService } from '../../database/drizzle.service';
|
||||
import { report } from '../../database/schema';
|
||||
import { CreateReportDto } from './dto/create-report.dto';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
@Injectable()
|
||||
export class ReportsService {
|
||||
constructor(private readonly drizzleService: DrizzleService) {}
|
||||
|
||||
async create(userId: string, dto: CreateReportDto) {
|
||||
const [newReport] = await this.drizzleService.db
|
||||
.insert(report)
|
||||
.values({
|
||||
sourceUser: userId,
|
||||
entityId: dto.entityId,
|
||||
entityType: dto.entityType,
|
||||
description: dto.description || null,
|
||||
} as any)
|
||||
.returning();
|
||||
return newReport;
|
||||
}
|
||||
|
||||
async getAll() {
|
||||
return this.drizzleService.db.select().from(report).orderBy(report.id);
|
||||
}
|
||||
|
||||
async getByUser(userId: string) {
|
||||
return this.drizzleService.db
|
||||
.select()
|
||||
.from(report)
|
||||
.where(eq(report.sourceUser, userId));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user