- 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.
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Delete,
|
|
Patch,
|
|
Body,
|
|
Param,
|
|
UseGuards,
|
|
HttpStatus,
|
|
} from "@nestjs/common";
|
|
import { ApiKeysService } from "./api-keys.service";
|
|
import { CreateApiKeyDto } from "./dto/api-key.dto";
|
|
import { JwtAuthGuard } from "../auth/jwt-auth.guard";
|
|
import {
|
|
ApiTags,
|
|
ApiBearerAuth,
|
|
ApiOperation,
|
|
ApiResponse,
|
|
} from "@nestjs/swagger";
|
|
|
|
import { RolesGuard } from "../common/guards/roles.guard";
|
|
import { Roles } from "../common/decorators/roles.decorator";
|
|
|
|
@ApiTags("Admin - مدیریت کلیدهای دسترسی (API Keys)")
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
@Roles("Admin", "SUPER_ADMIN")
|
|
@Controller("admin/api-keys")
|
|
export class ApiKeysController {
|
|
constructor(private readonly apiKeysService: ApiKeysService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: "دریافت لیست کلیدهای دسترسی API" })
|
|
@ApiResponse({
|
|
status: HttpStatus.OK,
|
|
description: "لیست کلیدها با موفقیت دریافت شد",
|
|
})
|
|
async findAll() {
|
|
const keys = await this.apiKeysService.findAll();
|
|
return {
|
|
success: true,
|
|
data: keys,
|
|
};
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: "ایجاد یک API Key جدید" })
|
|
@ApiResponse({
|
|
status: HttpStatus.CREATED,
|
|
description: "کلید جدید با موفقیت ایجاد شد",
|
|
})
|
|
async create(@Body() dto: CreateApiKeyDto) {
|
|
const result = await this.apiKeysService.create(dto);
|
|
return {
|
|
success: true,
|
|
message:
|
|
"کلید دسترسی با موفقیت ایجاد شد. لطفاً آن را در جای امن ذخیره نمایید.",
|
|
data: result,
|
|
};
|
|
}
|
|
|
|
@Patch(":id/toggle")
|
|
@ApiOperation({ summary: "تغییر وضعیت فعال/غیرفعال کلید" })
|
|
async toggleStatus(@Param("id") id: string) {
|
|
const updated = await this.apiKeysService.toggleStatus(id);
|
|
return {
|
|
success: true,
|
|
message: "وضعیت کلید با موفقیت بهروزرسانی شد",
|
|
data: updated,
|
|
};
|
|
}
|
|
|
|
@Delete(":id")
|
|
@ApiOperation({ summary: "حذف کلید دسترسی" })
|
|
async delete(@Param("id") id: string) {
|
|
await this.apiKeysService.delete(id);
|
|
return {
|
|
success: true,
|
|
message: "کلید دسترسی با موفقیت حذف شد",
|
|
};
|
|
}
|
|
}
|