Skip to content

Commit

Permalink
Merge branch 'SPSH-1654' of https://github.com/dBildungsplattform/dbi…
Browse files Browse the repository at this point in the history
…ldungs-iam-server into SPSH-1654
  • Loading branch information
YoussefBouch committed Jan 14, 2025
2 parents b3d6b30 + e16f253 commit 0dd684a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
17 changes: 12 additions & 5 deletions src/modules/person/domain/person-time-limit-info.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DoFactory } from '../../../../test/utils/do-factory.js';
import { TimeLimitOccasion } from '../domain/time-limit-occasion.enums.js';
import { Personenkontext } from '../../personenkontext/domain/personenkontext.js';
import { PersonTimeLimitInfo } from './person-time-limit-info.js';
import { KOPERS_DEADLINE_IN_DAYS } from './person-time-limit.js';
import { KOPERS_DEADLINE_IN_DAYS, NO_KONTEXTE_DEADLINE_IN_DAYS } from './person-time-limit.js';

describe('PersonTimeLimitService', () => {
let module: TestingModule;
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('PersonTimeLimitService', () => {

describe('getPersonTimeLimitInfo', () => {
it('should return PersonTimeLimitInfo array', async () => {
const person: Person<true> = DoFactory.createPerson(true);
const person: Person<true> = DoFactory.createPerson(true, { orgUnassignmentDate: new Date('2024-01-01') });
person.personalnummer = undefined;
personRepoMock.findById.mockResolvedValue(person);

Expand All @@ -58,13 +58,20 @@ describe('PersonTimeLimitService', () => {

const result: PersonTimeLimitInfo[] = await sut.getPersonTimeLimitInfo(person.id);

const expectedDeadline: Date = new Date(pesonenkontext.createdAt);
expectedDeadline.setDate(expectedDeadline.getDate() + KOPERS_DEADLINE_IN_DAYS);
const expectedKopersDeadline: Date = new Date(pesonenkontext.createdAt);
expectedKopersDeadline.setDate(expectedKopersDeadline.getDate() + KOPERS_DEADLINE_IN_DAYS);

const expectedNoKontexteDeadline: Date = new Date(person.orgUnassignmentDate!);
expectedNoKontexteDeadline.setDate(expectedNoKontexteDeadline.getDate() + NO_KONTEXTE_DEADLINE_IN_DAYS);

expect(result).toEqual<PersonTimeLimitInfo[]>([
{
occasion: TimeLimitOccasion.KOPERS,
deadline: expectedDeadline,
deadline: expectedKopersDeadline,
},
{
occasion: TimeLimitOccasion.NO_KONTEXTE,
deadline: expectedNoKontexteDeadline,
},
]);
});
Expand Down
9 changes: 8 additions & 1 deletion src/modules/person/domain/person-time-limit-info.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PersonRepository } from '../../person/persistence/person.repository.js'
import { Person } from '../../person/domain/person.js';
import { PersonTimeLimitInfo } from './person-time-limit-info.js';
import { TimeLimitOccasion } from './time-limit-occasion.enums.js';
import { KOPERS_DEADLINE_IN_DAYS } from './person-time-limit.js';
import { KOPERS_DEADLINE_IN_DAYS, NO_KONTEXTE_DEADLINE_IN_DAYS } from './person-time-limit.js';

@Injectable()
export default class PersonTimeLimitService {
Expand Down Expand Up @@ -34,6 +34,13 @@ export default class PersonTimeLimitService {
lockInfos.push(new PersonTimeLimitInfo(TimeLimitOccasion.KOPERS, kopersdeadline));
}
}

if (person.orgUnassignmentDate) {
const noKontexteDeadline: Date = new Date(person.orgUnassignmentDate);
noKontexteDeadline.setDate(noKontexteDeadline.getDate() + NO_KONTEXTE_DEADLINE_IN_DAYS);
lockInfos.push(new PersonTimeLimitInfo(TimeLimitOccasion.NO_KONTEXTE, noKontexteDeadline));
}

return lockInfos;
}
}
1 change: 1 addition & 0 deletions src/modules/person/domain/person-time-limit.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const KOPERS_DEADLINE_IN_DAYS: number = 56;
export const NO_KONTEXTE_DEADLINE_IN_DAYS: number = 84;
1 change: 1 addition & 0 deletions src/modules/person/domain/time-limit-occasion.enums.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export enum TimeLimitOccasion {
KOPERS = 'KOPERS',
NO_KONTEXTE = 'NO_KONTEXTE',
}
4 changes: 2 additions & 2 deletions src/modules/person/persistence/person.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { SystemConfig } from '../../../shared/config/system.config.js';
import { UserLock } from '../../keycloak-administration/domain/user-lock.js';
import { ClassLogger } from '../../../core/logging/class-logger.js';
import { DownstreamKeycloakError } from '../domain/person-keycloak.error.js';
import { KOPERS_DEADLINE_IN_DAYS } from '../domain/person-time-limit.js';
import { KOPERS_DEADLINE_IN_DAYS, NO_KONTEXTE_DEADLINE_IN_DAYS } from '../domain/person-time-limit.js';

/**
* Return email-address for person, if an enabled email-address exists, return it.
Expand Down Expand Up @@ -828,7 +828,7 @@ export class PersonRepository {

public async getPersonWithoutOrgDeleteList(): Promise<string[]> {
const daysAgo: Date = new Date();
daysAgo.setDate(daysAgo.getDate() - 84);
daysAgo.setDate(daysAgo.getDate() - NO_KONTEXTE_DEADLINE_IN_DAYS);

const filters: QBFilterQuery<PersonEntity> = {
personenKontexte: {
Expand Down

0 comments on commit 0dd684a

Please sign in to comment.