feat(teacher-bff): 添加视口聚合端点 + 修复身份头读取

- 新增 GET /teacher/viewports 聚合 IAM 视口配置
- 修复 controller 从 x-user-id header 读取身份(替代 AuthenticatedRequest)
- 添加 zod + @types/express 依赖
This commit is contained in:
SpecialX
2026-07-09 00:49:24 +08:00
parent a2f0ca26ae
commit b2c2f6e567
4 changed files with 67 additions and 20 deletions

View File

@@ -1,22 +1,52 @@
import { Injectable } from '@nestjs/common';
import { env } from '../config/env.js';
import { Injectable } from "@nestjs/common";
import { env } from "../config/env.js";
export interface ViewportItem {
key: string;
label: string;
route: string;
icon: string | null;
sortOrder: string;
requiredPermission: string | null;
}
@Injectable()
export class TeacherService {
// 聚合 IAM + classes 服务的数据
async getDashboard(userId: string): Promise<unknown> {
async getDashboard(userId: string): Promise<{
user: unknown;
classes: unknown;
}> {
const [iamRes, classesRes] = await Promise.allSettled([
fetch(`${env.IamServiceUrl}/iam/me`, {
headers: { 'x-user-id': userId },
headers: { "x-user-id": userId },
}),
fetch(`${env.ClassesServiceUrl}/classes`, {
headers: { 'x-user-id': userId },
headers: { "x-user-id": userId },
}),
]);
return {
user: iamRes.status === 'fulfilled' ? await iamRes.value.json() : null,
classes: classesRes.status === 'fulfilled' ? await classesRes.value.json() : null,
user: iamRes.status === "fulfilled" ? await iamRes.value.json() : null,
classes:
classesRes.status === "fulfilled"
? await classesRes.value.json()
: null,
};
}
// 聚合 IAM 视口配置L1 导航)
async getViewports(userId: string): Promise<ViewportItem[]> {
const res = await fetch(`${env.IamServiceUrl}/iam/viewports`, {
headers: { "x-user-id": userId },
});
if (!res.ok) {
return [];
}
const json = (await res.json()) as {
success: boolean;
data?: ViewportItem[];
};
return json.data ?? [];
}
}