From adc5b9243979b2733424bb60ffe4477fa6b60a2b Mon Sep 17 00:00:00 2001 From: Majed Mak <132336669+MajedAlaitwniCap@users.noreply.github.com> Date: Thu, 16 Nov 2023 15:29:39 +0100 Subject: [PATCH] EW-612 add return value for create Person --- .../frontend/api/frontend.controller.spec.ts | 1 + .../person/api/person-api.mapper.profile.ts | 2 ++ src/modules/person/api/person.controller.spec.ts | 3 ++- src/modules/person/api/person.controller.ts | 16 ++++++++++++++-- src/modules/person/api/person.dto.ts | 3 +++ src/modules/person/api/person.response.spec.ts | 2 ++ src/modules/person/api/person.response.ts | 4 ++++ src/modules/person/api/person.uc.ts | 5 +++-- src/modules/person/domain/person.do.ts | 3 +++ src/modules/person/domain/person.service.spec.ts | 2 ++ src/modules/person/persistence/person.entity.ts | 4 ++++ test/utils/do-factory.ts | 1 + 12 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/modules/frontend/api/frontend.controller.spec.ts b/src/modules/frontend/api/frontend.controller.spec.ts index 278674130..75ccddc86 100644 --- a/src/modules/frontend/api/frontend.controller.spec.ts +++ b/src/modules/frontend/api/frontend.controller.spec.ts @@ -235,6 +235,7 @@ describe('FrontendController', () => { geschlecht: Geschlecht.M, lokalisierung: '', vertrauensstufe: Vertrauensstufe.VOLL, + revision: '1', }; const personenKontextResponse: PersonenkontextResponse[] = []; const response: PersonendatensatzResponse = { diff --git a/src/modules/person/api/person-api.mapper.profile.ts b/src/modules/person/api/person-api.mapper.profile.ts index dd3b32164..f32261f75 100644 --- a/src/modules/person/api/person-api.mapper.profile.ts +++ b/src/modules/person/api/person-api.mapper.profile.ts @@ -97,6 +97,7 @@ export class PersonApiMapperProfile extends AutomapperProfile { forMember((dest: PersonDo) => dest.id, ignore()), forMember((dest: PersonDo) => dest.createdAt, ignore()), forMember((dest: PersonDo) => dest.updatedAt, ignore()), + forMember((dest: PersonDo) => dest.revision, ignore()), ); createMap( mapper, @@ -200,6 +201,7 @@ export class PersonApiMapperProfile extends AutomapperProfile { forMember((dest: PersonDo) => dest.lokalisierung, ignore()), forMember((dest: PersonDo) => dest.vertrauensstufe, ignore()), forMember((dest: PersonDo) => dest.auskunftssperre, ignore()), + forMember((dest: PersonDo) => dest.revision, ignore()), ); createMap(mapper, CreatePersonDto, UserDo); diff --git a/src/modules/person/api/person.controller.spec.ts b/src/modules/person/api/person.controller.spec.ts index 65c32a7d0..cc7a6c3ae 100644 --- a/src/modules/person/api/person.controller.spec.ts +++ b/src/modules/person/api/person.controller.spec.ts @@ -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(), diff --git a/src/modules/person/api/person.controller.ts b/src/modules/person/api/person.controller.ts index 8d0e7c752..9ef8cb62a 100644 --- a/src/modules/person/api/person.controller.ts +++ b/src/modules/person/api/person.controller.ts @@ -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'; @@ -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 { + public async createPerson(@Body() params: CreatePersonBodyParams): Promise { 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') diff --git a/src/modules/person/api/person.dto.ts b/src/modules/person/api/person.dto.ts index 50abcf693..94035b4cc 100644 --- a/src/modules/person/api/person.dto.ts +++ b/src/modules/person/api/person.dto.ts @@ -42,4 +42,7 @@ export class PersonDto { @AutoMap() public auskunftssperre?: boolean; + + @AutoMap() + public revision!: string; } diff --git a/src/modules/person/api/person.response.spec.ts b/src/modules/person/api/person.response.spec.ts index 5a94848b2..32324af91 100644 --- a/src/modules/person/api/person.response.spec.ts +++ b/src/modules/person/api/person.response.spec.ts @@ -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', () => { @@ -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); diff --git a/src/modules/person/api/person.response.ts b/src/modules/person/api/person.response.ts index cc8988374..a3ff849c0 100644 --- a/src/modules/person/api/person.response.ts +++ b/src/modules/person/api/person.response.ts @@ -40,4 +40,8 @@ export class PersonResponse { @AutoMap(() => String) @ApiProperty({ enum: Vertrauensstufe }) public vertrauensstufe!: Vertrauensstufe; + + @AutoMap() + @ApiProperty() + public revision!: string; } diff --git a/src/modules/person/api/person.uc.ts b/src/modules/person/api/person.uc.ts index b1ebf1e4d..55188df12 100644 --- a/src/modules/person/api/person.uc.ts +++ b/src/modules/person/api/person.uc.ts @@ -24,7 +24,7 @@ export class PersonUc { @Inject(getMapperToken()) private readonly mapper: Mapper, ) {} - public async createPerson(personDto: CreatePersonDto): Promise { + public async createPerson(personDto: CreatePersonDto): Promise { // create user const userDo: UserDo = this.mapper.map(personDto, CreatePersonDto, UserDo); const userIdResult: Result = await this.userService.create(userDo); @@ -38,7 +38,8 @@ export class PersonUc { const result: Result> = 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 diff --git a/src/modules/person/domain/person.do.ts b/src/modules/person/domain/person.do.ts index a6069822b..f8c2accce 100644 --- a/src/modules/person/domain/person.do.ts +++ b/src/modules/person/domain/person.do.ts @@ -77,4 +77,7 @@ export class PersonDo implements DoBase { id: undefined, createdAt: undefined, updatedAt: undefined, + revision: '1', }); expect(result).toEqual>>({ ok: true, @@ -83,6 +84,7 @@ describe('PersonService', () => { id: undefined, createdAt: undefined, updatedAt: undefined, + revision: '1', }); expect(result).toEqual>>({ ok: false, diff --git a/src/modules/person/persistence/person.entity.ts b/src/modules/person/persistence/person.entity.ts index f5a07ab2a..590175479 100644 --- a/src/modules/person/persistence/person.entity.ts +++ b/src/modules/person/persistence/person.entity.ts @@ -95,4 +95,8 @@ export class PersonEntity extends TimestampedEntity { @ManyToOne({ nullable: true }) public dataProvider?: DataProviderEntity; + + @AutoMap() + @Property({ nullable: false, default: '1' }) + public revision!: string; } diff --git a/test/utils/do-factory.ts b/test/utils/do-factory.ts index fc8a6d951..1cc6c9b64 100644 --- a/test/utils/do-factory.ts +++ b/test/utils/do-factory.ts @@ -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(), person, props); }