diff --git a/Cargo.toml b/Cargo.toml index da91926..11b4c58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,4 +32,4 @@ regex = "1.10.0" ctor = "0.2.6" axum-client-ip = "0.4.0" jsonwebtoken = "9" -tower = "0.4.13" \ No newline at end of file +tower = "0.4.13" diff --git a/src/endpoints/admin/quest/get_quest_participants.rs b/src/endpoints/admin/quest/get_quest_participants.rs index 23735cb..217edbf 100644 --- a/src/endpoints/admin/quest/get_quest_participants.rs +++ b/src/endpoints/admin/quest/get_quest_participants.rs @@ -58,11 +58,13 @@ pub async fn get_quest_participants_handler( doc! { "$match": { "task_id": { "$in": &task_ids } } }, doc! { "$group": { "_id": "$address", - "task_ids": { "$addToSet": "$task_id" } + "task_ids": { "$addToSet": "$task_id" }, + "max_timestamp": { "$max": "$timestamp" } }}, doc! { "$project": { "address": "$_id", - "tasks_completed_count": { "$size": "$task_ids" } + "tasks_completed_count": { "$size": "$task_ids" }, + "quest_completion_timestamp": "$max_timestamp" }}, ]; @@ -83,13 +85,21 @@ pub async fn get_quest_participants_handler( Err(_) => continue, // Skip invalid documents }; + let timestamp = match doc.get_i64("quest_completion_timestamp") { + Ok(ts) => ts, + Err(_) => continue, // Skip invalid documents + }; + let tasks_completed_count: usize = match doc.get_i32("tasks_completed_count") { Ok(count) => count as usize, Err(_) => continue, // Skip invalid documents }; if tasks_completed_count == total_tasks { - participants.push(address); + participants.push(json!({ + "address": address, + "quest_completion_timestamp": timestamp, + })); } } Err(e) => return get_error(format!("Error processing aggregation results: {}", e)),