summary filter
This commit is contained in:
@@ -6,10 +6,18 @@ export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const searchParams = request.nextUrl.searchParams;
|
||||
|
||||
// 获取可能存在的多个团队、项目和标签ID
|
||||
const teamIds = searchParams.getAll('teamId');
|
||||
const projectIds = searchParams.getAll('projectId');
|
||||
const tagIds = searchParams.getAll('tagId');
|
||||
|
||||
const summary = await getEventsSummary({
|
||||
startTime: searchParams.get('startTime') || undefined,
|
||||
endTime: searchParams.get('endTime') || undefined,
|
||||
linkId: searchParams.get('linkId') || undefined
|
||||
linkId: searchParams.get('linkId') || undefined,
|
||||
teamIds: teamIds.length > 0 ? teamIds : undefined,
|
||||
projectIds: projectIds.length > 0 ? projectIds : undefined,
|
||||
tagIds: tagIds.length > 0 ? tagIds : undefined
|
||||
});
|
||||
|
||||
const response: ApiResponse<typeof summary> = {
|
||||
|
||||
@@ -57,6 +57,9 @@ export async function getEventsSummary(params: {
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
linkId?: string;
|
||||
teamIds?: string[];
|
||||
projectIds?: string[];
|
||||
tagIds?: string[];
|
||||
}): Promise<EventsSummary> {
|
||||
const filter = buildFilter(params);
|
||||
|
||||
|
||||
@@ -56,16 +56,29 @@ export function buildFilter(params: Partial<EventsQueryParams>): string {
|
||||
filters.push(`user_id = '${params.userId}'`);
|
||||
}
|
||||
|
||||
// 团队ID过滤
|
||||
if (params.teamId) {
|
||||
// 团队ID过滤 - 支持多选
|
||||
if (params.teamIds && params.teamIds.length > 0) {
|
||||
const teamValues = params.teamIds.map(id => `'${id}'`).join(', ');
|
||||
filters.push(`team_id IN (${teamValues})`);
|
||||
} else if (params.teamId) {
|
||||
filters.push(`team_id = '${params.teamId}'`);
|
||||
}
|
||||
|
||||
// 项目ID过滤
|
||||
if (params.projectId) {
|
||||
// 项目ID过滤 - 支持多选
|
||||
if (params.projectIds && params.projectIds.length > 0) {
|
||||
const projectValues = params.projectIds.map(id => `'${id}'`).join(', ');
|
||||
filters.push(`project_id IN (${projectValues})`);
|
||||
} else if (params.projectId) {
|
||||
filters.push(`project_id = '${params.projectId}'`);
|
||||
}
|
||||
|
||||
// 标签ID过滤 - 支持多选
|
||||
if (params.tagIds && params.tagIds.length > 0) {
|
||||
// 假设我们在link_tags字段存储标签ID的JSON数组
|
||||
const tagConditions = params.tagIds.map(id => `arrayExists(x -> x = '${id}', JSONExtractArrayRaw(link_tags))`);
|
||||
filters.push(`(${tagConditions.join(' OR ')})`);
|
||||
}
|
||||
|
||||
return filters.length > 0 ? `WHERE ${filters.join(' AND ')}` : '';
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,10 @@ export interface EventsQueryParams {
|
||||
linkSlug?: string;
|
||||
userId?: string;
|
||||
teamId?: string;
|
||||
teamIds?: string[]; // 团队ID数组,支持多选
|
||||
projectId?: string;
|
||||
projectIds?: string[]; // 项目ID数组,支持多选
|
||||
tagIds?: string[]; // 标签ID数组,支持多选
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
sortBy?: string;
|
||||
|
||||
Reference in New Issue
Block a user