R38: 完成员工管理筛选与部门树试跑

这个提交包含在:
2026-03-28 13:15:32 +08:00
父节点 debef078f6
当前提交 f33431fdb8
共修改 9 个文件,包含 474 行新增和 60 行删除
+1 -1
查看文件
@@ -281,7 +281,7 @@ async function buildEmployeeProfile(prisma, employeeId) {
}
async function employeesRoutes(fastify) {
await usersRoutes(fastify, { basePath: "/employees" });
await usersRoutes(fastify, { basePath: "/employees", allowDepartmentFilter: true });
fastify.get("/employees/:id/profile", { preHandler: fastify.authenticate }, async (request, reply) => {
await ensureFeatureEnabled(fastify, request);
+11 -3
查看文件
@@ -32,6 +32,9 @@ const listQuerySchema = z.object({
status: z.enum(["active", "archived"]).optional(),
q: z.string().max(100).optional(),
});
const listQueryWithDepartmentSchema = listQuerySchema.extend({
departmentId: z.string().uuid().optional(),
});
const createBodySchema = z.object({
employeeNo: z.string().min(1).max(50),
@@ -86,8 +89,10 @@ function parseUserId(params) {
return parsed.data;
}
function parseListQuery(query) {
const parsed = listQuerySchema.safeParse(query ?? {});
function parseListQuery(query, options = {}) {
const allowDepartmentFilter = options.allowDepartmentFilter === true;
const schema = allowDepartmentFilter ? listQueryWithDepartmentSchema : listQuerySchema;
const parsed = schema.safeParse(query ?? {});
if (!parsed.success) {
throw new AppError({
code: "VALID_001",
@@ -102,6 +107,7 @@ function parseListQuery(query) {
pageSize: parsed.data.pageSize ?? 20,
status: parsed.data.status,
q: parsed.data.q?.trim() ?? "",
departmentId: allowDepartmentFilter ? parsed.data.departmentId : undefined,
};
}
@@ -232,6 +238,7 @@ async function usersRoutes(fastify, opts = {}) {
typeof opts.basePath === "string" && opts.basePath.trim() ? opts.basePath.trim() : "/users";
const basePath = basePathRaw.startsWith("/") ? basePathRaw : `/${basePathRaw}`;
const routeBasePath = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
const allowDepartmentFilter = opts.allowDepartmentFilter === true;
fastify.get(
routeBasePath,
@@ -239,12 +246,13 @@ async function usersRoutes(fastify, opts = {}) {
preHandler: fastify.requirePermission("system.users"),
},
async (request, reply) => {
const query = parseListQuery(request.query);
const query = parseListQuery(request.query, { allowDepartmentFilter });
const skip = (query.page - 1) * query.pageSize;
const q = query.q;
const where = {
...(query.status ? { status: query.status } : {}),
...(query.departmentId ? { department_id: query.departmentId } : {}),
...(q
? {
OR: [