-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathanalytics.service.ts
More file actions
48 lines (43 loc) · 1.7 KB
/
Copy pathanalytics.service.ts
File metadata and controls
48 lines (43 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment';
import { catchError, Observable, tap, throwError } from 'rxjs';
import { MoodAnalyticsResponse, MoodTrendsAnalysis } from '../interfaces/mood-analytics.response';
import { ApiResponse } from '../../shared/interfaces/api-response';
@Injectable({
providedIn: 'root',
})
export class AnalyticsService {
private http = inject(HttpClient);
private readonly baseUrl = `${environment.apiUrl}/api/mind/mood-tracking`;
getMoodAnalytics(months: number = 3): Observable<ApiResponse<MoodAnalyticsResponse>> {
return this.http
.get<ApiResponse<MoodAnalyticsResponse>>(
`${this.baseUrl}/user-mood/statistics?month=${months}`,
)
.pipe(
tap((response) => {
console.log('Analytics response', response);
}),
catchError((error) => {
console.error('Error al traer las estadisticas', error);
return throwError(
() =>
new Error(
'Error la obtener las estadisticas de los estados de animo',
),
);
}),
);
}
getMoodTrendsAnalysis(month: number = 3): Observable<ApiResponse<MoodTrendsAnalysis>> {
return this.http.get<ApiResponse<MoodTrendsAnalysis>>(`${this.baseUrl}/user-mood/trends-analysis?months=${month}`
).pipe(
tap((response) => console.log("Mood Trend Anlysis", response)),
catchError((error) => {
console.error("Error al traer las estadisticas", error)
return throwError(() => new Error("Error al obtener las analiticas de los estados de animo"))
})
);
}
}