75 lines
2.5 KiB
TypeScript
75 lines
2.5 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getEvents, EventsQueryParams } from '@/lib/analytics';
|
|
import { ApiResponse } from '@/lib/types';
|
|
|
|
// 获取事件列表
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const { searchParams } = new URL(request.url);
|
|
|
|
// 获取查询参数
|
|
const page = parseInt(searchParams.get('page') || '1');
|
|
const pageSize = parseInt(searchParams.get('pageSize') || '20');
|
|
const eventType = searchParams.get('eventType') || undefined;
|
|
const linkId = searchParams.get('linkId') || undefined;
|
|
const linkSlug = searchParams.get('linkSlug') || undefined;
|
|
const userId = searchParams.get('userId') || undefined;
|
|
const subpath = searchParams.get('subpath') || undefined;
|
|
|
|
// 获取可能存在的多个团队、项目和标签ID
|
|
const teamIds = searchParams.getAll('teamId');
|
|
const projectIds = searchParams.getAll('projectId');
|
|
const tagIds = searchParams.getAll('tagId');
|
|
|
|
const startTime = searchParams.get('startTime') || undefined;
|
|
const endTime = searchParams.get('endTime') || undefined;
|
|
const sortBy = searchParams.get('sortBy') || undefined;
|
|
const sortOrder = (searchParams.get('sortOrder') as 'asc' | 'desc') || undefined;
|
|
|
|
console.log("API接收到的tagIds:", tagIds); // 添加日志便于调试
|
|
console.log("API接收到的subpath:", subpath); // 添加日志便于调试
|
|
|
|
// 获取事件列表
|
|
const params: EventsQueryParams = {
|
|
page,
|
|
pageSize,
|
|
eventType,
|
|
linkId,
|
|
linkSlug,
|
|
userId,
|
|
subpath,
|
|
teamIds: teamIds.length > 0 ? teamIds : undefined,
|
|
projectIds: projectIds.length > 0 ? projectIds : undefined,
|
|
tagIds: tagIds.length > 0 ? tagIds : undefined,
|
|
startTime,
|
|
endTime,
|
|
sortBy,
|
|
sortOrder
|
|
};
|
|
|
|
// 记录完整的参数用于调试
|
|
console.log("完整请求参数:", JSON.stringify(params));
|
|
|
|
const result = await getEvents(params);
|
|
|
|
const response: ApiResponse<typeof result.events> = {
|
|
success: true,
|
|
data: result.events,
|
|
meta: {
|
|
total: result.total,
|
|
page,
|
|
pageSize
|
|
}
|
|
};
|
|
|
|
return NextResponse.json(response);
|
|
} catch (error) {
|
|
console.error('获取事件列表失败:', error);
|
|
const response: ApiResponse<null> = {
|
|
success: false,
|
|
data: null,
|
|
error: error instanceof Error ? error.message : '获取事件列表失败'
|
|
};
|
|
return NextResponse.json(response, { status: 500 });
|
|
}
|
|
}
|