-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EW-617: Add create Personenkontext route to person controller.
- Loading branch information
1 parent
088894b
commit 64c88fa
Showing
16 changed files
with
437 additions
and
8 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/modules/person/api/create-personenkontext.body.params.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { AutoMap } from '@automapper/classes'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsString, IsEnum, IsOptional } from 'class-validator'; | ||
import { Jahrgangsstufe, Personenstatus, Rolle } from '../domain/personenkontext.enums.js'; | ||
|
||
export class CreatePersonenkontextBodyParams { | ||
@AutoMap() | ||
@IsString() | ||
@IsOptional() | ||
@ApiProperty({ required: false }) | ||
public readonly referrer?: string; | ||
|
||
@AutoMap() | ||
@IsEnum(Rolle) | ||
@ApiProperty({ enum: Rolle, required: true }) | ||
public readonly rolle!: Rolle; | ||
|
||
@AutoMap() | ||
@IsEnum(Personenstatus) | ||
@IsOptional() | ||
@ApiProperty({ enum: Personenstatus, required: false }) | ||
public readonly personenstatus?: Personenstatus; | ||
|
||
@AutoMap() | ||
@IsEnum(Jahrgangsstufe) | ||
@IsOptional() | ||
@ApiProperty({ enum: Jahrgangsstufe, required: false }) | ||
public readonly jahrgangsstufe?: Jahrgangsstufe; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { AutoMap } from '@automapper/classes'; | ||
import { Rolle, Personenstatus, Jahrgangsstufe } from '../domain/personenkontext.enums.js'; | ||
|
||
export class CreatePersonenkontextDto { | ||
@AutoMap() | ||
public personId!: string; | ||
|
||
@AutoMap() | ||
public readonly referrer?: string; | ||
|
||
@AutoMap() | ||
public readonly rolle!: Rolle; | ||
|
||
@AutoMap() | ||
public readonly personenstatus?: Personenstatus; | ||
|
||
@AutoMap() | ||
public readonly jahrgangsstufe?: Jahrgangsstufe; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export class CreatedPersonenkontextDtoOrganisation { | ||
public readonly id!: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { AutoMap } from '@automapper/classes'; | ||
import { Jahrgangsstufe, Personenstatus, Rolle } from '../domain/personenkontext.enums.js'; | ||
import { CreatedPersonenkontextDtoOrganisation } from './created-personenkontext-org.dto.js'; | ||
|
||
export class CreatedPersonenkontextDto { | ||
@AutoMap() | ||
public readonly id!: string; | ||
|
||
@AutoMap() | ||
public readonly referrer?: string; | ||
|
||
@AutoMap() | ||
public readonly mandant!: string; | ||
|
||
@AutoMap() | ||
public readonly organisation!: CreatedPersonenkontextDtoOrganisation; | ||
|
||
@AutoMap() | ||
public readonly rolle!: Rolle; | ||
|
||
@AutoMap() | ||
public readonly personenstatus?: Personenstatus; | ||
|
||
@AutoMap() | ||
public readonly jahrgangsstufe?: Jahrgangsstufe; | ||
|
||
@AutoMap() | ||
public readonly revision!: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { AutoMap } from '@automapper/classes'; | ||
import { Rolle, Personenstatus, Jahrgangsstufe } from '../domain/personenkontext.enums.js'; | ||
import { CreatedPersonenkontextDtoOrganisation } from './created-personenkontext-org.dto.js'; | ||
|
||
export class PersonenkontextResponse { | ||
@AutoMap() | ||
public readonly id!: string; | ||
|
||
@AutoMap() | ||
public readonly referrer?: string; | ||
|
||
@AutoMap() | ||
public readonly mandant!: string; | ||
|
||
@AutoMap() | ||
public readonly organisation!: CreatedPersonenkontextDtoOrganisation; | ||
|
||
@AutoMap() | ||
public readonly rolle!: Rolle; | ||
|
||
@AutoMap() | ||
public readonly personenstatus?: Personenstatus; | ||
|
||
@AutoMap() | ||
public readonly jahrgangsstufe?: Jahrgangsstufe; | ||
|
||
@AutoMap() | ||
public readonly revision!: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Mapper } from '@automapper/core'; | ||
import { getMapperToken } from '@automapper/nestjs'; | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { PersonenkontextDo } from '../domain/personenkontext.do.js'; | ||
import { PersonenkontextService } from '../domain/personenkontext.service.js'; | ||
import { CreatePersonenkontextDto } from './create-personenkontext.dto.js'; | ||
import { CreatedPersonenkontextDto } from './created-personenkontext.dto.js'; | ||
|
||
@Injectable() | ||
export class PersonenkontextUc { | ||
public constructor( | ||
private readonly personenkontextService: PersonenkontextService, | ||
@Inject(getMapperToken()) private readonly mapper: Mapper, | ||
) {} | ||
|
||
public async createPersonenkontext( | ||
personenkontextDto: CreatePersonenkontextDto, | ||
): Promise<CreatedPersonenkontextDto> { | ||
const personenkontextDo: PersonenkontextDo<false> = this.mapper.map( | ||
personenkontextDto, | ||
CreatePersonenkontextDto, | ||
PersonenkontextDo, | ||
); | ||
const result: Result<PersonenkontextDo<true>> = await this.personenkontextService.createPersonenkontext( | ||
personenkontextDo, | ||
); | ||
if (result.ok) { | ||
return this.mapper.map(result.value, PersonenkontextDo, CreatedPersonenkontextDto); | ||
} | ||
throw result.error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { AutoMap } from '@automapper/classes'; | ||
import { DoBase } from '../../../shared/types/index.js'; | ||
import { OrganisationDo } from '../../organisation/domain/organisation.do.js'; | ||
import { Jahrgangsstufe, Personenstatus, Rolle } from './personenkontext.enums.js'; | ||
|
||
export class PersonenkontextDo<WasPersisted extends boolean> implements DoBase<WasPersisted> { | ||
/** | ||
* @deprecated This constructor is for automapper only. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-useless-constructor, @typescript-eslint/no-empty-function | ||
public constructor() {} | ||
|
||
@AutoMap() | ||
public createdAt!: Persisted<Date, WasPersisted>; | ||
|
||
@AutoMap() | ||
public updatedAt!: Persisted<Date, WasPersisted>; | ||
|
||
@AutoMap() | ||
public id!: Persisted<string, WasPersisted>; | ||
|
||
@AutoMap() | ||
public personId!: string; | ||
|
||
@AutoMap() | ||
public referrer?: string; | ||
|
||
@AutoMap() | ||
public mandant!: string; | ||
|
||
@AutoMap() | ||
public organisation!: OrganisationDo<WasPersisted>; | ||
|
||
@AutoMap() | ||
public rolle!: Rolle; | ||
|
||
@AutoMap() | ||
public personenstatus?: Personenstatus; | ||
|
||
@AutoMap() | ||
public jahrgangsstufe?: Jahrgangsstufe; | ||
|
||
@AutoMap() | ||
public sichtfreigabe?: boolean = false; | ||
|
||
@AutoMap() | ||
public loeschungZeitpunkt?: Date; | ||
|
||
@AutoMap() | ||
public revision!: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export enum Personenstatus { | ||
Aktiv = 'AKTIV', | ||
} | ||
|
||
export enum Jahrgangsstufe { | ||
Jahrgangsstufe1 = '01', | ||
Jahrgangsstufe2 = '02', | ||
Jahrgangsstufe3 = '03', | ||
Jahrgangsstufe4 = '04', | ||
Jahrgangsstufe5 = '05', | ||
Jahrgangsstufe6 = '06', | ||
Jahrgangsstufe7 = '07', | ||
Jahrgangsstufe8 = '08', | ||
Jahrgangsstufe9 = '09', | ||
Jahrgangsstufe10 = '10', | ||
} | ||
|
||
export enum Rolle { | ||
Lernender = 'LERN', | ||
Lehrender = 'LEHR', | ||
Externe_Person = 'EXTERN', | ||
Organisationsadministrator = 'ORGADMIN', | ||
Organisationsleitung = 'LEIT', | ||
Systemadministrator = 'SYSADMIN', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { DomainError } from '../../../shared/error/index.js'; | ||
import { EntityCouldNotBeCreated } from '../../../shared/error/entity-could-not-be-created.error.js'; | ||
import { PersonenkontextRepo } from '../persistence/personenkontext.repo.js'; | ||
import { PersonenkontextDo } from './personenkontext.do.js'; | ||
|
||
@Injectable() | ||
export class PersonenkontextService { | ||
public constructor(private readonly personenkontextRepo: PersonenkontextRepo) {} | ||
|
||
public async createPersonenkontext( | ||
personenkontextDo: PersonenkontextDo<false>, | ||
): Promise<Result<PersonenkontextDo<true>, DomainError>> { | ||
const personenkontext: PersonenkontextDo<true> = await this.personenkontextRepo.save(personenkontextDo); | ||
if (personenkontext) { | ||
return { ok: true, value: personenkontext }; | ||
} | ||
return { ok: false, error: new EntityCouldNotBeCreated(`Personenkontext could not be created`) }; | ||
} | ||
} |
Oops, something went wrong.