detail on course

This commit is contained in:
OnlyPapy98
2025-12-31 14:53:40 +01:00
parent 87c33f25cf
commit afa5fab55d
17 changed files with 462 additions and 41 deletions

View File

@@ -0,0 +1,41 @@
import { Course, CourseType } from "./course";
export type TypeFormule =
| 'UNITAIRE'
| 'CHAMP_X'
| 'CHAMP_TOTAL'
| 'FORMULE_COMPLETE';
export interface RapportDetail {
id: number;
libelle: string;
rapport: number;
nombreGagnants: number;
massePartageeRang: number;
gainsFormule: string;
}
export interface Formule {
id: number;
gains: string;
typePari: CourseType;
typeFormule: TypeFormule;
masseInitiale: number;
masseApresPrelevements: number;
masseFinale: number;
totalPari: number;
totalGagnants: number;
rapportsDetails: RapportDetail[];
}
export interface ResultatCagnotte {
id: number;
course: Course;
montantCagnotte: number;
montantARembourser: number;
dateCalcul: string;
formules: Formule[];
}

View File

@@ -157,7 +157,6 @@ export class CourseService {
}
getById(id: string): Observable<Course | undefined> {
if (USE_SERVER) {
return this.http
.get<CourseApiResponse>(`${this.apiUrl}/${id}`, { headers: this.getNgrokHeaders() })
.pipe(
@@ -165,9 +164,6 @@ export class CourseService {
// Fetch the reunion (non-partants are already included in the API response)
return this.hippodromeService.getById(String(apiCourse.hippodromeId)).pipe(
map((hippodrome) => {
if (!hippodrome) {
return undefined;
}
return {
id: String(apiCourse.id),
hippodrome: hippodrome ?? undefined,
@@ -196,8 +192,6 @@ export class CourseService {
return of(undefined);
})
);
}
return of(undefined);
}
// getByReunionId(reunionId: string): Observable<Course[]> {

View File

@@ -8,15 +8,10 @@ import { environment } from 'src/environments/environment.development';
export interface ResultatCourse {
id: number;
course: Course;
course: Partial<Course>;
statut: ResultatStatut;
ordreArrivee: string;
datePublication?: string; // ISO string
dateValidation?: string; // ISO string
dateAnnulation?: string; // ISO string
notes?: string;
createdAt?: string;
updatedAt?: string;
datePublication?: string;
}
const API_BASE = '/api/v1/depouillement';

View File

@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { Gain } from './gain';
describe('Gain', () => {
let service: Gain;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(Gain);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,107 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { map, catchError, switchMap } from 'rxjs/operators';
import { ResultatCagnotte, Formule } from '../interfaces/gain';
import { normalizePage } from '@shared/paging/normalize-page';
import { PaginatedHttpService } from '@shared/paging/paginated-http.service';
import { ListParams, PagedResult } from '@shared/paging/paging';
import { environment } from 'src/environments/environment.development';
import { ServicesUtils } from './services-utils';
const USE_SERVER = true;
const API_BASE = '/api/v1/gains';
export interface ResultatCagnotteApi extends ResultatCagnotte {}
@Injectable({
providedIn: 'root',
})
export class Gain {
private apiUrl = environment.depouillementBaseUrl + API_BASE;
constructor(private http: HttpClient, private pager: PaginatedHttpService, private servicesUtil: ServicesUtils) {}
private getNgrokHeaders(): Record<string, string> {
const isNgrok =
environment.apiBaseUrl.includes('ngrok-free.app') ||
environment.apiBaseUrl.includes('ngrok.io') ||
environment.apiBaseUrl.includes('ngrok');
return isNgrok ? { 'ngrok-skip-browser-warning': 'true' } : {};
}
// List (paginated) ResultatCagnotte
list(params: ListParams): Observable<PagedResult<ResultatCagnotte>> {
if (USE_SERVER) {
const url = this.apiUrl;
return this.pager.fetch<ResultatCagnotteApi>(url, params).pipe(
map((res) => {
const content = (res.content ?? []).map((api) => api as ResultatCagnotte);
return {
pageable: res.pageable,
totalPages: res.totalPages,
totalElements: res.totalElements,
content,
} as PagedResult<ResultatCagnotte>;
}),
catchError((err) => {
console.error('Error fetching gains list:', err);
return of({ content: [], pageable: { pageNumber: 1, pageSize: 0, total: 0 }, totalPages: 1, totalElements: 0 } as PagedResult<ResultatCagnotte>);
})
);
}
return of({ content: [], pageable: { pageNumber: 1, pageSize: 0, total: 0 }, totalPages: 1, totalElements: 0 } as PagedResult<ResultatCagnotte>);
}
getById(id: string): Observable<ResultatCagnotte | undefined> {
if (USE_SERVER) {
return this.http.get<ResultatCagnotteApi>(`${this.apiUrl}/rapport/${id}`, { headers: this.getNgrokHeaders() }).pipe(
map((api) => api as ResultatCagnotte),
catchError((err) => {
console.error(`Error fetching gain ${id}:`, err);
return of(undefined);
})
);
}
return of(undefined);
}
create(payload: Partial<ResultatCagnotteApi>): Observable<ResultatCagnotte> {
if (USE_SERVER) {
return this.http.post<ResultatCagnotteApi>(this.apiUrl, payload, { headers: this.getNgrokHeaders() }).pipe(
map((api) => api as ResultatCagnotte),
catchError((err) => {
console.error('Error creating gain:', err);
throw err;
})
);
}
throw new Error('Server mode required');
}
update(id: string, payload: Partial<ResultatCagnotteApi>): Observable<ResultatCagnotte | undefined> {
if (USE_SERVER) {
return this.http.put<ResultatCagnotteApi>(`${this.apiUrl}/${id}`, payload, { headers: this.getNgrokHeaders() }).pipe(
map((api) => api as ResultatCagnotte),
catchError((err) => {
console.error(`Error updating gain ${id}:`, err);
return of(undefined);
})
);
}
return of(undefined);
}
delete(id: string): Observable<void> {
if (USE_SERVER) {
return this.http.delete<void>(`${this.apiUrl}/${id}`, { headers: this.getNgrokHeaders() }).pipe(
catchError((err) => {
console.error(`Error deleting gain ${id}:`, err);
throw err;
})
);
}
return of(void 0);
}
}