api-server/src/modules/notifications/admin-notifications.controller.ts
WangDL 8e5d722a1e
All checks were successful
Deploy API Server / build-and-deploy (push) Successful in 44s
feat: M3-04/05/06 — Workspace Experience, Notification, Cache Module
M3-04: RecentItem/Favorite/SearchHistory models, Tag CRUD, global search, workspace dashboard
M3-05: NotificationPreference/PushToken/Template models, preferences, push tokens, admin templates
M3-06: CacheService with wrap() penetration protection, key naming conventions, admin cache management
E2E: 27 new tests for M3-04/05/06 (35/36 passing overall)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-24 16:01:34 +08:00

53 lines
1.8 KiB
TypeScript

import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation, ApiBody, ApiQuery } from '@nestjs/swagger';
import { NotificationsService } from './notifications.service';
@ApiTags('admin-notifications')
@ApiBearerAuth()
@Controller('admin-api/notifications')
export class AdminNotificationsController {
constructor(private readonly service: NotificationsService) {}
// ═══ Templates ═══
@Get('templates')
@ApiOperation({ summary: '通知模板列表' })
async getTemplates() {
return this.service.getTemplates();
}
@Post('templates')
@ApiOperation({ summary: '创建通知模板' })
@ApiBody({ schema: { type: 'object', required: ['name', 'type', 'title', 'content'], properties: {
name: { type: 'string' },
type: { type: 'string' },
title: { type: 'string' },
content: { type: 'string' },
channel: { type: 'string', enum: ['in_app', 'push', 'email'] },
} } })
async createTemplate(@Body() dto: { name: string; type: string; title: string; content: string; channel?: string }) {
return this.service.createTemplate(dto);
}
@Patch('templates/:id')
@ApiOperation({ summary: '更新通知模板' })
async updateTemplate(@Param('id') id: string, @Body() dto: Record<string, any>) {
return this.service.updateTemplate(id, dto);
}
@Delete('templates/:id')
@ApiOperation({ summary: '删除通知模板' })
async deleteTemplate(@Param('id') id: string) {
return this.service.deleteTemplate(id);
}
// ═══ Send Log ═══
@Get('send-log')
@ApiOperation({ summary: '通知发送日志' })
@ApiQuery({ name: 'limit', required: false })
async getSendLog(@Query('limit') limit?: string) {
return this.service.getSendLogs(Number(limit) || 100);
}
}