feat: add authentication check before updating filament and improve error handling

This commit is contained in:
2026-03-14 15:33:53 -03:00
parent d1eabfb690
commit 9ac83ad823
2 changed files with 13 additions and 8 deletions
+1
View File
@@ -0,0 +1 @@
mobile/.env.production
+12 -8
View File
@@ -153,26 +153,30 @@ export default function EditFilamentScreen(): React.ReactElement {
} }
setIsLoading(true); setIsLoading(true);
try { try {
// TODO: UpdateFilamentUseCase via container DI const user = useAuthStore.getState().user;
const updated = { if (!user) {
...filament!, Alert.alert('Erro', 'Usuário não autenticado.');
return;
}
const updated = await updateFilamentUseCase.execute(filament!.id, user.id, {
brand: data.brand, brand: data.brand,
model: data.model ?? null, model: data.model ?? null,
colorHex: selectedColor, colorHex: selectedColor,
material: selectedMaterial, material: selectedMaterial,
spoolPresetId: selectedPresetId, spoolPresetId: selectedPresetId,
totalWeightG: Number(data.totalWeightG), totalWeightG: Number(data.totalWeightG),
netWeightG: netWeight,
tempHotendC: data.tempHotendC ?? null, tempHotendC: data.tempHotendC ?? null,
tempBedC: data.tempBedC ?? null, tempBedC: data.tempBedC ?? null,
flowFactorPct: data.flowFactorPct ?? null, flowFactorPct: data.flowFactorPct ?? null,
notes: data.notes ?? null, notes: data.notes ?? null,
updatedAt: new Date().toISOString(), });
};
updateFilament(updated); updateFilament(updated);
router.back(); router.back();
} catch { } catch (err) {
Alert.alert('Erro', 'Não foi possível salvar as alterações.'); console.error('update filament error', err);
Alert.alert('Erro', 'Falha ao atualizar: ' + (err as Error).message);
} finally { } finally {
setIsLoading(false); setIsLoading(false);
} }