Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/EW-646-logger-module' into EW-64…
Browse files Browse the repository at this point in the history
…6-logger-module
  • Loading branch information
alweber-cap committed Nov 17, 2023
2 parents eecd4d5 + c23acbd commit f9a61a5
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 54 deletions.
6 changes: 3 additions & 3 deletions config/config.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"SESSION_SECRET": "SessionSecretForDevelopment",
"SESSION_TTL_MS": 3600000,
"BACKEND_ADDRESS": "http://127.0.0.1:9090",
"OIDC_CALLBACK_URL": "http://localhost:8099/api/frontend/login",
"DEFAULT_LOGIN_REDIRECT": "http://localhost:8099/",
"LOGOUT_REDIRECT": "http://localhost:8099/"
"OIDC_CALLBACK_URL": "https://localhost:8099/api/frontend/login",
"DEFAULT_LOGIN_REDIRECT": "https://localhost:8099/",
"LOGOUT_REDIRECT": "https://localhost:8099/"
},
"DB": {
"CLIENT_URL": "postgres://admin:[email protected]:5432",
Expand Down
4 changes: 2 additions & 2 deletions dev-realm-spsh.json
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@
"secret": "YDp6fYkbUcj4ZkyAOnbAHGQ9O72htc5M",
"redirectUris": [
"http://localhost:9091/*",
"http://localhost:8099/*",
"https://localhost:8099/*",
"/*"
],
"webOrigins": [
Expand Down Expand Up @@ -2364,4 +2364,4 @@
"clientPolicies": {
"policies": []
}
}
}
95 changes: 55 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"express-session": "^1.17.3",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"nest-commander": "^3.12.2",
"nest-commander": "~3.10",
"nest-keycloak-connect": "^1.9.2",
"openid-client": "^5.6.0",
"passport": "^0.6.0",
Expand Down
1 change: 1 addition & 0 deletions src/modules/frontend/api/frontend.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ describe('FrontendController', () => {
geschlecht: Geschlecht.M,
lokalisierung: '',
vertrauensstufe: Vertrauensstufe.VOLL,
revision: '1',
};
const personenKontextResponse: PersonenkontextResponse[] = [];
const response: PersonendatensatzResponse = {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/frontend/auth/user.decorator.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ExecutionContext, createParamDecorator } from '@nestjs/common';
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { Request } from 'express';
import { UserinfoResponse } from 'openid-client';

type UserDecoratorFactory = () => ParameterDecorator;

export type User = { id_token: string; access_token: string; userinfo: UserinfoResponse } & Express.User;
export type User = { id_token: string; access_token: string; userinfo: UserinfoResponse };

export const CurrentUser: UserDecoratorFactory = createParamDecorator((_data: unknown, ctx: ExecutionContext) => {
const request: Request = ctx.switchToHttp().getRequest<Request>();
Expand Down
2 changes: 2 additions & 0 deletions src/modules/person/api/person-api.mapper.profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class PersonApiMapperProfile extends AutomapperProfile {
forMember((dest: PersonDo<boolean>) => dest.id, ignore()),
forMember((dest: PersonDo<boolean>) => dest.createdAt, ignore()),
forMember((dest: PersonDo<boolean>) => dest.updatedAt, ignore()),
forMember((dest: PersonDo<boolean>) => dest.revision, ignore()),
);
createMap(
mapper,
Expand Down Expand Up @@ -200,6 +201,7 @@ export class PersonApiMapperProfile extends AutomapperProfile {
forMember((dest: PersonDo<false>) => dest.lokalisierung, ignore()),
forMember((dest: PersonDo<false>) => dest.vertrauensstufe, ignore()),
forMember((dest: PersonDo<false>) => dest.auskunftssperre, ignore()),
forMember((dest: PersonDo<false>) => dest.revision, ignore()),
);

createMap(mapper, CreatePersonDto, UserDo);
Expand Down
3 changes: 2 additions & 1 deletion src/modules/person/api/person.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ describe('PersonController', () => {

describe('when creating a person', () => {
it('should not throw', async () => {
personUcMock.createPerson.mockResolvedValue();
const personDto: PersonDto = {} as PersonDto;
personUcMock.createPerson.mockResolvedValue(personDto);
const params: CreatePersonBodyParams = {
username: faker.internet.userName(),
mandant: faker.string.uuid(),
Expand Down
16 changes: 14 additions & 2 deletions src/modules/person/api/person.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { CreatedPersonenkontextDto } from './created-personenkontext.dto.js';
import { FindPersonendatensatzDto } from './find-personendatensatz.dto.js';
import { FindPersonenkontextDto } from './find-personenkontext.dto.js';
import { PersonByIdParams } from './person-by-id.param.js';
import { PersonDto } from './person.dto.js';
import { PersonenQueryParams } from './personen-query.param.js';
import { PersonendatensatzDto } from './personendatensatz.dto.js';
import { PersonendatensatzResponse } from './personendatensatz.response.js';
Expand All @@ -56,14 +57,25 @@ export class PersonController {
) {}

@Post()
@HttpCode(200)
@ApiCreatedResponse({ description: 'The person was successfully created.' })
@ApiBadRequestResponse({ description: 'The person already exists.' })
@ApiUnauthorizedResponse({ description: 'Not authorized to create the person.' })
@ApiForbiddenResponse({ description: 'Insufficient permissions to create the person.' })
@ApiInternalServerErrorResponse({ description: 'Internal server error while creating the person.' })
public async createPerson(@Body() params: CreatePersonBodyParams): Promise<void> {
public async createPerson(@Body() params: CreatePersonBodyParams): Promise<PersonendatensatzResponse> {
const dto: CreatePersonDto = this.mapper.map(params, CreatePersonBodyParams, CreatePersonDto);
await this.personUc.createPerson(dto);
const person: PersonDto = await this.personUc.createPerson(dto);
const personendatensatzDto: PersonendatensatzDto = {
person: person,
personenkontexte: [],
};
const personendatensatzResponse: PersonendatensatzResponse = this.mapper.map(
personendatensatzDto,
PersonendatensatzDto,
PersonendatensatzResponse,
);
return personendatensatzResponse;
}

@Get(':personId')
Expand Down
3 changes: 3 additions & 0 deletions src/modules/person/api/person.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ export class PersonDto {

@AutoMap()
public auskunftssperre?: boolean;

@AutoMap()
public revision!: string;
}
2 changes: 2 additions & 0 deletions src/modules/person/api/person.response.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('PersonResponse', () => {
geschlecht: faker.person.gender(),
lokalisierung: faker.location.country(),
vertrauensstufe: Vertrauensstufe.VOLL,
revision: '1',
};

it('should convert plain object of person response to a class of person response', () => {
Expand All @@ -39,6 +40,7 @@ describe('PersonResponse', () => {
geschlecht: personResponse.geschlecht,
lokalisierung: personResponse.lokalisierung,
vertrauensstufe: personResponse.vertrauensstufe,
revision: personResponse.revision,
};
const mappedParams: PersonResponse = plainToInstance(PersonResponse, person, {});
expect(mappedParams).toBeInstanceOf(PersonResponse);
Expand Down
4 changes: 4 additions & 0 deletions src/modules/person/api/person.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ export class PersonResponse {
@AutoMap(() => String)
@ApiProperty({ enum: Vertrauensstufe })
public vertrauensstufe!: Vertrauensstufe;

@AutoMap()
@ApiProperty()
public revision!: string;
}
5 changes: 3 additions & 2 deletions src/modules/person/api/person.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class PersonUc {
@Inject(getMapperToken()) private readonly mapper: Mapper,
) {}

public async createPerson(personDto: CreatePersonDto): Promise<void> {
public async createPerson(personDto: CreatePersonDto): Promise<PersonDto> {
// create user
const userDo: UserDo<false> = this.mapper.map(personDto, CreatePersonDto, UserDo<false>);
const userIdResult: Result<string> = await this.userService.create(userDo);
Expand All @@ -38,7 +38,8 @@ export class PersonUc {

const result: Result<PersonDo<true>> = await this.personService.createPerson(personDo);
if (result.ok) {
return;
const resPersonDto: PersonDto = this.mapper.map(personDo, PersonDo, PersonDto);
return resPersonDto;
}

// delete user if person could not be created
Expand Down
3 changes: 3 additions & 0 deletions src/modules/person/domain/person.do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,7 @@ export class PersonDo<WasPersisted extends boolean> implements DoBase<WasPersist

@AutoMap()
public auskunftssperre?: boolean;

@AutoMap()
public revision!: string;
}
2 changes: 2 additions & 0 deletions src/modules/person/domain/person.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('PersonService', () => {
id: undefined,
createdAt: undefined,
updatedAt: undefined,
revision: '1',
});
expect(result).toEqual<Result<PersonDo<true>>>({
ok: true,
Expand All @@ -83,6 +84,7 @@ describe('PersonService', () => {
id: undefined,
createdAt: undefined,
updatedAt: undefined,
revision: '1',
});
expect(result).toEqual<Result<PersonDo<true>>>({
ok: false,
Expand Down
4 changes: 4 additions & 0 deletions src/modules/person/persistence/person.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,8 @@ export class PersonEntity extends TimestampedEntity<PersonEntity, 'id'> {

@ManyToOne({ nullable: true })
public dataProvider?: DataProviderEntity;

@AutoMap()
@Property({ nullable: false, default: '1' })
public revision!: string;
}
2 changes: 1 addition & 1 deletion src/modules/rolle/api/provider.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { AuthenticatedUser } from 'nest-keycloak-connect';
import { GetServiceProviderInfoDo } from '../domain/get-service-provider-info.do.js';

@ApiTags('rolle')
@ApiTags('provider')
@Controller({ path: 'provider' })
export class ProviderController {
public constructor(private readonly rolleService: RolleService) {}
Expand Down
1 change: 1 addition & 0 deletions test/utils/do-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class DoFactory {
id: withId ? faker.string.uuid() : undefined,
createdAt: withId ? faker.date.past() : undefined,
updatedAt: withId ? faker.date.recent() : undefined,
revision: '1',
};
return Object.assign(new PersonDo<WasPersisted>(), person, props);
}
Expand Down

0 comments on commit f9a61a5

Please sign in to comment.