Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tikle-cap committed Dec 9, 2024
1 parent ea8b059 commit 239bf42
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import { RolleRepo } from '../../rolle/repo/rolle.repo.js';
import { OrganisationRepository } from '../../organisation/persistence/organisation.repository.js';
import { KeycloakConfig } from '../../../shared/config/keycloak.config.js';
import { KeycloakUserService } from '../../keycloak-administration/index.js';
import PersonTimeLimitService from '../services/person-time-limit-info.service.js';
import { TimeLimitOccasion } from '../domain/time-limit-occasion.enums.js';
import { TimeLimitOccasion } from '../../person/domain/time-limit-occasion.enums.js';
import PersonTimeLimitService from '../../person/domain/person-time-limit-info.service.js';

describe('AuthenticationController', () => {
let module: TestingModule;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/authentication/api/authentication.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import { AuthenticationExceptionFilter } from './authentication-exception-filter
import { KeycloakUserService } from '../../keycloak-administration/index.js';
import { DomainError } from '../../../shared/error/domain.error.js';
import { getLowestStepUpLevel } from '../passport/oidc.strategy.js';
import PersonTimeLimitService from '../services/person-time-limit-info.service.js';
import { PersonTimeLimitInfo } from '../domain/person-time-limit-info.js';
import { PersonTimeLimitInfo } from '../../person/domain/person-time-limit-info.js';
import { PersonTimeLimitInfoResponse } from './person-time-limit-info.reponse.js';
import PersonTimeLimitService from '../../person/domain/person-time-limit-info.service.js';

@UseFilters(new AuthenticationExceptionFilter())
@ApiTags('auth')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { TimeLimitOccasion } from '../domain/time-limit-occasion.enums.js';
import { TimeLimitOccasion } from '../../person/domain/time-limit-occasion.enums.js';

export class PersonTimeLimitInfoResponse {
@ApiProperty({ nullable: true })
Expand Down
2 changes: 1 addition & 1 deletion src/modules/authentication/api/userinfo.response.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PersonenkontextRolleFieldsResponse } from './personen-kontext-rolle-fie
import { createMock } from '@golevelup/ts-jest';
import { StepUpLevel } from '../passport/oidc.strategy.js';
import { PersonTimeLimitInfoResponse } from './person-time-limit-info.reponse.js';
import { TimeLimitOccasion } from '../domain/time-limit-occasion.enums.js';
import { TimeLimitOccasion } from '../../person/domain/time-limit-occasion.enums.js';

describe('UserinfoResponse', () => {
const permissions: PersonPermissions = new PersonPermissions(
Expand Down
2 changes: 1 addition & 1 deletion src/modules/authentication/authentication-api.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { JwtStrategy } from './passport/jwt.strategy.js';
import { OrganisationModule } from '../organisation/organisation.module.js';
import { RolleModule } from '../rolle/rolle.module.js';
import { KeycloakAdministrationModule } from '../keycloak-administration/keycloak-administration.module.js';
import PersonTimeLimitService from './services/person-time-limit-info.service.js';
import PersonTimeLimitService from '../person/domain/person-time-limit-info.service.js';

@Module({
imports: [
Expand Down
3 changes: 2 additions & 1 deletion src/modules/person/api/person.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import { PersonEmailResponse } from './person-email-response.js';
import { UserLock } from '../../keycloak-administration/domain/user-lock.js';
import { StepUpGuard } from '../../authentication/api/steup-up.guard.js';
import { PersonLockOccasion } from '../domain/person.enums.js';
import { KOPERS_DEADLINE_IN_DAYS } from '../domain/person-time-limit.js';

@UseFilters(SchulConnexValidationErrorFilter, new AuthenticationExceptionFilter(), new PersonExceptionFilter())
@ApiTags('personen')
Expand Down Expand Up @@ -218,7 +219,7 @@ export class PersonController {
await this.dBiamPersonenkontextService.getKopersPersonenkontext(personResult.value.id);
if (kopersKontext) {
const koperslockDate: Date = new Date(kopersKontext.createdAt);
koperslockDate.setDate(koperslockDate.getDate() + 56);
koperslockDate.setDate(koperslockDate.getDate() + KOPERS_DEADLINE_IN_DAYS);
}
}
const response: PersonendatensatzResponse = new PersonendatensatzResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import PersonTimeLimitService from './person-time-limit-info.service.js';
import { DBiamPersonenkontextService } from '../../personenkontext/domain/dbiam-personenkontext.service.js';
import { Person } from '../../person/domain/person.js';
import { DoFactory } from '../../../../test/utils/do-factory.js';
import { PersonTimeLimitInfo } from '../domain/person-time-limit-info.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';

describe('PersonTimeLimitService', () => {
let module: TestingModule;
Expand Down Expand Up @@ -61,7 +62,7 @@ describe('PersonTimeLimitService', () => {
const result: PersonTimeLimitInfo[] = await sut.getPersonTimeLimitInfo(person.id);

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

expect(result).toEqual<PersonTimeLimitInfo[]>([
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Injectable } from '@nestjs/common';
import { Personenkontext } from '../../personenkontext/domain/personenkontext.js';
import { PersonTimeLimitInfo } from '../domain/person-time-limit-info.js';
import { DBiamPersonenkontextService } from '../../personenkontext/domain/dbiam-personenkontext.service.js';
import { TimeLimitOccasion } from '../domain/time-limit-occasion.enums.js';
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';

@Injectable()
export default class PersonTimeLimitService {
Expand All @@ -27,7 +28,7 @@ export default class PersonTimeLimitService {
await this.dBiamPersonenkontextService.getKopersPersonenkontext(person.id);
if (kopersKontext) {
const kopersdeadline: Date = new Date(kopersKontext.createdAt);
kopersdeadline.setDate(kopersdeadline.getDate() + 56);
kopersdeadline.setDate(kopersdeadline.getDate() + KOPERS_DEADLINE_IN_DAYS);
lockInfos.push(new PersonTimeLimitInfo(TimeLimitOccasion.KOPERS, kopersdeadline));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/person/domain/person-time-limit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const KOPERS_DEADLINE_IN_DAYS: number = 56;
5 changes: 3 additions & 2 deletions src/modules/person/persistence/person.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { PersonalNummerForPersonWithTrailingSpaceError } from '../domain/persona
import { VornameForPersonWithTrailingSpaceError } from '../domain/vorname-with-trailing-space.error.js';
import { SystemConfig } from '../../../shared/config/system.config.js';
import { UserLock } from '../../keycloak-administration/domain/user-lock.js';
import { KOPERS_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 @@ -761,15 +762,15 @@ export class PersonRepository {

public async getKoPersUserLockList(): Promise<[PersonID, string][]> {
const daysAgo: Date = new Date();
daysAgo.setDate(daysAgo.getDate() - 56);
daysAgo.setDate(daysAgo.getDate() - KOPERS_DEADLINE_IN_DAYS);

const filters: QBFilterQuery<PersonEntity> = {
$and: [
{ personalnummer: { $eq: null } },
{
personenKontexte: {
$some: {
createdAt: { $lte: daysAgo }, // Check that createdAt is older than 56 days
createdAt: { $lte: daysAgo }, // Check that createdAt is older than KOPERS_DEADLINE_IN_DAYS
rolleId: {
merkmale: { merkmal: RollenMerkmal.KOPERS_PFLICHT },
},
Expand Down

0 comments on commit 239bf42

Please sign in to comment.