Skip to content

Commit

Permalink
introduce OrganisationKennung FlavoredType in Email- and OxEventHandl…
Browse files Browse the repository at this point in the history
…er and LDAPClientSvc
  • Loading branch information
DPDS93CT committed Jan 14, 2025
1 parent 57ec4ab commit 0928fc2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
24 changes: 16 additions & 8 deletions src/core/ldap/domain/ldap-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { LdapInstanceConfig } from '../ldap-instance-config.js';
import { UsernameRequiredError } from '../../../modules/person/domain/username-required.error.js';
import { Mutex } from 'async-mutex';
import { LdapSearchError } from '../error/ldap-search.error.js';
import { PersonID, PersonReferrer } from '../../../shared/types/aggregate-ids.types.js';
import { OrganisationKennung, PersonID, PersonReferrer } from '../../../shared/types/aggregate-ids.types.js';
import { EventService } from '../../eventbus/services/event.service.js';
import { LdapPersonEntryChangedEvent } from '../../../shared/events/ldap-person-entry-changed.event.js';
import { LdapEmailAddressError } from '../error/ldap-email-address.error.js';
Expand Down Expand Up @@ -120,14 +120,22 @@ export class LdapClientService {
);
}

public async deleteLehrer(person: PersonData, orgaKennung: string, domain: string): Promise<Result<PersonData>> {
public async deleteLehrer(
person: PersonData,
orgaKennung: OrganisationKennung,
domain: string,
): Promise<Result<PersonData>> {
return this.executeWithRetry(
() => this.deleteLehrerInternal(person, orgaKennung, domain),
LdapClientService.DEFAULT_RETRIES,
);
}

public async addPersonToGroup(personUid: string, orgaKennung: string, lehrerUid: string): Promise<Result<boolean>> {
public async addPersonToGroup(
personUid: string,
orgaKennung: OrganisationKennung,
lehrerUid: string,
): Promise<Result<boolean>> {
return this.executeWithRetry(
() => this.addPersonToGroupInternal(personUid, orgaKennung, lehrerUid),
LdapClientService.DEFAULT_RETRIES,
Expand All @@ -147,7 +155,7 @@ export class LdapClientService {

public async removePersonFromGroup(
referrer: PersonReferrer,
orgaKennung: string,
orgaKennung: OrganisationKennung,
lehrerUid: string,
): Promise<Result<boolean>> {
return this.executeWithRetry(
Expand All @@ -158,7 +166,7 @@ export class LdapClientService {

public async removePersonFromGroupByUsernameAndKennung(
referrer: PersonReferrer,
orgaKennung: string,
orgaKennung: OrganisationKennung,
domain: string,
): Promise<Result<boolean>> {
const rootName: Result<string> = this.getRootNameOrError(domain);
Expand Down Expand Up @@ -531,7 +539,7 @@ export class LdapClientService {

private async deleteLehrerInternal(
person: PersonData,
orgaKennung: string,
orgaKennung: OrganisationKennung,
domain: string,
): Promise<Result<PersonData>> {
const rootName: Result<string> = this.getRootNameOrError(domain);
Expand Down Expand Up @@ -667,7 +675,7 @@ export class LdapClientService {

private async addPersonToGroupInternal(
personUid: string,
orgaKennung: string,
orgaKennung: OrganisationKennung,
lehrerUid: string,
): Promise<Result<boolean>> {
const groupId: string = 'lehrer-' + orgaKennung;
Expand Down Expand Up @@ -749,7 +757,7 @@ export class LdapClientService {

private async removePersonFromGroupInternal(
referrer: PersonReferrer,
orgaKennung: string,
orgaKennung: OrganisationKennung,
lehrerUid: string,
): Promise<Result<boolean>> {
const groupId: string = 'lehrer-' + orgaKennung;
Expand Down
10 changes: 5 additions & 5 deletions src/modules/email/domain/email-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ServiceProvider } from '../../service-provider/domain/service-provider.
import { ServiceProviderKategorie } from '../../service-provider/domain/service-provider.enum.js';
import { PersonDeletedEvent } from '../../../shared/events/person-deleted.event.js';
import { DomainError, EntityNotFoundError } from '../../../shared/error/index.js';
import { OrganisationID, PersonID, PersonReferrer } from '../../../shared/types/index.js';
import { OrganisationID, OrganisationKennung, PersonID, PersonReferrer } from '../../../shared/types/index.js';
import { EmailAddressEntity } from '../persistence/email-address.entity.js';
import { EmailAddressNotFoundError } from '../error/email-address-not-found.error.js';
import { EmailRepo } from '../persistence/email.repo.js';
Expand Down Expand Up @@ -460,7 +460,7 @@ export class EmailEventHandler {
}
}

private async getOrganisationKennung(organisationId: OrganisationID): Promise<Result<string>> {
private async getOrganisationKennung(organisationId: OrganisationID): Promise<Result<OrganisationKennung>> {
const organisation: Option<Organisation<true>> = await this.organisationRepository.findById(organisationId);
if (!organisation || !organisation.kennung) {
this.logger.error(`Could not retrieve orgaKennung, orgaId:${organisationId}`);
Expand All @@ -476,7 +476,7 @@ export class EmailEventHandler {
}

private async createOrEnableEmail(personId: PersonID, organisationId: OrganisationID): Promise<void> {
const organisationKennung: Result<string> = await this.getOrganisationKennung(organisationId);
const organisationKennung: Result<OrganisationKennung> = await this.getOrganisationKennung(organisationId);
if (!organisationKennung.ok) return;

const existingEmails: EmailAddress<true>[] = await this.emailRepo.findByPersonSortedByUpdatedAtDesc(personId);
Expand Down Expand Up @@ -556,7 +556,7 @@ export class EmailEventHandler {
}

private async createNewEmail(personId: PersonID, organisationId: OrganisationID): Promise<void> {
const organisationKennung: Result<string> = await this.getOrganisationKennung(organisationId);
const organisationKennung: Result<OrganisationKennung> = await this.getOrganisationKennung(organisationId);
if (!organisationKennung.ok) return;
const personReferrer: Result<string> = await this.getPersonReferrerOrError(personId);
if (!personReferrer.ok) {
Expand Down Expand Up @@ -597,7 +597,7 @@ export class EmailEventHandler {
organisationId: OrganisationID,
oldEmail: EmailAddress<true>,
): Promise<void> {
const organisationKennung: Result<string> = await this.getOrganisationKennung(organisationId);
const organisationKennung: Result<OrganisationKennung> = await this.getOrganisationKennung(organisationId);
if (!organisationKennung.ok) return;
const personReferrer: Result<string> = await this.getPersonReferrerOrError(personId);
if (!personReferrer.ok) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/ox/domain/ox-event-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigTestModule, LoggingTestModule } from '../../../../test/utils/index.js';
import { ClassLogger } from '../../../core/logging/class-logger.js';
import { PersonID, PersonReferrer } from '../../../shared/types/index.js';
import { OrganisationKennung, PersonID, PersonReferrer } from '../../../shared/types/index.js';
import { OxEventHandler } from './ox-event-handler.js';
import { OxService } from './ox.service.js';
import { CreateUserAction } from '../actions/user/create-user.action.js';
Expand Down Expand Up @@ -1313,7 +1313,7 @@ describe('OxEventHandler', () => {
let username: string;
let oxUserId: OXUserID;
let oxGroupId: OXGroupID;
let rollenArtLehrPKOrgaKennung: string;
let rollenArtLehrPKOrgaKennung: OrganisationKennung;
let event: PersonenkontextUpdatedEvent;
let person: Person<true>;
beforeEach(() => {
Expand Down
8 changes: 6 additions & 2 deletions src/modules/ox/domain/ox-event-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DomainError } from '../../../shared/error/index.js';
import { OxConfig } from '../../../shared/config/ox.config.js';
import { OxService } from './ox.service.js';
import { CreateUserAction, CreateUserParams, CreateUserResponse } from '../actions/user/create-user.action.js';
import { PersonID, PersonReferrer } from '../../../shared/types/index.js';
import { OrganisationKennung, PersonID, PersonReferrer } from '../../../shared/types/index.js';
import { Person } from '../../person/domain/person.js';
import { PersonRepository } from '../../person/persistence/person.repository.js';
import { EmailAddressGeneratedEvent } from '../../../shared/events/email-address-generated.event.js';
Expand Down Expand Up @@ -455,7 +455,11 @@ export class OxEventHandler {
return result;
}

private async createOxUser(personId: PersonID, referrer: PersonReferrer, orgaKennung: string): Promise<void> {
private async createOxUser(
personId: PersonID,
referrer: PersonReferrer,
orgaKennung: OrganisationKennung,
): Promise<void> {
const person: Option<Person<true>> = await this.personRepository.findById(personId);

if (!person) {
Expand Down
3 changes: 3 additions & 0 deletions src/shared/types/aggregate-ids.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export type PersonReferrer = Flavor<string, typeof personReferrerSymbol>;
declare const organisationSymbol: unique symbol;
export type OrganisationID = Flavor<string, typeof organisationSymbol>;

declare const organisationKennungSymbol: unique symbol;
export type OrganisationKennung = Flavor<string, typeof organisationKennungSymbol>;

declare const rolleSymbol: unique symbol;
export type RolleID = Flavor<string, typeof rolleSymbol>;

Expand Down

0 comments on commit 0928fc2

Please sign in to comment.