ARTICLE AD BOX
Angular service methods:
getDetails<T>(date: string) Observable<typeA<T>> { return this.myService.getMyDetails(date); } getFullYearDetails(id: number, year: number): Observable(typeB>{ return this.myService.getYearData(id, year); }First method returns:
{ records [ { id: 28, somemoredata: [{a: 123, b: 12345}], totalOfSomething: 2000 }, { id: 32, somemoredata: [{a: 345, b: 26435}], totalOfSomething: 3000 } ]}Second method result:
{ id: 28, year: 2026, months: [ {id: 1, total: 1000]}, {id: 2, total: 1500]} }If I call getDetails, I want to return expected / same result, but the total must be the one that is from a specific month. (Example id: 28 and month: 2)
{id: 28, somemoredata: [{a: 123, b: 12345}], totalOfsomething: 1500}I altered my code to (I use date-fns and my input for the date is '02-2026'):
getDetails<T>(date: string) Observable<typeA<T>> { const month = getMonth(parse(date, 'MM-yyyy', new date())); // result 1 const month = getYear(parse(date, 'MM-yyyy', new date())); // result 2026 this.myService.getMydetails(date).pipe( switchMap(details =>({ return this.myService.getFullYearDetails(details.records[0].id, year).pipe( map(yeardata => ({ ...details, }) ) }) ) // return this.myService.getMyDetails(date); }The service method getdetails is called from another file component and is expecting an observable object.
I added records[0].totalOfsomething : yeardata.months[1].total, but this does not work.
How can I return the desired result?
