I save the profile and once the request would be sucess I make another request to create a payment. Right now the code lookes like this
this.profileService.saveProfile(dataProfile).pipe(
catchError(e => of(null))
).subscribe(res => {
if (res) { // if user saved profile data
const data = {
params: {
user: {
surname: this.formInfo.get('surname').value,
name: this.formInfo.get('name').value,
father_name: this.formInfo.get('father_name').value,
iin: this.formInfo.get('iin').value,
},
tariff: obj ? {
months: obj.Months,
amount: obj.Amount,
amountByMonth: obj.AmountByMonth
} : null,
}
this.buyService.create(data).pipe( ...
}
What is the best way to make this code be better ? I have read about concatMap operator in RXjs but this is related to array of Observables , here I have only one response if user saved own data or not.
Also how should I handle loading variable here for each request spearately?