|
|
|
|
@ -138,7 +138,9 @@ impl Merger {
|
|
|
|
|
is_child: bool,
|
|
|
|
|
) -> Result<Value, String> {
|
|
|
|
|
match data {
|
|
|
|
|
Value::Array(items) => self.merge_array(schema, items, notifications, parent_org_id, is_child),
|
|
|
|
|
Value::Array(items) => {
|
|
|
|
|
self.merge_array(schema, items, notifications, parent_org_id, is_child)
|
|
|
|
|
}
|
|
|
|
|
Value::Object(map) => {
|
|
|
|
|
if let Some(options) = schema.obj.compiled_options.get() {
|
|
|
|
|
if let Some(disc) = schema.obj.compiled_discriminator.get() {
|
|
|
|
|
@ -210,7 +212,13 @@ impl Merger {
|
|
|
|
|
|
|
|
|
|
let mut resolved_items = Vec::new();
|
|
|
|
|
for item in items {
|
|
|
|
|
let resolved = self.merge_internal(item_schema.clone(), item, notifications, parent_org_id.clone(), is_child)?;
|
|
|
|
|
let resolved = self.merge_internal(
|
|
|
|
|
item_schema.clone(),
|
|
|
|
|
item,
|
|
|
|
|
notifications,
|
|
|
|
|
parent_org_id.clone(),
|
|
|
|
|
is_child,
|
|
|
|
|
)?;
|
|
|
|
|
resolved_items.push(resolved);
|
|
|
|
|
}
|
|
|
|
|
Ok(Value::Array(resolved_items))
|
|
|
|
|
@ -340,7 +348,10 @@ impl Merger {
|
|
|
|
|
if let Some(relation) = self.db.relations.get(&edge.constraint) {
|
|
|
|
|
let parent_is_source = edge.forward;
|
|
|
|
|
|
|
|
|
|
let org_id_to_pass = entity_fields.get("organization_id").and_then(|v| v.as_str()).map(|s| s.to_string());
|
|
|
|
|
let org_id_to_pass = entity_fields
|
|
|
|
|
.get("organization_id")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.map(|s| s.to_string());
|
|
|
|
|
if parent_is_source {
|
|
|
|
|
let mut merged_relative = match self.merge_internal(
|
|
|
|
|
rel_schema.clone(),
|
|
|
|
|
@ -443,7 +454,10 @@ impl Merger {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let org_id_to_pass = entity_fields.get("organization_id").and_then(|v| v.as_str()).map(|s| s.to_string());
|
|
|
|
|
let org_id_to_pass = entity_fields
|
|
|
|
|
.get("organization_id")
|
|
|
|
|
.and_then(|v| v.as_str())
|
|
|
|
|
.map(|s| s.to_string());
|
|
|
|
|
let mut relative_responses = Vec::new();
|
|
|
|
|
for relative_item_val in relative_arr {
|
|
|
|
|
if let Value::Object(mut relative_item) = relative_item_val {
|
|
|
|
|
@ -946,12 +960,10 @@ impl Merger {
|
|
|
|
|
Value::Object(old_vals)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let entity_type_name = type_name.as_str().unwrap_or(&type_obj.name);
|
|
|
|
|
|
|
|
|
|
let mut notification = serde_json::Map::new();
|
|
|
|
|
notification.insert("kind".to_string(), Value::String(change_kind.to_string()));
|
|
|
|
|
notification.insert("complete".to_string(), Value::Object(complete));
|
|
|
|
|
notification.insert("new".to_string(), new_val_obj.clone());
|
|
|
|
|
notification.insert("kind".to_string(), Value::String(change_kind.to_string()));
|
|
|
|
|
|
|
|
|
|
if old_val_obj != Value::Null {
|
|
|
|
|
notification.insert("old".to_string(), old_val_obj.clone());
|
|
|
|
|
@ -964,15 +976,14 @@ impl Merger {
|
|
|
|
|
let mut notify_sql = None;
|
|
|
|
|
if type_obj.historical && change_kind != "replace" {
|
|
|
|
|
let change_sql = format!(
|
|
|
|
|
"INSERT INTO agreego.change (\"old\", \"new\", \"entity_id\", \"id\", \"kind\", \"modified_at\", \"modified_by\", \"entity_type\") VALUES ({}, {}, {}, {}, {}, {}, {}, {})",
|
|
|
|
|
"INSERT INTO agreego.change (\"old\", \"new\", \"entity_id\", \"id\", \"kind\", \"modified_at\", \"modified_by\") VALUES ({}, {}, {}, {}, {}, {}, {})",
|
|
|
|
|
Self::quote_literal(&old_val_obj),
|
|
|
|
|
Self::quote_literal(&new_val_obj),
|
|
|
|
|
Self::quote_literal(id_str),
|
|
|
|
|
Self::quote_literal(&Value::String(uuid::Uuid::new_v4().to_string())),
|
|
|
|
|
Self::quote_literal(&Value::String(change_kind.to_string())),
|
|
|
|
|
Self::quote_literal(&Value::String(timestamp.to_string())),
|
|
|
|
|
Self::quote_literal(&Value::String(user_id.to_string())),
|
|
|
|
|
Self::quote_literal(&Value::String(entity_type_name.to_string()))
|
|
|
|
|
Self::quote_literal(&Value::String(user_id.to_string()))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
self.db.execute(&change_sql, None)?;
|
|
|
|
|
|