Skip to content

Commit

Permalink
317: limit absences to current students
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon Spahr committed Jul 29, 2021
1 parent b191512 commit 8bc1cab
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ describe('PresenceControlStateService', () => {
)
)
);
expectLoadOtherTeachersAbsencesRequest([], person.Id, [66]);

resetCallbackSpies();

service.updateLessonPresencesTypes([
Expand All @@ -273,6 +275,8 @@ describe('PresenceControlStateService', () => {
expect(entries[0].lessonPresence.Type).toBe('Abwesend');
expect(entries[0].presenceType).toBe(absent);

expectLoadOtherTeachersAbsencesRequest([], person.Id, [66]);

expectCstRequest();
});
});
Expand Down Expand Up @@ -353,9 +357,13 @@ describe('PresenceControlStateService', () => {

function expectLoadOtherTeachersAbsencesRequest(
response = otherAbsences,
personId: number
personId: number,
students?: number[]
): void {
const url = `https://eventotest.api/LessonTeachers/except/${personId}/LessonAbsences?expand=LessonRef`;
let url = `https://eventotest.api/LessonTeachers/except/${personId}/LessonAbsences?expand=LessonRef`;
if (students && students.length > 0) {
url = url.concat('&filter.StudentRef=;', students.join(';'));
}
httpTestingController
.expectOne(url)
.flush(t.array(LessonAbsence).encode(response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
takeUntil,
mergeAll,
filter,
startWith,
} from 'rxjs/operators';
import { isEqual, uniq } from 'lodash-es';
import { format } from 'date-fns';
Expand Down Expand Up @@ -110,9 +111,26 @@ export class PresenceControlStateService
.getAbsenceConfirmationStates()
.pipe(shareReplay(1));

otherTeachersAbsences$ = this.personsService.getMyself().pipe(
switchMap((person) =>
this.lessonTeacherService.loadOtherTeachersLessonAbsences(person.Id)
selectedLessonStudentIds$ = combineLatest([
this.selectLesson$,
this.lessonPresences$,
]).pipe(
map(([lesson, presences]) => {
return presences.filter((i) => i.LessonRef.Id === Number(lesson?.id));
}),
map((p) => p.map((i) => i.StudentRef.Id)),
shareReplay(1)
);

otherTeachersAbsences$ = combineLatest([
this.personsService.getMyself(),
this.selectedLessonStudentIds$.pipe(startWith([])),
]).pipe(
switchMap(([person, students]) =>
this.lessonTeacherService.loadOtherTeachersLessonAbsences(
person.Id,
students
)
),
shareReplay(1)
);
Expand Down
12 changes: 7 additions & 5 deletions src/app/shared/services/lesson-teachers-rest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ export class LessonTeachersRestService extends RestService<
}

/**
* Returns all lesson absences for all teachers expect for the given teacher
* Returns all lesson absences for all teachers expect for the given teacher for the current lesson corresponding students
*/
loadOtherTeachersLessonAbsences(
personId: number,
students: number[],
params?: HttpParams | Dict<string>
): Observable<ReadonlyArray<LessonAbsence>> {
let url = `${this.baseUrl}/except/${personId}/LessonAbsences?expand=LessonRef`;
if (students && students.length > 0) {
url = url.concat('&filter.StudentRef=;' + students.join(';'));
}
return this.http
.get<unknown>(
`${this.baseUrl}/except/${personId}/LessonAbsences?expand=LessonRef`,
{ params }
)
.get<unknown>(url, { params })
.pipe(switchMap(decodeArray(LessonAbsence)));
}
}

0 comments on commit 8bc1cab

Please sign in to comment.