diff --git a/src/endpoints/get_quest.rs b/src/endpoints/get_quest.rs index 16d161dc..64cd70b9 100644 --- a/src/endpoints/get_quest.rs +++ b/src/endpoints/get_quest.rs @@ -21,7 +21,10 @@ pub async fn handler( Query(query): Query, ) -> impl IntoResponse { let collection = state.db.collection::("quests"); - match collection.find_one(doc! {"id": query.id}, None).await { + match collection + .find_one(doc! {"id": query.id, "disabled" : false}, None) + .await + { Ok(Some(quest)) => (StatusCode::OK, Json(quest)).into_response(), Ok(None) => get_error("Quest not found".to_string()), Err(_) => get_error("Error querying quest".to_string()), diff --git a/src/endpoints/get_quests.rs b/src/endpoints/get_quests.rs index 178b0c20..280e84a6 100644 --- a/src/endpoints/get_quests.rs +++ b/src/endpoints/get_quests.rs @@ -20,7 +20,13 @@ pub struct NFTItem { pub async fn handler(State(state): State>) -> impl IntoResponse { let collection = state.db.collection::("quests"); - match collection.find(None, None).await { + let filter = doc! { + "$and": [ + {"disabled": false}, + {"hidden": false} + ] + }; + match collection.find(Some(filter), None).await { Ok(cursor) => { let quests: Vec = cursor.try_collect().await.unwrap_or_else(|_| vec![]); if quests.is_empty() { @@ -29,6 +35,6 @@ pub async fn handler(State(state): State>) -> impl IntoResponse { (StatusCode::OK, Json(quests)).into_response() } } - Err(_) => get_error("Error querying quest".to_string()), + Err(_) => get_error("Error querying quests".to_string()), } } diff --git a/src/endpoints/get_tasks.rs b/src/endpoints/get_tasks.rs index a2549b8a..fa439c4a 100644 --- a/src/endpoints/get_tasks.rs +++ b/src/endpoints/get_tasks.rs @@ -51,6 +51,16 @@ pub async fn handler( "as": "completed", } }, + doc! { + "$lookup": { + "from": "quests", + "localField": "quest_id", + "foreignField": "id", + "as": "quest" + } + }, + doc! { "$unwind": "$quest" }, + doc! { "$match": { "quest.disabled": false } }, doc! { "$project": { "_id": 0, diff --git a/src/models.rs b/src/models.rs index 7738561b..0cf5ee9c 100644 --- a/src/models.rs +++ b/src/models.rs @@ -28,7 +28,8 @@ pub_struct!(Debug, Serialize, Deserialize; QuestDocument { rewards_nfts: Vec, img_card: String, title_card: String, - finished: bool, + hidden: bool, + disabled: bool, }); pub_struct!(Deserialize; CompletedTasks {