• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

How to get a Long Value from a Backend function and catch in a service.ts?

April 10, 2020 by

Questions › How to get a Long Value from a Backend function and catch in a service.ts?
0
Vote Up
Vote Down
Garmaine asked 4 years 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!

Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: angular, javascript, long-integer, subscribe, typescript

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements best Business strategies commercial convenience economic Finances Cognitive decline Financial growth firm Future Hidden Gems Home hydration Impact Innovations lighting line of work Mental health Must-See New York City office patronage Productivity profession Profitability tips Profit optimization pursuit recreation Revenue enhancement romance sippy cups social station Technological breakthroughs technology toddlers trading transaction Treasures Uncover undertaking Well-being Wonders Work Young onset dementia

Copyright © 2023