Compare commits

...

1 Commits

Author SHA1 Message Date
root 60ec60bf29 fix: sb_atualizar_fechamento aceita id numerico ou UUID string
Build Fechamento de Caixa / build (macos-14, app) (push) Has been cancelled
Build Fechamento de Caixa / build (ubuntu-22.04, deb) (push) Has been cancelled
Build Fechamento de Caixa / build (windows-2022, msi) (push) Has been cancelled
2026-06-29 12:39:50 +00:00
+14 -9
View File
@@ -247,12 +247,14 @@ impl SupabaseClient {
} }
} }
/// Atualiza campos específicos de um fechamento pelo id numérico (PATCH). /// Atualiza campos específicos de um fechamento pelo id numérico (pk) ou UUID.
pub fn atualizar_fechamento(&self, id: i64, updates: &serde_json::Value) -> Result<Value, SupabaseError> { pub fn atualizar_fechamento(&self, id: Option<i64>, uuid: &str, updates: &serde_json::Value) -> Result<Value, SupabaseError> {
let url = format!( // Se temos id numerico, usa id=eq.; senao usa id=eq.UUID
"{}/rest/v1/fechamentos_web?id=eq.{}", let url = if let Some(num) = id {
self.base_url, id format!("{}/rest/v1/fechamentos_web?id=eq.{}", self.base_url, num)
); } else {
format!("{}/rest/v1/fechamentos_web?id=eq.{}", self.base_url, uuid)
};
let resp = self let resp = self
.http .http
@@ -262,7 +264,7 @@ impl SupabaseClient {
.send()?; .send()?;
if resp.status().is_success() { if resp.status().is_success() {
Ok(serde_json::json!({ "ok": true, "id": id })) Ok(serde_json::json!({ "ok": true, "id": id.unwrap_or(0) }))
} else { } else {
let status = resp.status(); let status = resp.status();
let body = resp.text().unwrap_or_default(); let body = resp.text().unwrap_or_default();
@@ -462,10 +464,13 @@ pub fn sb_buscar_por_id_fechamento(
#[tauri::command] #[tauri::command]
pub fn sb_atualizar_fechamento( pub fn sb_atualizar_fechamento(
sb: State<'_, SupabaseClient>, sb: State<'_, SupabaseClient>,
id: i64, id: String,
updates: serde_json::Value, updates: serde_json::Value,
) -> Result<serde_json::Value, SupabaseError> { ) -> Result<serde_json::Value, SupabaseError> {
sb.atualizar_fechamento(id, &updates) // Tenta primeiro como i64 (id numerico), depois como String (UUID)
let id_i64 = id.parse::<i64>().ok();
let id_str = &id;
sb.atualizar_fechamento(id_i64, id_str, &updates)
} }
#[tauri::command] #[tauri::command]