feat(msg): 完整实现 msg 消息服务

包含 channels/preferences/templates/grpc/kafka/outbox/push/redis 等完整实现
This commit is contained in:
SpecialX
2026-07-10 19:09:52 +08:00
parent 21530dc7f6
commit 7b7abbb309
51 changed files with 5204 additions and 371 deletions

View File

@@ -0,0 +1,48 @@
import { Body, Controller, Get, Param, Put } from "@nestjs/common";
import { PreferencesService } from "./preferences.service.js";
import { updatePreferencesSchema } from "./preferences.dto.js";
import type { UpdatePreferencesDto } from "./preferences.dto.js";
import {
Permissions,
RequirePermission,
} from "../middleware/permission.guard.js";
/**
* PreferencesController —— 用户通知偏好 REST API。
*
* 对齐 02-architecture-design.md §4.1
* - GET /preferences/user/:userId查询偏好
* - PUT /preferences/user/:userId更新偏好
*/
@Controller("preferences")
export class PreferencesController {
constructor(private readonly service: PreferencesService) {}
@Get("user/:userId")
@RequirePermission(Permissions.MSG_NOTIFICATION_READ)
async getByUserId(
@Param("userId") userId: string,
): Promise<{ success: true; data: unknown }> {
const preferences = await this.service.getByUserId(userId);
return { success: true, data: { preferences } };
}
@Put("user/:userId")
@RequirePermission(Permissions.MSG_NOTIFICATION_MANAGE)
async update(
@Param("userId") userId: string,
@Body() body: unknown,
): Promise<{ success: true }> {
// body 来自 HTTP 请求体,类型为 unknown转 Record 以便合并 userId从 unknown 转换允许 as
const obj: Record<string, unknown> =
typeof body === "object" && body !== null
? (body as Record<string, unknown>)
: {};
const dto: UpdatePreferencesDto = updatePreferencesSchema.parse({
...obj,
userId,
});
await this.service.update(dto);
return { success: true };
}
}