feat(api-keys): add api keys management and authentication for n8n workflows
This commit is contained in:
1 parent
ba9472c938
commit
1fff11ee4f
24 files changed
+158204
-5768
No files matched your search
@@ -0,0 +1,67 @@
|
||||
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';
|
||||
|
||||
@ApiTags('Admin - مدیریت کلیدهای دسترسی (API Keys)')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@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: 'کلید دسترسی با موفقیت حذف شد',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user