steel validation in progress
This commit is contained in:
@@ -2,8 +2,29 @@
|
||||
use tonic::Status;
|
||||
use sqlx::{PgPool, Error as SqlxError};
|
||||
use common::proto::multieko2::table_script::{PostTableScriptRequest, TableScriptResponse};
|
||||
use crate::steel::handlers::evaluator::validate_target_column;
|
||||
use crate::steel::validation::script::validate_script;
|
||||
use serde_json::Value;
|
||||
|
||||
const SYSTEM_COLUMNS: &[&str] = &["id", "deleted", "created_at"];
|
||||
|
||||
fn validate_target_column(
|
||||
table_name: &str,
|
||||
target: &str,
|
||||
table_columns: &Value,
|
||||
) -> Result<(), String> {
|
||||
if SYSTEM_COLUMNS.contains(&target) {
|
||||
return Err(format!("Cannot override system column: {}", target));
|
||||
}
|
||||
|
||||
let columns: Vec<String> = serde_json::from_value(table_columns.clone())
|
||||
.map_err(|e| format!("Invalid column data: {}", e))?;
|
||||
|
||||
if !columns.iter().any(|c| c == target) {
|
||||
return Err(format!("Target column {} not defined in table {}", target, table_name));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn post_table_script(
|
||||
db_pool: &PgPool,
|
||||
|
||||
Reference in New Issue
Block a user