4

I'm having a little trouble getting the correct observable type from an http.get request. Here is the function I'm having trouble on:

getMovie(title:string, year:number): Observable<Movie> {
    const params = new HttpParams()
        .set('title', title)
        .set('year', year.toString());
    return this.http.get(this.moviePath, {params})
  }

As you can see I want to receive and Observable of the class Movie from my backend api using the parameters 'title' and 'year'. The problem is that the reponse always comes back with the type Observable<Object> and not Observable<Movie>.

I'm aware that I could create a new Movie instance giving it the properties recieved from the list. The problem with that is that my movie class has properties that are optional. Here is my movie class:

export class Movie {
  title:string;
  year?:number;
  imdb?:string;
  trailer?:string;
  reviewClip?:string;
  reviewSummary?:string;
  reviewScore:number;
  createdAt?:Date;
  bestWeek:boolean;
  bestMonth:boolean;
}

Does anybody know an easy way to get the response to be of the type Observable<Movie> instead of Observable<Object>


I have come with solution after a lot R&D and googling . It is not possible in single query, we have to apply 2 query

SELECT * FROM emp LEFT JOIN salary ON salary.emp_id=emp.empno WHERE salary.sal_id IN ( SELECT MAX(salary.sal_id) FROM salary GROUP BY salary.emp_id ) GROUP BY salary.sal_id ORDER BY salary.sal_id DESC
4

2 に答える 2