chore(release): 1.3.3 发布并退役旧联动

This commit is contained in:
LoveChengke committed 2026-10-17 03:06:46 +08:00
1 parent b7cdc7c9ea
commit c0ebf88138
184 files changed
+5450 -11705

No files matched your search

@@ -2,12 +2,7 @@ import { Router } from 'express';
import { sendCreated, sendOk } from '../../lib/http.js';
import { idParamSchema } from '../../lib/schemas.js';
import { authenticate, getAuthUser, requirePermission } from '../../middleware/auth.js';
import {
validate,
validatedBody,
validatedParams,
validatedQuery,
} from '../../middleware/validate.js';
import { validate, validatedBody, validatedParams, validatedQuery } from '../../middleware/validate.js';
import { defineModule } from '../module.types.js';
import {
addStudentSchema,
@@ -19,14 +14,12 @@ import {
promoteClassesSchema,
updateClassAccountSchema,
updateClassSchema,
updateNotificationChannelSchema,
updateStudentGradeQuerySchema,
type AddStudentInput,
type AssignSubjectTeachersInput,
type CreateClassInput,
type UpdateClassAccountInput,
type UpdateClassInput,
type UpdateNotificationChannelInput,
type UpdateStudentGradeQueryInput,
} from './classes.schemas.js';
import * as classService from './classes.service.js';
@@ -73,10 +66,15 @@ router.get('/:id', validate({ params: idParamSchema }), async (req, res) => {
});
/** POST /api/classes - 创建班级(称呼由入学年份 + 班号生成,如「2026级1班」) */
router.post('/', requirePermission('class:manage'), validate({ body: createClassSchema }), async (req, res) => {
const user = getAuthUser(req);
sendCreated(res, await classService.createClass(user, req.body as CreateClassInput), '班级创建成功');
});
router.post(
'/',
requirePermission('class:manage'),
validate({ body: createClassSchema }),
async (req, res) => {
const user = getAuthUser(req);
sendCreated(res, await classService.createClass(user, req.body as CreateClassInput), '班级创建成功');
},
);
/** PATCH /api/classes/:id - 编辑班级(年级 / 届别 / 教学周数),仅管理员 */
router.patch(
@@ -160,55 +158,9 @@ router.put(
},
);
/**
* GET /api/classes/:id/classisland-status - 本班 ClassHelper 班级端 / ClassIsland 联动状态
*
* 教室机器(ClassHelper 班级端)也能读:客户端「设置 → ClassIsland 联动」据此显示状态。
*/
router.get('/:id/classisland-status', validate({ params: idParamSchema }), async (req, res) => {
const user = getAuthUser(req);
const { id } = validatedParams<{ id: string }>(req);
sendOk(res, await classService.getClassIslandStatus(user, id), '获取联动状态成功');
});
/**
* GET /api/classes/:id/notification-channel - 读取"通知显示到哪个端"
*
* 教室的 ClassHelper 班级端登录后会拉这个值,据此决定自己是弹窗/上岛还是静默;
* 教师/管理员也能读(Web 端展示用)。
*/
router.get('/:id/notification-channel', validate({ params: idParamSchema }), async (req, res) => {
const user = getAuthUser(req);
const { id } = validatedParams<{ id: string }>(req);
sendOk(res, await classService.getNotificationChannel(user, id), '获取通知显示位置成功');
});
/**
* PATCH /api/classes/:id/notification-channel - 设置"通知显示到哪个端"
*
* **由教室的 ClassHelper 班级端自己选**,教师/管理员也可改。
*/
router.patch(
'/:id/notification-channel',
validate({ params: idParamSchema, body: updateNotificationChannelSchema }),
async (req, res) => {
const user = getAuthUser(req);
const { id } = validatedParams<{ id: string }>(req);
sendOk(
res,
await classService.updateNotificationChannel(
user,
id,
validatedBody<UpdateNotificationChannelInput>(req),
),
'通知显示位置已更新',
);
},
);
/**
* GET /api/classes/:id/student-grade-query - 本班是否允许班级端按学号查成绩明细
* PATCH 同路径 - 开关它(班级端自己可改,教师/管理员也可改)
* PATCH 同路径 - 教师/管理员按班级管理权限设置,班级端只读
*/
router.get('/:id/student-grade-query', validate({ params: idParamSchema }), async (req, res) => {
const user = getAuthUser(req);
@@ -224,11 +176,7 @@ router.patch(
const { id } = validatedParams<{ id: string }>(req);
sendOk(
res,
await classService.updateStudentGradeQuery(
user,
id,
validatedBody<UpdateStudentGradeQueryInput>(req),
),
await classService.updateStudentGradeQuery(user, id, validatedBody<UpdateStudentGradeQueryInput>(req)),
'成绩查询开关已更新',
);
},
@@ -1,5 +1,5 @@
import { z } from 'zod';
import { CLASSISLAND_NOTIFICATION_CHANNELS, MAX_TERM_WEEK, SUBJECT_CATALOG, isDayKey } from '@classhelper/shared';
import { MAX_TERM_WEEK, SUBJECT_CATALOG, isDayKey } from '@classhelper/shared';
import {
classIndexSchema,
enrollmentYearSchema,
@@ -99,10 +99,7 @@ export const assignSubjectTeachersSchema = z.object({
.trim()
.min(1, '请选择或填写科目')
.max(32)
.refine(
(value) => value.length > 0,
{ message: '科目名不能为空' },
),
.refine((value) => value.length > 0, { message: '科目名不能为空' }),
teacherId: z.string().min(1).nullish(),
}),
)
@@ -114,17 +111,6 @@ export const assignHeadTeacherSchema = z.object({
teacherId: z.string().min(1, '请选择班主任'),
});
/**
* 通知显示位置(both / client / classisland)。
* 由 **ClassHelper 班级端**在设置页里改,教师/管理员也可以在 Web 端改。
*/
export const updateNotificationChannelSchema = z.object({
notificationChannel: z.enum(
CLASSISLAND_NOTIFICATION_CHANNELS as unknown as [string, ...string[]],
{ message: '显示位置只能是 both / client / classisland' },
),
});
/** 班级端按学号查询成绩明细的开关 */
export const updateStudentGradeQuerySchema = z.object({
enabled: z.boolean(),
@@ -138,7 +124,6 @@ export const classStudentParamSchema = z.object({
export type CreateClassInput = z.infer<typeof createClassSchema>;
export type UpdateClassInput = z.infer<typeof updateClassSchema>;
export type UpdateClassAccountInput = z.infer<typeof updateClassAccountSchema>;
export type UpdateNotificationChannelInput = z.infer<typeof updateNotificationChannelSchema>;
export type UpdateStudentGradeQueryInput = z.infer<typeof updateStudentGradeQuerySchema>;
export type AddStudentInput = z.infer<typeof addStudentSchema>;
export type AssignSubjectTeachersInput = z.infer<typeof assignSubjectTeachersSchema>;
@@ -1,10 +1,4 @@
import type {
ClassDetailDto,
ClassDto,
ClassIslandNotificationChannel,
StudentDto,
SubjectTeacherDto,
} from '@classhelper/shared';
import type { ClassDetailDto, ClassDto, StudentDto, SubjectTeacherDto } from '@classhelper/shared';
import { SOCKET_EVENTS, formatClassName } from '@classhelper/shared';
import { env } from '../../config/env.js';
import {
@@ -13,7 +7,6 @@ import {
assertCanManageRoster,
assertClassAccess,
classScopeIdFilter,
isClassDevice,
isStaff,
resolveClassScope,
} from '../../lib/access.js';
@@ -24,23 +17,15 @@ import {
import { prisma } from '../../lib/db.js';
import { ApiError } from '../../lib/http.js';
import type { TokenPayload } from '../../lib/jwt.js';
import {
toClassDto,
toCourseDto,
toNotificationChannel,
toStudentDto,
toTeacherBrief,
} from '../../lib/mappers.js';
import { toClassDto, toCourseDto, toStudentDto, toTeacherBrief } from '../../lib/mappers.js';
import { emitToClass } from '../../realtime/bus.js';
import type {
AddStudentInput,
AssignSubjectTeachersInput,
CreateClassInput,
UpdateClassInput,
UpdateNotificationChannelInput,
UpdateStudentGradeQueryInput,
} from './classes.schemas.js';
import { attachIntegrationFlag } from '../integrations/integrations.service.js';
import { logger } from '../../lib/logger.js';
const countSelect = {
@@ -106,8 +91,7 @@ export async function listClasses(user: TokenPayload, keyword?: string): Promise
orderBy: [{ enrollmentYear: 'desc' }, { classIndex: 'asc' }, { grade: 'asc' }],
});
// 附上「是否已接入 ClassIsland」徽标:Web 端班级列表/课表页据此提示
return attachIntegrationFlag(classes.map((item) => toClassDtoWithAccount(user, item)));
return classes.map((item) => toClassDtoWithAccount(user, item));
}
/** 班级详情:学生名单 + 课程 + 班主任 + 各科任课老师 */
@@ -261,7 +245,10 @@ export async function assignSubjectTeachers(
.teacherId;
const existing = assignment.courseId
? await prisma.course.findUnique({ where: { id: assignment.courseId }, select: { id: true, classId: true } })
? await prisma.course.findUnique({
where: { id: assignment.courseId },
select: { id: true, classId: true },
})
: await prisma.course.findUnique({
where: { classId_name: { classId, name: assignment.subjectName } },
select: { id: true, classId: true },
@@ -481,98 +468,6 @@ export async function removeStudent(user: TokenPayload, classId: string, student
emitToClass(classId, SOCKET_EVENTS.classUpdated, { classId, action: 'updated' });
}
/* ---------------------------------------------------------------- ClassHelper 班级端状态 */
/**
* 本班的 ClassHelper 联动状态(教室机器上的「联动」面板展示)。
*
* 为什么单独开一个接口:设备列表(/integrations/devices)是管理面,只对教师/管理员开放;
* 而教室机器(ClassHelper 班级端)需要知道"本班接没接 ClassIsland、最后什么时候上报的",
* 才能给出准确的提示(例如没接就别选"只在 ClassIsland 上弹")。
*/
export async function getClassIslandStatus(
user: TokenPayload,
classId: string,
): Promise<{
connected: boolean;
deviceName: string | null;
deviceCount: number;
onlineCount: number;
lastSeenAt: string | null;
lastHeartbeatAt: string | null;
pluginVersion: string | null;
classIslandVersion: string | null;
}> {
await assertClassAccess(user, classId);
const devices = await prisma.integrationDevice.findMany({
where: { classId, enabled: true, mode: 'plugin' },
select: {
name: true,
lastSeenAt: true,
lastHeartbeatAt: true,
pluginVersion: true,
classIslandVersion: true,
},
orderBy: { lastHeartbeatAt: 'desc' },
});
const latest = devices[0];
const window = 60_000;
return {
connected: devices.length > 0,
deviceName: latest?.name ?? null,
deviceCount: devices.length,
onlineCount: devices.filter(
(item) => item.lastHeartbeatAt && Date.now() - item.lastHeartbeatAt.getTime() < window,
).length,
lastSeenAt: latest?.lastSeenAt ? latest.lastSeenAt.toISOString() : null,
lastHeartbeatAt: latest?.lastHeartbeatAt ? latest.lastHeartbeatAt.toISOString() : null,
pluginVersion: latest?.pluginVersion ?? null,
classIslandVersion: latest?.classIslandVersion ?? null,
};
}
/* ---------------------------------------------------------------- 班级端设置 */
/**
* 读取班级的通知显示位置(both / client / classisland)。
* 这是**教室机器**要读的值:登录后拉一次,把自己的弹窗行为对齐到同一个选择。
*/
export async function getNotificationChannel(
user: TokenPayload,
classId: string,
): Promise<{ notificationChannel: ClassIslandNotificationChannel }> {
await assertClassAccess(user, classId);
const record = await prisma.class.findUnique({
where: { id: classId },
select: { notificationChannel: true },
});
return { notificationChannel: toNotificationChannel(record?.notificationChannel) };
}
/**
* 设置班级的通知显示位置。
*
* 允许两类人改:**该班的 ClassHelper 班级端**(需求就是"由教室机器自己选")
* 与教师 / 管理员(Web 端也能改,便于老师统一要求)。
*/
export async function updateNotificationChannel(
user: TokenPayload,
classId: string,
input: UpdateNotificationChannelInput,
): Promise<{ notificationChannel: ClassIslandNotificationChannel }> {
await assertClassAccess(user, classId);
if (!isClassDevice(user) && !isStaff(user)) {
throw ApiError.forbidden('只有 ClassHelper 班级端或教师/管理员可以修改通知显示位置');
}
const channel = toNotificationChannel(input.notificationChannel);
await prisma.class.update({ where: { id: classId }, data: { notificationChannel: channel } });
emitToClass(classId, SOCKET_EVENTS.classUpdated, { classId, action: 'updated' });
logger.info(`班级通知显示位置已更新:classId=${classId} channel=${channel} by=${user.sub}`);
return { notificationChannel: channel };
}
/**
* 读取「是否允许 ClassHelper 班级端按学号查询本班学生成绩明细」。
* 班级端设置页用它渲染开关的当前状态。
@@ -595,10 +490,7 @@ export async function getStudentGradeQuery(
* 设置「是否允许 ClassHelper 班级端查看本班成绩与排名」。
*
* **只有教师 / 管理员能改**(需求:「成绩查询由服务端控制,客户端只读」)。
* 原先班级端自己也能改这个开关 —— 教室机器能给自己开成绩查询,等于把
* "学校说不给看"变成了一台机器说了算;而与它同一套模式的「通知显示位置」
* (`Class.notificationChannel`)**仍然由班级端自己改**,那个确实是现场偏好,
* 两者别再按"同一个模式"去理解。关闭后班级端查成绩一律 403,教师端不受影响。
* 关闭后班级端查成绩一律 403,教师端不受影响。
*/
export async function updateStudentGradeQuery(
user: TokenPayload,