Files
SAAS/src/app/api/team/users/route.ts
2025-05-14 00:30:11 +08:00

39 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 团队用户API路由
* 作者: 阿瑞
* 功能: 提供团队用户相关API演示如何使用团队数据库连接
* 版本: 2.0
*/
import { NextRequest, NextResponse } from 'next/server';
import { connectTeamDB, RequestWithDB } from '@/lib/db';
/**
* 获取团队用户列表
* 自动从请求中提取团队信息并连接对应的数据库
*/
export async function GET(req: NextRequest) {
try {
// 使用connectTeamDB中间件处理请求
return await connectTeamDB(async (dbReq: RequestWithDB) => {
try {
// 执行SQL查询
const [users] = await dbReq.db.query('SELECT * FROM users LIMIT 100');
return NextResponse.json({ users });
} catch (error) {
console.error('查询用户列表失败:', error);
return NextResponse.json(
{ error: '查询用户列表失败' },
{ status: 500 }
);
}
})(req);
} catch (error) {
console.error('处理请求失败:', error);
return NextResponse.json(
{ error: '处理请求失败' },
{ status: 500 }
);
}
}