Added ReportsModule to manage user reports. Includes service methods for creating, retrieving, and updating report statuses, as well as controller endpoints for handling these operations. Integrated with authentication, role-based access control, and database logic.
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
DefaultValuePipe,
|
|
Get,
|
|
Param,
|
|
ParseIntPipe,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
Req,
|
|
UseGuards,
|
|
} from "@nestjs/common";
|
|
import { Roles } from "../auth/decorators/roles.decorator";
|
|
import { AuthGuard } from "../auth/guards/auth.guard";
|
|
import { RolesGuard } from "../auth/guards/roles.guard";
|
|
import type { AuthenticatedRequest } from "../common/interfaces/request.interface";
|
|
import { CreateReportDto } from "./dto/create-report.dto";
|
|
import { UpdateReportStatusDto } from "./dto/update-report-status.dto";
|
|
import { ReportsService } from "./reports.service";
|
|
|
|
@Controller("reports")
|
|
export class ReportsController {
|
|
constructor(private readonly reportsService: ReportsService) {}
|
|
|
|
@Post()
|
|
@UseGuards(AuthGuard)
|
|
create(
|
|
@Req() req: AuthenticatedRequest,
|
|
@Body() createReportDto: CreateReportDto,
|
|
) {
|
|
return this.reportsService.create(req.user.sub, createReportDto);
|
|
}
|
|
|
|
@Get()
|
|
@UseGuards(AuthGuard, RolesGuard)
|
|
@Roles("admin", "moderator")
|
|
findAll(
|
|
@Query("limit", new DefaultValuePipe(10), ParseIntPipe) limit: number,
|
|
@Query("offset", new DefaultValuePipe(0), ParseIntPipe) offset: number,
|
|
) {
|
|
return this.reportsService.findAll(limit, offset);
|
|
}
|
|
|
|
@Patch(":id/status")
|
|
@UseGuards(AuthGuard, RolesGuard)
|
|
@Roles("admin", "moderator")
|
|
updateStatus(
|
|
@Param("id") id: string,
|
|
@Body() updateReportStatusDto: UpdateReportStatusDto,
|
|
) {
|
|
return this.reportsService.updateStatus(id, updateReportStatusDto.status);
|
|
}
|
|
}
|