Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
add [properties-be] - util for document and task isCompleted (#617)
Daniel Kweona172768c83f8
diff --git a/rust/cloud-storage/properties/.sqlx/query-45ac2a692bf3676d053ca1905fe8586ff1dd139822d3cbde8e125add5575194a.json b/rust/cloud-storage/properties/.sqlx/query-45ac2a692bf3676d053ca1905fe8586ff1dd139822d3cbde8e125add5575194a.jsonnew file mode 100644index 0000000000..fcef7e28e8--- /dev/null+++ b/rust/cloud-storage/properties/.sqlx/query-45ac2a692bf3676d053ca1905fe8586ff1dd139822d3cbde8e125add5575194a.json@@ -0,0 +1,40 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT values as \"values: serde_json::Value\"\n FROM entity_properties\n WHERE entity_id = $1\n AND entity_type = $2\n AND property_definition_id = $3\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "values: serde_json::Value",+ "type_info": "Jsonb"+ }+ ],+ "parameters": {+ "Left": [+ "Text",+ {+ "Custom": {+ "name": "property_entity_type",+ "kind": {+ "Enum": [+ "CHANNEL",+ "CHAT",+ "DOCUMENT",+ "PROJECT",+ "THREAD",+ "USER",+ "COMPANY",+ "TASK"+ ]+ }+ }+ },+ "Uuid"+ ]+ },+ "nullable": [+ true+ ]+ },+ "hash": "45ac2a692bf3676d053ca1905fe8586ff1dd139822d3cbde8e125add5575194a"+}diff --git a/rust/cloud-storage/properties/src/domain/ports.rs b/rust/cloud-storage/properties/src/domain/ports.rsindex 3d26bd4e6c..3b5a733d48 100644--- a/rust/cloud-storage/properties/src/domain/ports.rs+++ b/rust/cloud-storage/properties/src/domain/ports.rs@@ -51,4 +51,13 @@ pub trait PropertiesRepo: Send + Sync + 'static {task_id: Uuid,subtask_ids: Vec<Uuid>,) -> impl Future<Output = Result<(), Self::Err>> + Send;++ /// Get a property value for a specific entity and property definition.+ /// Returns `None` if the property is not attached to the entity.+ fn get_entity_property_value(+ &self,+ entity_id: &str,+ entity_type: EntityType,+ property_definition_id: Uuid,+ ) -> impl Future<Output = Result<Option<PropertyValue>, Self::Err>> + Send;}diff --git a/rust/cloud-storage/properties/src/domain/service.rs b/rust/cloud-storage/properties/src/domain/service.rsindex f1a0a56f18..5a073fab5b 100644--- a/rust/cloud-storage/properties/src/domain/service.rs+++ b/rust/cloud-storage/properties/src/domain/service.rs@@ -1,6 +1,8 @@//! Service trait for properties.use models_properties::EntityType;+use models_properties::service::property_value::PropertyValue;+use system_properties::SystemPropertyKey;use uuid::Uuid;/// Service trait for property operations.@@ -41,4 +43,22 @@ pub trait PropertiesService: Send + Sync + 'static {task_id: Uuid,subtask_ids: Vec<Uuid>,) -> impl Future<Output = Result<(), Self::Err>> + Send;++ /// Get a property value for an entity by property definition ID.+ /// Returns `None` if the property is not attached to the entity.+ fn get_property_value(+ &self,+ entity_id: &str,+ entity_type: EntityType,+ property_definition_id: Uuid,+ ) -> impl Future<Output = Result<Option<PropertyValue>, Self::Err>> + Send;++ /// Get a system property value for an entity.+ /// Returns `None` if the property is not attached to the entity.+ fn get_system_property_value(+ &self,+ entity_id: &str,+ entity_type: EntityType,+ property_key: SystemPropertyKey,+ ) -> impl Future<Output = Result<Option<PropertyValue>, Self::Err>> + Send;}diff --git a/rust/cloud-storage/properties/src/domain/service_impl.rs b/rust/cloud-storage/properties/src/domain/service_impl.rsindex 5c6858b6fc..af4fd03004 100644--- a/rust/cloud-storage/properties/src/domain/service_impl.rs+++ b/rust/cloud-storage/properties/src/domain/service_impl.rs@@ -73,4 +73,27 @@ whereasync fn link_subtasks(&self, task_id: Uuid, subtask_ids: Vec<Uuid>) -> Result<(), Self::Err> {self.repository.link_subtasks(task_id, subtask_ids).await}++ #[tracing::instrument(skip(self), fields(entity_id = %entity_id, entity_type = ?entity_type, property_definition_id = %property_definition_id))]+ async fn get_property_value(+ &self,+ entity_id: &str,+ entity_type: EntityType,+ property_definition_id: Uuid,+ ) -> Result<Option<PropertyValue>, Self::Err> {+ self.repository+ .get_entity_property_value(entity_id, entity_type, property_definition_id)+ .await+ }++ #[tracing::instrument(skip(self), fields(entity_id = %entity_id, entity_type = ?entity_type, property_key = ?property_key))]+ async fn get_system_property_value(+ &self,+ entity_id: &str,+ entity_type: EntityType,+ property_key: SystemPropertyKey,+ ) -> Result<Option<PropertyValue>, Self::Err> {+ self.get_property_value(entity_id, entity_type, property_key.uuid())+ .await+ }}diff --git a/rust/cloud-storage/properties/src/domain/test.rs b/rust/cloud-storage/properties/src/domain/test.rsindex f27c8b21b6..61c7c8daaf 100644--- a/rust/cloud-storage/properties/src/domain/test.rs+++ b/rust/cloud-storage/properties/src/domain/test.rs@@ -162,7 +162,6 @@ async fn test_link_subtasks_error_propagates() {repo.expect_link_subtasks().returning(|_, _| Box::pin(async { Err(anyhow!("subtask link failed")) }));-let service = PropertiesServiceImpl::new(repo);let err = service@@ -172,3 +171,134 @@ async fn test_link_subtasks_error_propagates() {assert_eq!(err.to_string(), "subtask link failed");}++// ============================================================================+// get_property_value unit tests+// ============================================================================++#[tokio::test]+async fn test_get_property_value_returns_value_when_exists() {+ let mut repo = MockPropertiesRepo::new();++ let prop_id = Uuid::from_u128(0xdeadbeef_dead_beef_dead_beefdeadbeef);++ repo.expect_get_entity_property_value()+ .withf(move |entity_id, entity_type, p| {+ entity_id == "e1" && *entity_type == EntityType::Document && *p == prop_id+ })+ .returning(|_, _, _| Box::pin(async { Ok(Some(PropertyValue::Str("hello".to_string()))) }));++ let service = PropertiesServiceImpl::new(repo);++ let result = service+ .get_property_value("e1", EntityType::Document, prop_id)+ .await+ .unwrap();++ assert_eq!(result, Some(PropertyValue::Str("hello".to_string())));+}++#[tokio::test]+async fn test_get_property_value_returns_none_when_not_attached() {+ let mut repo = MockPropertiesRepo::new();++ repo.expect_get_entity_property_value()+ .returning(|_, _, _| Box::pin(async { Ok(None) }));++ let service = PropertiesServiceImpl::new(repo);++ let result = service+ .get_property_value("e1", EntityType::Document, Uuid::nil())+ .await+ .unwrap();++ assert_eq!(result, None);+}++#[tokio::test]+async fn test_get_property_value_error_path() {+ let mut repo = MockPropertiesRepo::new();++ repo.expect_get_entity_property_value()+ .returning(|_, _, _| Box::pin(async { Err(anyhow!("db error")) }));++ let service = PropertiesServiceImpl::new(repo);++ let err = service+ .get_property_value("e1", EntityType::Document, Uuid::nil())+ .await+ .unwrap_err();++ assert_eq!(err.to_string(), "db error");+}++// ============================================================================+// get_system_property_value unit tests+// ============================================================================++#[tokio::test]+async fn test_get_system_property_value_returns_value_when_exists() {+ let mut repo = MockPropertiesRepo::new();++ repo.expect_get_entity_property_value()+ .withf(|entity_id, entity_type, prop_id| {+ entity_id == "e1"+ && *entity_type == EntityType::Document+ && *prop_id == SystemPropertyKey::STATUS_UUID+ })+ .returning(|_, _, _| {+ Box::pin(async {+ Ok(Some(PropertyValue::SelectOption(vec![+ StatusOption::COMPLETED_UUID,+ ])))+ })+ });++ let service = PropertiesServiceImpl::new(repo);++ let result = service+ .get_system_property_value("e1", EntityType::Document, SystemPropertyKey::Status)+ .await+ .unwrap();++ assert_eq!(+ result,+ Some(PropertyValue::SelectOption(vec![+ StatusOption::COMPLETED_UUID+ ]))+ );+}++#[tokio::test]+async fn test_get_system_property_value_returns_none_when_not_attached() {+ let mut repo = MockPropertiesRepo::new();++ repo.expect_get_entity_property_value()+ .returning(|_, _, _| Box::pin(async { Ok(None) }));++ let service = PropertiesServiceImpl::new(repo);++ let result = service+ .get_system_property_value("e1", EntityType::Document, SystemPropertyKey::Status)+ .await+ .unwrap();++ assert_eq!(result, None);+}++#[tokio::test]+async fn test_get_system_property_value_error_path() {+ let mut repo = MockPropertiesRepo::new();++ repo.expect_get_entity_property_value()+ .returning(|_, _, _| Box::pin(async { Err(anyhow!("db error")) }));++ let service = PropertiesServiceImpl::new(repo);++ let err = service+ .get_system_property_value("e1", EntityType::Document, SystemPropertyKey::Status)+ .await+ .unwrap_err();++ assert_eq!(err.to_string(), "db error");+}diff --git a/rust/cloud-storage/properties/src/outbound/properties_pg_repo.rs b/rust/cloud-storage/properties/src/outbound/properties_pg_repo.rsindex 5b0be4ebbf..44ea8c7afd 100644--- a/rust/cloud-storage/properties/src/outbound/properties_pg_repo.rs+++ b/rust/cloud-storage/properties/src/outbound/properties_pg_repo.rs@@ -55,4 +55,39 @@ impl PropertiesRepo for PropertiesPgRepo {async fn link_subtasks(&self, task_id: Uuid, subtask_ids: Vec<Uuid>) -> Result<(), Self::Err> {task_property_queries::link_subtasks(&self.pool, task_id, subtask_ids).await}++ #[tracing::instrument(skip(self))]+ async fn get_entity_property_value(+ &self,+ entity_id: &str,+ entity_type: EntityType,+ property_definition_id: Uuid,+ ) -> Result<Option<PropertyValue>, Self::Err> {+ let row = sqlx::query!(+ r#"+ SELECT values as "values: serde_json::Value"+ FROM entity_properties+ WHERE entity_id = $1+ AND entity_type = $2+ AND property_definition_id = $3+ "#,+ entity_id,+ entity_type as EntityType,+ property_definition_id+ )+ .fetch_optional(&self.pool)+ .await?;++ match row {+ None => Ok(None),+ Some(r) => match r.values {+ None => Ok(None),+ Some(json_value) if json_value.is_null() => Ok(None),+ Some(json_value) => {+ let value: PropertyValue = serde_json::from_value(json_value)?;+ Ok(Some(value))+ }+ },+ }+ }}