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
+12 -8
View File
@@ -153,26 +153,30 @@ export default function EditFilamentScreen(): React.ReactElement {
}
setIsLoading(true);
try {
// TODO: UpdateFilamentUseCase via container DI
const updated = {
...filament!,
const user = useAuthStore.getState().user;
if (!user) {
Alert.alert('Erro', 'Usuário não autenticado.');
return;
}
const updated = await updateFilamentUseCase.execute(filament!.id, user.id, {
brand: data.brand,
model: data.model ?? null,
colorHex: selectedColor,
material: selectedMaterial,
spoolPresetId: selectedPresetId,
totalWeightG: Number(data.totalWeightG),
netWeightG: netWeight,
tempHotendC: data.tempHotendC ?? null,
tempBedC: data.tempBedC ?? null,
flowFactorPct: data.flowFactorPct ?? null,
notes: data.notes ?? null,
updatedAt: new Date().toISOString(),
};
});
updateFilament(updated);
router.back();
} catch {
Alert.alert('Erro', 'Não foi possível salvar as alterações.');
} catch (err) {
console.error('update filament error', err);
Alert.alert('Erro', 'Falha ao atualizar: ' + (err as Error).message);
} finally {
setIsLoading(false);
}