save result

This commit is contained in:
OnlyPapy98
2025-12-31 10:24:22 +01:00
parent f21a5fd4e6
commit 87c33f25cf
4 changed files with 41 additions and 44 deletions

View File

@@ -37,6 +37,10 @@ export interface CourseApiResponse {
typesParisOuverts: Array<string>;
}
export interface NonApiRequest {
nonPartants: String[]
}
@Injectable({ providedIn: 'root' })
export class CourseService {
private apiUrl = environment.apiBaseUrl + API_BASE;
@@ -454,34 +458,20 @@ export class CourseService {
}
addNonPartant(courseId: string, npList: string[]) {
const payload = {
nonPartants: [...npList]
}
console.warn('addNonPartant is deprecated. Use setNonPartants instead.');
return this.setNonPartants(courseId, npList);
return this.setNonPartants(courseId, payload);
}
setNonPartants(courseId: string, npList: string[]): Observable<Course | undefined> {
if (USE_SERVER) {
// Use PUT endpoint to replace the entire list
return this.nonPartantService.replaceNonPartants(courseId, npList).pipe(
switchMap((updatedNonPartants) => {
// Fetch the updated course to return it
return this.getById(courseId).pipe(
map((course) => {
if (course) {
return {
...course,
nonPartants: updatedNonPartants,
};
}
return undefined;
})
);
}),
catchError((err) => {
console.error(`Error setting nonPartants for course ${courseId}:`, err);
return of(undefined);
})
);
}
throw new Error('Server mode is required');
setNonPartants(courseId: string, npList: NonApiRequest): Observable<CourseApiResponse | undefined> {
return this.nonPartantService.replaceNonPartants(courseId, npList).pipe(
map((updatedNonPartants) => updatedNonPartants),
catchError((err) => {
console.error(`Error setting nonPartants for course ${courseId}:`, err);
return of(undefined);
})
);
}
}