Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fallback to Email for study class students #712 #767

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ describe("EventsStudentsStateService", () => {
"getSummaries",
]);
personsServiceMock.getSummaries.and.callFake((ids) =>
of(students.filter((s) => ids.includes(s.Id))),
of(
students
.filter((s) => ids.includes(s.Id))
.map((s) => ({ ...s, Email: null })),
),
);
return personsServiceMock;
},
Expand Down
1 change: 1 addition & 0 deletions src/app/events/services/events-students-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export class EventsStudentsStateService {
eventId,
persons,
subscriptions,
{ emailFallback: true },
);
return decorateCourseStudentsWithCompanies(students, contracts);
}),
Expand Down
8 changes: 7 additions & 1 deletion src/app/events/utils/events-students.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function convertPersonsToStudentEntries(
eventId: number,
persons: ReadonlyArray<PersonSummary>,
subscriptions: ReadonlyArray<Subscription>,
{ emailFallback }: { emailFallback?: boolean } = {},
): StudentEntries {
return {
eventId: eventId,
Expand All @@ -74,7 +75,12 @@ export function convertPersonsToStudentEntries(
({
id: person.Id,
name: person.FullName,
email: person.DisplayEmail ?? undefined,
email:
// Due to a backend bug where `DisplayEmail` is null for study class
// students, we have to fallback to `Email` as a workaround.
(emailFallback
? (person.DisplayEmail ?? person.Email)
: person.DisplayEmail) ?? undefined,
status: subscriptions.find((s) => s.PersonId === person.Id)?.Status,
}) satisfies StudentEntry,
),
Expand Down
3 changes: 2 additions & 1 deletion src/app/shared/models/person.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ const Person = t.type({

const PersonSummary = t.type({
Id: t.number,
DisplayEmail: Option(t.string),
FullName: t.string,
DisplayEmail: Option(t.string),
Email: Maybe(t.string),
});

type Person = t.TypeOf<typeof Person>;
Expand Down
5 changes: 3 additions & 2 deletions src/app/shared/services/persons-rest.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ describe("PersonsRestService", () => {
const personSummaries: ReadonlyArray<PersonSummary> = [
buildPersonSummary(54425),
buildPersonSummary(56200),
].map(({ Id, FullName, DisplayEmail }) => ({
].map(({ Id, FullName, DisplayEmail, Email }) => ({
Id,
FullName,
DisplayEmail,
Email,
}));

service.getSummaries([54425, 56200]).subscribe((result) => {
Expand All @@ -51,7 +52,7 @@ describe("PersonsRestService", () => {

httpTestingController
.expectOne(
"https://eventotest.api/Persons/?filter.Id=;54425;56200&fields=Id,FullName,DisplayEmail",
"https://eventotest.api/Persons/?filter.Id=;54425;56200&fields=Id,FullName,DisplayEmail,Email",
)
.flush(personSummaries);
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/services/persons-rest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class PersonsRestService extends RestService<typeof Person> {
.get<unknown>(`${this.baseUrl}/`, {
params: {
"filter.Id": `;${ids.join(";")}`,
fields: ["Id", "FullName", "DisplayEmail"].join(","),
fields: ["Id", "FullName", "DisplayEmail", "Email"].join(","),
},
})
.pipe(switchMap(decodeArray(PersonSummary)));
Expand Down
3 changes: 2 additions & 1 deletion src/spec-builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,9 @@ export function buildStudent(id: number): Student {
export function buildPersonSummary(id: number): PersonSummary {
return {
Id: id,
DisplayEmail: null,
FullName: "Tux",
DisplayEmail: null,
Email: null,
};
}

Expand Down
Loading