- 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.
75 lines
2.3 KiB
TypeScript
75 lines
2.3 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
} from "@nestjs/common";
|
|
import { Prisma } from "@prisma/client";
|
|
import { CategoriesService } from "./categories.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/categories")
|
|
export class CategoriesController {
|
|
constructor(private readonly categoriesService: CategoriesService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: "لیست دستهبندیها (با صفحهبندی)" })
|
|
@ApiQuery({ name: "page", required: false, description: "شماره صفحه" })
|
|
@ApiQuery({ name: "limit", required: false, description: "تعداد آیتمها" })
|
|
@ApiQuery({ name: "search", required: false, description: "جستجو در نام" })
|
|
async getCategories(@Query() query: PaginationDto) {
|
|
return this.categoriesService.getCategories(query);
|
|
}
|
|
|
|
@Get("all")
|
|
@ApiOperation({ summary: "لیست تمام دستهبندیها (بدون صفحهبندی)" })
|
|
async getAllCategoriesRaw() {
|
|
const data = await this.categoriesService.getAllCategoriesRaw();
|
|
return { success: true, data };
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: "ایجاد دستهبندی جدید" })
|
|
async createCategory(@Body() body: Prisma.CategoryCreateInput) {
|
|
const data = await this.categoriesService.createCategory(body);
|
|
return { success: true, data };
|
|
}
|
|
|
|
@Put(":id")
|
|
@ApiOperation({ summary: "ویرایش دستهبندی" })
|
|
async updateCategory(
|
|
@Param("id") id: string,
|
|
@Body() body: Prisma.CategoryUpdateInput,
|
|
) {
|
|
const data = await this.categoriesService.updateCategory(id, body);
|
|
return { success: true, data };
|
|
}
|
|
|
|
@Delete(":id")
|
|
@ApiOperation({ summary: "حذف دستهبندی" })
|
|
async deleteCategory(@Param("id") id: string) {
|
|
await this.categoriesService.deleteCategory(id);
|
|
return { success: true };
|
|
}
|
|
}
|