As a newcomer to Angular development, I'm curious if there's a more elegant way to streamline the repetitive code shown below.
addTransaccion() {
try {
if (this.idTransaccion === '0') {
this.transaccionesSrv.addTransaccion(data)
.then(res => {
if (res) {
this.router.navigate(['/cuentas/transacciones'], { queryParamsHandling: "preserve" });
}
});
} else {
this.transaccionesSrv.actualizarTransaccion(data, this.idTransaccion)
.then(res => {
if (res) {
this.router.navigate(['/cuentas/transacciones'], { queryParamsHandling: "preserve" });
}
});
}
} catch (error) {
this.envioFormularioOk = false;
}
}