From 67e6da345aaf40efe64ab326ffb19a2bc1552d24 Mon Sep 17 00:00:00 2001 From: imabdulbasit Date: Thu, 27 Jul 2023 03:48:23 +0500 Subject: [PATCH] Update total_mints when indexing each mint & fix metadata_json indexing --- api/src/events.rs | 15 ++++++++++++--- api/src/mutations/collection.rs | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/api/src/events.rs b/api/src/events.rs index 4360d89..d218634 100644 --- a/api/src/events.rs +++ b/api/src/events.rs @@ -214,7 +214,7 @@ impl Processor { project_id: Set(project_id.parse()?), credits_deduction_id: Set(None), creation_status: Set(CreationStatus::Created), - total_mints: Set(-1), + total_mints: Set(0), address: Set(Some(mint_address)), signature: Set(None), seller_fee_basis_points: Set(seller_fee_basis_points.try_into()?), @@ -233,7 +233,7 @@ impl Processor { image: Set(image), animation_url: Set(None), external_url: Set(None), - ..Default::default() + identifier: Set(String::new()), }; let json_model = metadata_json.insert(self.db.get()).await?; @@ -307,7 +307,7 @@ impl Processor { image: Set(image), animation_url: Set(None), external_url: Set(None), - ..Default::default() + identifier: Set(String::new()), }; let json_model = metadata_json.insert(self.db.get()).await?; @@ -324,6 +324,15 @@ impl Processor { index_attributes(&self.db, json_model.id, attributes).await?; index_files(&self.db, json_model.id, files).await?; + let collection = Collections::find_by_id(collection_id.parse()?) + .one(self.db.get()) + .await + .context("failed to load collection from db")? + .context("collection not found in db")?; + let mut collection_am: collections::ActiveModel = collection.clone().into(); + + collection_am.total_mints = Set(collection.total_mints + 1); + Ok(()) } diff --git a/api/src/mutations/collection.rs b/api/src/mutations/collection.rs index 462d21b..6a06008 100644 --- a/api/src/mutations/collection.rs +++ b/api/src/mutations/collection.rs @@ -311,7 +311,7 @@ impl Mutation { )), }), Some(&NftEventKey { - id: String::new(), + id: Uuid::new_v4().to_string(), project_id: input.project.to_string(), user_id: user_id.to_string(), }),