Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/faker-js/faker-8.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mkreuzkam-cap authored Nov 16, 2023
2 parents ac142c2 + adc5b92 commit ad436e2
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 5 deletions.
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
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;
}
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 ad436e2

Please sign in to comment.