My goal is to develop a service that assists individuals in making informed decisions. To achieve this, I must guide users through an onboarding process where they create entities that reflect their circumstances.
During data input, I aim to establish links between these entities and also connect them to the user.
In my quest to facilitate this, I explored the following resources:
Jhipster extented user entity and account creation
JHipster : Registering a user with additional information
Although these resources didn't address my specific inquiry, my approach aligns with their methodology.
I have devised a user metadata object and linked it to the Jhipster user entity through JDL. Now, my focus is on retrieving the logged in user to establish a reference between the user and the entities they generate.
I've made considerable progress and have utilized insights from the JHipster source code.
Within a component method, several questions arise:
company: Company;
project: Project;
team: Team;
account: Account;
user: User;
userMetadata: UserMetadata;
linkEntities() {
// Question 1: Am I approaching this correctly?
// Identify the logged-in account, to which the user is associated
this.accountService.identity().then(account => {
this.account = account;
});
// Retrieve the user linked to that account
this.userService.find(this.account.login)
.subscribe(res => this.user = res.body);
// Fetch the metadata
this.userMetadataService.find(this.user.id)
.subscribe(res => this.userMetadata = res.body);
// Question 2: Why are these values undefined?
// Is there a glaring oversight that could explain this?
console.log(this.account);
console.log(this.user);
console.log(this.userMetadata);
// The company, project, and team entities have already been created and submitted in a previous function. Here, I update them with mutual references.
this.company.employees.push(currentlyLoggedInUserMetadata)
this.project.participants.push(currentlyLoggedInUserMetadata)
this.team.members.push(currentlyLoggedInUserMetadata)
this.company.teamOwners.push(this.team);
this.company.companyProjects.push(this.project);
this.project.implementingTeams.push(this.team);
this.project.parentCompany = this.company;
this.team.parentCompany = this.company;
this.team.teamProjects.push(this.project);
// Proceed to send the updated entities to the API
this.subscribeToCompanySaveResponse(this.companyService.update(this.company));
this.subscribeToProjectSaveResponse(this.projectService.update(this.project));
this.subscribeToTeamSaveResponse(this.teamService.update(this.team));
}
I'm perplexed about the errors in the three console logs above. I just assigned these values before the logs. As a newcomer to RxJS, could there be a quirk in how observables function causing this?
It would be ideal to have a globally accessible value for the logged-in user stored within the user service (the account service holds a private account instance, but lacks user - should I expose the account publicly as a default private value?)
I'm uncertain about the optimal or most 'JHipster' method to obtain the one-to-one linked user <--> userMetadata object for the presently logged in user.
Moreover, I'm aware that this method is quite extensive and attempts to accomplish multiple tasks. Once I confirm its functionality, I plan to refactor it for better manageability.
If anyone can offer advice on this approach, has undertaken a similar task, or can shed light on why the account and user variables, in particular, are undefined (I performed the method while logged in as admin), your insights would be greatly appreciated!
Thank you in advance for any guidance and time you can provide!