Skip to content

Commit

Permalink
Merge pull request #118 from starknet-id/feat/ordering-tasks
Browse files Browse the repository at this point in the history
feat: ordering tasks in a quest
  • Loading branch information
Th0rgal authored Oct 29, 2023
2 parents 6f1b694 + 8a6a3ff commit 45d7a5c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/endpoints/get_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ pub async fn handler(
},
doc! { "$unwind": "$quest" },
doc! { "$match": { "quest.disabled": false } },
doc! {
"$addFields": {
"sort_order": doc! {
"$switch": {
"branches": [
{
"case": doc! { "$eq": ["$verify_endpoint_type", "quiz"] },
"then": 1
},
{
"case": doc! { "$eq": ["$verify_endpoint_type", "default"] },
"then": 2
}
],
"default": 3
}
}
}
},
doc! { "$sort": { "sort_order": 1 } },
doc! {
"$project": {
"_id": 0,
Expand Down Expand Up @@ -96,7 +116,6 @@ pub async fn handler(
if tasks.is_empty() {
get_error("No tasks found for this quest_id".to_string())
} else {
tasks.sort_by(|a, b| a.id.cmp(&b.id));
(StatusCode::OK, Json(tasks)).into_response()
}
}
Expand Down

0 comments on commit 45d7a5c

Please sign in to comment.