Files
canina/backend/src/admin/blogs.controller.ts
T
devops ddbf1ca026
Deploy Canina / deploy (push) Successful in 4m1s
E2E Playwright Tests / Run Full E2E & Security Suites (push) Failing after 7s
test: comprehensive test suites and quality gates pass across backend, storefront and admin
- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation.
- Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings.
- Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors.
- Fixed unmount lifecycle guards, promise error handling, and component edge cases.
2026-10-13 16:01:00 +00:00

183 lines
5.2 KiB
TypeScript

import {
Controller,
Get,
Post,
Put,
Patch,
Delete,
Body,
Param,
Query,
UseGuards,
Request,
} from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { BlogsService } from "./blogs.service";
import { JwtAuthGuard } from "../auth/jwt-auth.guard";
import {
ApiTags,
ApiBearerAuth,
ApiOperation,
ApiQuery,
} from "@nestjs/swagger";
import { PaginationDto } from "../common/dto/pagination.dto";
import { RolesGuard } from "../common/guards/roles.guard";
import { Roles } from "../common/decorators/roles.decorator";
@ApiTags("Admin - مدیریت مقالات (بلاگ)")
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RolesGuard)
@Roles("Admin", "SUPER_ADMIN")
@Controller("admin/blogs")
export class BlogsController {
constructor(private readonly blogsService: BlogsService) {}
@Get()
@ApiOperation({ summary: "لیست مقالات" })
@ApiQuery({ name: "page", required: false })
@ApiQuery({ name: "limit", required: false })
@ApiQuery({ name: "search", required: false })
@ApiQuery({ name: "status", required: false })
@ApiQuery({ name: "categoryId", required: false })
async getBlogs(
@Query()
query: PaginationDto & {
status?: string;
categoryId?: string;
tagId?: string;
},
) {
return this.blogsService.getBlogs(query);
}
@Get("authors")
@ApiOperation({ summary: "لیست کاربران برای انتخاب به عنوان نویسنده" })
async getAuthors() {
const data = await this.blogsService.getAuthors();
return { success: true, data };
}
@Get("categories")
@ApiOperation({ summary: "لیست دسته‌بندی‌های وبلاگ" })
async getBlogCategories() {
const data = await this.blogsService.getBlogCategories();
return { success: true, data };
}
@Post("categories")
@ApiOperation({ summary: "ایجاد دسته‌بندی جدید برای وبلاگ" })
async createBlogCategory(@Body() body: Prisma.BlogCategoryCreateInput) {
const data = await this.blogsService.createBlogCategory(body);
return { success: true, data };
}
@Put("categories/:id")
@ApiOperation({ summary: "ویرایش دسته‌بندی وبلاگ" })
async updateBlogCategory(
@Param("id") id: string,
@Body() body: Prisma.BlogCategoryUpdateInput,
) {
const data = await this.blogsService.updateBlogCategory(id, body);
return { success: true, data };
}
@Delete("categories/:id")
@ApiOperation({ summary: "حذف دسته‌بندی وبلاگ" })
async deleteBlogCategory(@Param("id") id: string) {
await this.blogsService.deleteBlogCategory(id);
return { success: true };
}
@Get("tags")
@ApiOperation({ summary: "لیست تگ‌های وبلاگ" })
async getBlogTags() {
const data = await this.blogsService.getBlogTags();
return { success: true, data };
}
@Post("tags")
@ApiOperation({ summary: "ایجاد تگ جدید برای وبلاگ" })
async createBlogTag(@Body() body: { name: string; slug?: string }) {
const data = await this.blogsService.createBlogTag(body);
return { success: true, data };
}
@Delete("tags/:id")
@ApiOperation({ summary: "حذف تگ وبلاگ" })
async deleteBlogTag(@Param("id") id: string) {
await this.blogsService.deleteBlogTag(id);
return { success: true };
}
@Get(":id")
@ApiOperation({ summary: "دریافت مشخصات یک مقاله" })
async getBlogById(@Param("id") id: string) {
const data = await this.blogsService.getBlogById(id);
return { success: true, data };
}
@Post()
@ApiOperation({ summary: "ایجاد مقاله جدید" })
async createBlog(
@Body() body: any,
@Request() req: { user: { id: string } },
) {
const data = await this.blogsService.createBlog(body, req.user.id);
return { success: true, data };
}
@Put(":id")
@ApiOperation({ summary: "ویرایش مقاله" })
async updateBlog(@Param("id") id: string, @Body() body: any) {
const data = await this.blogsService.updateBlog(id, body);
return { success: true, data };
}
@Delete(":id")
@ApiOperation({ summary: "حذف مقاله" })
async deleteBlog(@Param("id") id: string) {
await this.blogsService.deleteBlog(id);
return { success: true };
}
// Blog Comments endpoints
@Get("comments")
@ApiOperation({ summary: "لیست نظرات مقالات" })
@ApiQuery({
name: "status",
required: false,
description: "PENDING | APPROVED | REJECTED",
})
@ApiQuery({ name: "blogId", required: false })
@ApiQuery({ name: "page", required: false })
@ApiQuery({ name: "limit", required: false })
async getComments(
@Query()
query: {
page?: number;
limit?: number;
status?: string;
blogId?: string;
},
) {
return this.blogsService.getComments(query);
}
@Patch("comments/:id/status")
@ApiOperation({ summary: "تغییر وضعیت نظر (تأیید/رد)" })
async updateCommentStatus(
@Param("id") id: string,
@Body() body: { status: "APPROVED" | "REJECTED" },
) {
return this.blogsService.updateCommentStatus(id, body.status);
}
@Delete("comments/:id")
@ApiOperation({ summary: "حذف نظر" })
async deleteComment(@Param("id") id: string) {
await this.blogsService.deleteComment(id);
return { success: true };
}
}