Skip to content

Commit e70f4c9

Browse files
committed
fix: 修复 TypeScript 编译错误
- paper-group-settings.tsx: saved 改为 saveSuccess(对应翻译键) - types/api.ts: Notebook 增加 tagSet 字段 - error-items/[id]/route.ts: 使用 ErrorItemUncheckedUpdateInput 并修正 subject 关联更新 - paper-level.test.ts: 使用 vi.hoisted 避免 mock 初始化问题
1 parent 9ee8026 commit e70f4c9

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

‎src/__tests__/unit/paper-level.test.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { describe, expect, it, vi, beforeEach } from 'vitest';
22
import { getDefaultPaperLevelGroupId, ensureDefaultPaperGroups } from '@/lib/paper-level';
3-
import { prisma } from '@/lib/prisma';
43

5-
vi.mock('@/lib/prisma', () => ({
6-
prisma: {
4+
const mocks = vi.hoisted(() => ({
5+
mockPrisma: {
76
paperGroup: {
87
findFirst: vi.fn(),
98
findMany: vi.fn(),
@@ -12,7 +11,11 @@ vi.mock('@/lib/prisma', () => ({
1211
},
1312
}));
1413

15-
const mockPrisma = vi.mocked(prisma);
14+
vi.mock('@/lib/prisma', () => ({
15+
prisma: mocks.mockPrisma,
16+
}));
17+
18+
const mockPrisma = mocks.mockPrisma;
1619

1720
describe('星级对应的默认卷别分组', () => {
1821
beforeEach(() => {

‎src/app/api/error-items/[id]/route.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export async function PUT(
103103
}
104104

105105
// 构建更新数据
106-
const updateData: Prisma.ErrorItemUpdateInput = {};
106+
const updateData: Prisma.ErrorItemUncheckedUpdateInput = {};
107107
if (figureScale !== undefined) updateData.figureScale = figureScale;
108108
if (gradeSemester !== undefined) updateData.gradeSemester = gradeSemester;
109109
if (paperLevel !== undefined) {
@@ -132,7 +132,7 @@ export async function PUT(
132132
if (!targetSubject || targetSubject.userId !== user.id) {
133133
return forbidden("Not authorized to move to this notebook");
134134
}
135-
updateData.subject = subjectId === "" ? { disconnect: true } : { connect: { id: subjectId } };
135+
updateData.subjectId = subjectId === "" ? null : subjectId;
136136
}
137137
if (mistakeStatus !== undefined || wrongAnswerText !== undefined || mistakeAnalysis !== undefined) {
138138
const nextWrongAnswerText = wrongAnswerText !== undefined ? wrongAnswerText : errorItem.wrongAnswerText;

‎src/components/settings/paper-group-settings.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function PaperGroupSettings() {
2626
try {
2727
await apiClient.post("/api/paper-groups", { name });
2828
setNewName("");
29-
toast.success(t.common?.messages?.saved || "Saved");
29+
toast.success(t.common?.messages?.saveSuccess || "Saved");
3030
refetch();
3131
} catch (error) {
3232
frontendLogger.error("[PaperGroupSettings]", "Failed to add group", { error });
@@ -44,7 +44,7 @@ export function PaperGroupSettings() {
4444
if (!name || name.trim() === oldName) return;
4545
try {
4646
await apiClient.patch(`/api/paper-groups/${id}`, { name: name.trim() });
47-
toast.success(t.common?.messages?.saved || "Saved");
47+
toast.success(t.common?.messages?.saveSuccess || "Saved");
4848
refetch();
4949
} catch (error) {
5050
frontendLogger.error("[PaperGroupSettings]", "Failed to rename group", { error });
@@ -55,7 +55,7 @@ export function PaperGroupSettings() {
5555
const handleToggleActive = async (id: string, isActive: boolean) => {
5656
try {
5757
await apiClient.patch(`/api/paper-groups/${id}`, { isActive: !isActive });
58-
toast.success(t.common?.messages?.saved || "Saved");
58+
toast.success(t.common?.messages?.saveSuccess || "Saved");
5959
refetch();
6060
} catch (error) {
6161
frontendLogger.error("[PaperGroupSettings]", "Failed to toggle group", { error });

‎src/types/api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface Notebook {
5050
name: string;
5151
stage?: string; // 学段:primary / junior_high / senior_high
5252
subjectKey?: string | null; // 学科:math / english 等
53+
tagSet?: string | null; // 标签体系:default / cn-math-taxonomy 等
5354
userId: string;
5455
createdAt: string;
5556
updatedAt: string;

0 commit comments

Comments
 (0)