Skip to content

Commit

Permalink
Only load legal repr. & apprent. contracts for students #727
Browse files Browse the repository at this point in the history
  • Loading branch information
hupf committed Dec 9, 2024
1 parent 44b0594 commit 3f88629
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
33 changes: 32 additions & 1 deletion src/app/shared/services/student-profile.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { ApprenticeshipManager } from "../models/apprenticeship-manager.model";
import { DropDownItem } from "../models/drop-down-item.model";
import { JobTrainer } from "../models/job-trainer.model";
import { StorageService } from "./storage.service";

describe("StudentProfileService", () => {
let httpTestingController: HttpTestingController;
Expand All @@ -37,9 +38,25 @@ describe("StudentProfileService", () => {
let legalRepresentative2: Person;
let persons: Person[];
let dropDownItems: DropDownItem[];
let roles: string;

beforeEach(() => {
TestBed.configureTestingModule(buildTestModuleMetadata({}));
roles = "StudentRole";

TestBed.configureTestingModule(
buildTestModuleMetadata({
providers: [
{
provide: StorageService,
useValue: {
getPayload: () => ({
roles,
}),
},
},
],
}),
);
httpTestingController = TestBed.inject(HttpTestingController);
service = TestBed.inject(StudentProfileService);

Expand Down Expand Up @@ -229,6 +246,20 @@ describe("StudentProfileService", () => {
expectJobTrainerRequest(apprenticeshipContract.JobTrainer);
}
});

it("does not load legal representatives & apprenticeship contracts for non-student", () => {
roles = "TeacherRole";
service.getMyProfile().subscribe((result: Profile<Person>) => {
expect(result).toEqual({
student: myself,
stayPermitValue: "Permit Value",
legalRepresentativePersons: [],
apprenticeshipCompanies: [],
});
});
expectMyPersonRequest();
expectLoadStayPermitValueRequest();
});
});

function expectStudentRequest(id: number, response = student): void {
Expand Down
8 changes: 6 additions & 2 deletions src/app/shared/services/student-profile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { RestErrorInterceptorOptions } from "../interceptors/rest-error.intercep
import { notNull } from "../utils/filter";
import { isAdult } from "../utils/persons";
import { DropDownItemsRestService } from "./drop-down-items-rest.service";
import { StorageService } from "./storage.service";

export interface Profile<T extends Student | Person> {
student: T;
Expand Down Expand Up @@ -46,6 +47,7 @@ export class StudentProfileService {
private jobTrainersService: JobTrainersRestService,
private loadingService: LoadingService,
private dropDownItemsService: DropDownItemsRestService,
private storageService: StorageService,
) {}

/**
Expand All @@ -65,6 +67,8 @@ export class StudentProfileService {
* Returns the profile of the current user.
*/
getMyProfile(): Observable<Profile<Person>> {
const roles = this.storageService.getPayload()?.roles?.split(";") ?? [];
const isStudent = roles.includes("StudentRole");
return this.loadingService.load(
this.personsService
.getMyself({
Expand All @@ -76,8 +80,8 @@ export class StudentProfileService {
switchMap((person) =>
combineLatest([
of(person),
this.loadLegalRepresentatives(person.Id),
this.loadApprenticeshipContracts(person.Id),
isStudent ? this.loadLegalRepresentatives(person.Id) : of([]),
isStudent ? this.loadApprenticeshipContracts(person.Id) : of([]),
this.loadStayPermitValue(person.StayPermit),
]),
),
Expand Down

0 comments on commit 3f88629

Please sign in to comment.