Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 60ec60bf29 | |||
| 6d9e28a6f2 |
@@ -247,12 +247,14 @@ impl SupabaseClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Atualiza campos específicos de um fechamento pelo id numérico (PATCH).
|
||||
pub fn atualizar_fechamento(&self, id: i64, updates: &serde_json::Value) -> Result<Value, SupabaseError> {
|
||||
let url = format!(
|
||||
"{}/rest/v1/fechamentos_web?id=eq.{}",
|
||||
self.base_url, id
|
||||
);
|
||||
/// Atualiza campos específicos de um fechamento pelo id numérico (pk) ou UUID.
|
||||
pub fn atualizar_fechamento(&self, id: Option<i64>, uuid: &str, updates: &serde_json::Value) -> Result<Value, SupabaseError> {
|
||||
// Se temos id numerico, usa id=eq.; senao usa id=eq.UUID
|
||||
let url = if let Some(num) = 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
|
||||
.http
|
||||
@@ -262,7 +264,7 @@ impl SupabaseClient {
|
||||
.send()?;
|
||||
|
||||
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 {
|
||||
let status = resp.status();
|
||||
let body = resp.text().unwrap_or_default();
|
||||
@@ -462,10 +464,13 @@ pub fn sb_buscar_por_id_fechamento(
|
||||
#[tauri::command]
|
||||
pub fn sb_atualizar_fechamento(
|
||||
sb: State<'_, SupabaseClient>,
|
||||
id: i64,
|
||||
id: String,
|
||||
updates: serde_json::Value,
|
||||
) -> 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]
|
||||
|
||||
+3
-1
@@ -2197,7 +2197,9 @@ window.openConsultaRegistro = async function(idx) {
|
||||
|
||||
if (!full) { alert('Registro não encontrado.'); return; }
|
||||
|
||||
// Preserva o id numerico (pk da tabela) antes de guardar o registro completo
|
||||
window._currentConsulta = full;
|
||||
window._currentConsultaId = item.id;
|
||||
buildRelatorioModal(full);
|
||||
};
|
||||
|
||||
@@ -2425,7 +2427,7 @@ window.salvarEdicaoConsulta = async function() {
|
||||
if (!hasTauri) { alert('Tauri não disponível.'); return; }
|
||||
|
||||
try {
|
||||
const id = full.id;
|
||||
const id = window._currentConsultaId;
|
||||
if (!id) { alert('ID do registro não encontrado. Não é possível atualizar.'); return; }
|
||||
|
||||
await window.__TAURI__.core.invoke('sb_atualizar_fechamento', { id, updates });
|
||||
|
||||
Reference in New Issue
Block a user