Garmaine Staff asked 1 year ago

im newby in Java, i work in PLSQL and im trying to making a project using JHipster. I am trying to make a function that give me back the Owner from a Team, to check in angular if he is the owner, to enable some buttons in the ngInit. The repository, service and Resource is working, but i cant understand what im doing wrong in the TS file. In UserRepository.Java i have this:

@Query("select roster.team.owner from Roster roster where roster.id = ?1")
User findByRosterId(Long id);

The three Entities are roster, team and owner, there owner is the owner of the team and roster is the list of players of a Team in a Event.

In UserService.Java:

public Long checkOwner(Long id){
    return userRepository.findByRosterId(id).getId();

Where i return the 'id' of the owner.

In UserResorce.Java:

@GetMapping("/users/own/{id}")
public ResponseEntity<Long> checkOwner(@PathVariable Long id) {
        log.debug("REST request to get Owner : {}", id);
        return ResponseEntity.ok(userService.checkOwner(id));

}

In user.service.ts my script is:

findOwner(id: number): Observable<number> {
 return this.http.get<number>(`${this.resourceUrl}/own/${id}`);
}

In player.component.ts:

this.ownerId = 6;
this.userService.findOwner(this.rId)
                .subscribe((idOwn: number) => (this.ownerId = idOwn));
if (this.ownerId === 6)
{
  this.onError("Still 6");
}

Where i use this.onError to display a message in my html to check the value. The delaration of "ownerId" is number:

ownerId: number;

I run the program and i get "Still 6" message. If i check the console.log, i get this:

2020-04-10 16:56:24.748 DEBUG 14796 --- [XNIO-60 task-23] com.ar.pbpoints.web.rest.UserResource    : REST request to get Owner : 1
2020-04-10 16:56:24.748 DEBUG 14796 --- [XNIO-60 task-23] c.ar.pbpoints.aop.logging.LoggingAspect  : Enter: com.ar.pbpoints.service.UserService.checkOwner() with argument[s] = [1]
Hibernate: select user2_.id as id1_11_, user2_.created_by as created_2_11_, user2_.created_date as created_3_11_, user2_.last_modified_by as last_mod4_11_, user2_.last_modified_date as last_mod5_11_, user2_.activated as activate6_11_, user2_.activation_key as activati7_11_, user2_.email as email8_11_, user2_.first_name as first_na9_11_, user2_.image_url as image_u10_11_, user2_.lang_key as lang_ke11_11_, user2_.last_name as last_na12_11_, user2_.login as login13_11_, user2_.password_hash as passwor14_11_, user2_.reset_date as reset_d15_11_, user2_.reset_key as reset_k16_11_ from roster roster0_ cross join team team1_ inner join jhi_user user2_ on team1_.owner_id=user2_.id where roster0_.team_id=team1_.id and roster0_.id=?
2020-04-10 16:56:24.753 DEBUG 14796 --- [XNIO-60 task-23] c.ar.pbpoints.aop.logging.LoggingAspect  : Exit: com.ar.pbpoints.service.UserService.checkOwner() with result = 5
2020-04-10 16:56:24.753 DEBUG 14796 --- [XNIO-60 task-23] c.ar.pbpoints.aop.logging.LoggingAspect  : Exit: com.ar.pbpoints.web.rest.UserResource.checkOwner() with result = <200 OK OK,5,[]>

where 1 is the rosterId that im sending to the function, and 5 is the id of the owner. I think im wrong in user.service.ts or player.component.ts, but i cant find the error.

Any help is appreciated! Thanks!