I call two functions from a service in my submit function saveProfileContent() to save changed data via PATCH. This operation also works. Is it possible to make the two calls a bit more abstract, efficient and flexible? Do you have any ideas? I am curious about your contributions and ideas.
My Code:
// TS
**
* To save entries in the ProfileContent
*/
saveProfileContent() {
this.submitted = true;
// Stop here if form is invalid
if (this.profileContentForm.invalid) {
return { required: true };
}
const values = this.profileContentForm.value;
console.log('Show values', values);
const successText = 'Ihre Daten wurden erfolgreich gespeichert!';
const errorText = 'Ihre Daten konnten nicht gespeichert werden!';
this.profileContentAlertType = null;
this.profileContentMessage = null;
this.userAreaService.changeUserEntries(`${values.userId}`, values).subscribe(
currentUserData => {
console.log('You change the currentUserData', currentUserData);
this.submitted = false;
if (currentUserData.success) {
this.profileContentAlertType = 'success';
this.profileContentMessage = successText;
} else {
this.profileContentAlertType = 'error';
this.profileContentMessage = errorText;
}
},
error => {
this.submitted = false;
this.profileContentAlertType = 'error';
this.profileContentMessage = errorText;
});
this.userAreaService.changeSetup(values).subscribe(
currentMandantData => {
console.log('You change the currentMandantData', currentMandantData);
this.submitted = false;
if (currentMandantData.success) {
this.profileContentAlertType = 'success';
this.profileContentMessage = successText;
} else {
this.profileContentAlertType = 'error';
this.profileContentMessage = errorText;
}
},
error => {
this.submitted = false;
this.profileContentAlertType = 'error';
this.profileContentMessage = errorText;
});
}
}
looks good to me. although depending on constraints, it seems that there's an overlapping domains: data in user entry is most likely the same as the setup.