save result
This commit is contained in:
@@ -37,6 +37,10 @@ export interface CourseApiResponse {
|
|||||||
typesParisOuverts: Array<string>;
|
typesParisOuverts: Array<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface NonApiRequest {
|
||||||
|
nonPartants: String[]
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class CourseService {
|
export class CourseService {
|
||||||
private apiUrl = environment.apiBaseUrl + API_BASE;
|
private apiUrl = environment.apiBaseUrl + API_BASE;
|
||||||
@@ -454,34 +458,20 @@ export class CourseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addNonPartant(courseId: string, npList: string[]) {
|
addNonPartant(courseId: string, npList: string[]) {
|
||||||
|
const payload = {
|
||||||
|
nonPartants: [...npList]
|
||||||
|
}
|
||||||
console.warn('addNonPartant is deprecated. Use setNonPartants instead.');
|
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> {
|
setNonPartants(courseId: string, npList: NonApiRequest): Observable<CourseApiResponse | undefined> {
|
||||||
if (USE_SERVER) {
|
return this.nonPartantService.replaceNonPartants(courseId, npList).pipe(
|
||||||
// Use PUT endpoint to replace the entire list
|
map((updatedNonPartants) => updatedNonPartants),
|
||||||
return this.nonPartantService.replaceNonPartants(courseId, npList).pipe(
|
catchError((err) => {
|
||||||
switchMap((updatedNonPartants) => {
|
console.error(`Error setting nonPartants for course ${courseId}:`, err);
|
||||||
// Fetch the updated course to return it
|
return of(undefined);
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { HttpClient } from '@angular/common/http';
|
|||||||
import { Observable, of } from 'rxjs';
|
import { Observable, of } from 'rxjs';
|
||||||
import { map, catchError } from 'rxjs/operators';
|
import { map, catchError } from 'rxjs/operators';
|
||||||
import { environment } from 'src/environments/environment.development';
|
import { environment } from 'src/environments/environment.development';
|
||||||
|
import { CourseApiResponse, NonApiRequest } from './course';
|
||||||
|
|
||||||
const USE_SERVER = true;
|
const USE_SERVER = true;
|
||||||
|
|
||||||
@@ -20,21 +21,22 @@ export class NonPartantService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PUT /api/v1/courses/{courseId}/non-partants - Replace the list of non-partants for a course
|
// PUT /api/v1/courses/{courseId}/non-partants - Replace the list of non-partants for a course
|
||||||
replaceNonPartants(courseId: string, nonPartants: string[]): Observable<string[]> {
|
replaceNonPartants(courseId: string, nonPartants: NonApiRequest): Observable<CourseApiResponse | undefined> {
|
||||||
if (USE_SERVER) {
|
const courseApiUrl = environment.apiBaseUrl + '/api/courses';
|
||||||
const courseApiUrl = environment.apiBaseUrl + '/api/v1/courses';
|
return this.http
|
||||||
return this.http
|
.patch<CourseApiResponse>(`${courseApiUrl}/${courseId}/non-partants`, nonPartants, {
|
||||||
.put<string[]>(`${courseApiUrl}/${courseId}/non-partants`, nonPartants, {
|
headers: this.getNgrokHeaders(),
|
||||||
headers: this.getNgrokHeaders(),
|
})
|
||||||
|
.pipe(
|
||||||
|
map((res) => {
|
||||||
|
|
||||||
|
return res
|
||||||
|
}),
|
||||||
|
catchError((err) => {
|
||||||
|
console.log(err);
|
||||||
|
console.error(`Error replacing non-partants for course ${courseId}:`, err);
|
||||||
|
return of(undefined);
|
||||||
})
|
})
|
||||||
.pipe(
|
);
|
||||||
map((list) => list.map((np) => String(np))),
|
|
||||||
catchError((err) => {
|
|
||||||
console.error(`Error replacing non-partants for course ${courseId}:`, err);
|
|
||||||
return of([]);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return of([]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { ZardCardComponent } from '@shared/components/card/card.component';
|
|||||||
import { ZardButtonComponent } from '@shared/components/button/button.component';
|
import { ZardButtonComponent } from '@shared/components/button/button.component';
|
||||||
import { CourseStatut, Course as CourseType } from 'src/app/core/interfaces/course';
|
import { CourseStatut, Course as CourseType } from 'src/app/core/interfaces/course';
|
||||||
import { SortDir } from '@shared/paging/paging';
|
import { SortDir } from '@shared/paging/paging';
|
||||||
import { CourseApiResponse, CourseService } from 'src/app/core/services/course';
|
import { CourseApiResponse, CourseService, NonApiRequest } from 'src/app/core/services/course';
|
||||||
import { ResultatService } from 'src/app/core/services/resultat';
|
import { ResultatService } from 'src/app/core/services/resultat';
|
||||||
import { Resultat, ResultatStatut } from 'src/app/core/interfaces/resultat';
|
import { Resultat, ResultatStatut } from 'src/app/core/interfaces/resultat';
|
||||||
import { A11yModule } from '@angular/cdk/a11y';
|
import { A11yModule } from '@angular/cdk/a11y';
|
||||||
@@ -347,8 +347,13 @@ export class Course {
|
|||||||
onNonPartantSave(payload: string[]) {
|
onNonPartantSave(payload: string[]) {
|
||||||
const course = this.selectedCourse();
|
const course = this.selectedCourse();
|
||||||
if (!course) return;
|
if (!course) return;
|
||||||
|
const reqPayload = {
|
||||||
|
nonPartants: [
|
||||||
|
...payload
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
this.api.setNonPartants(course.id, payload).subscribe({
|
this.api.setNonPartants(course.id, reqPayload).subscribe({
|
||||||
next: (updatedCourse) => {
|
next: (updatedCourse) => {
|
||||||
if (updatedCourse) {
|
if (updatedCourse) {
|
||||||
toast.success('Non-partants mis à jour avec succès');
|
toast.success('Non-partants mis à jour avec succès');
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
apiBaseUrl: 'http://192.168.1.235:8383',
|
apiBaseUrl: 'http://192.168.1.235:8381',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user