Skip to content

Commit

Permalink
EW-561 introducing some helper classes
Browse files Browse the repository at this point in the history
  • Loading branch information
psachmann committed Oct 16, 2023
1 parent 6bd24fc commit 13b9df9
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 50 deletions.
3 changes: 2 additions & 1 deletion src/modules/person/api/finde-persondatensatz-dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AutoMap } from '@automapper/classes';
import { PagedDto } from '../../../shared/paging/index.js';

export class FindPersonDatensatzDTO {
export class FindPersonDatensatzDTO extends PagedDto {
@AutoMap()
public referrer?: string;

Expand Down
10 changes: 5 additions & 5 deletions src/modules/person/api/person-api.mapper.profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Gender, TrustLevel } from '../domain/person.enums.js';
import { CreatePersonBodyParams } from './create-person.body.params.js';
import { FindPersonDatensatzDTO } from './finde-persondatensatz-dto.js';
import { PersonGender, PersonTrustLevel } from './person.enums.js';
import { PersonenQueryParam, SichtfreigabeType } from './personen-query.param.js';
import { PersonenQueryParams, SichtfreigabeType } from './personen-query.param.js';
import { PersonenDatensatz } from './personendatensatz.js';

export const personGenderToGenderConverter: Converter<PersonGender, Gender> = {
Expand Down Expand Up @@ -215,19 +215,19 @@ export class PersonApiMapperProfile extends AutomapperProfile {
);
createMap(
mapper,
PersonenQueryParam,
PersonenQueryParams,
FindPersonDatensatzDTO,
forMember(
(dest: FindPersonDatensatzDTO) => dest.vorname,
mapFrom((src: PersonenQueryParam) => src.vorname),
mapFrom((src: PersonenQueryParams) => src.vorname),
),
forMember(
(dest: FindPersonDatensatzDTO) => dest.familienname,
mapFrom((src: PersonenQueryParam) => src.familienname),
mapFrom((src: PersonenQueryParams) => src.familienname),
),
forMember(
(dest: FindPersonDatensatzDTO) => dest.referrer,
mapFrom((src: PersonenQueryParam) => src.referrer),
mapFrom((src: PersonenQueryParams) => src.referrer),
),
);
createMap(
Expand Down
4 changes: 2 additions & 2 deletions src/modules/person/api/person.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { PersonUc } from './person.uc.js';
import { PersonByIdParams } from './person-by-id.param.js';
import { PersonResponse } from './person.response.js';
import { HttpException } from '@nestjs/common';
import { PersonenQueryParam } from './personen-query.param.js';
import { PersonenQueryParams } from './personen-query.param.js';
import { PersonBirthParams } from './person-birth.params.js';
import { TrustLevel } from '../domain/person.enums.js';
import { PersonenDatensatz } from './personendatensatz.js';
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('PersonController', () => {
lastName: faker.person.lastName(),
firstName: faker.person.firstName(),
};
const queryParams: PersonenQueryParam = {
const queryParams: PersonenQueryParams = {
referrer: options.referrer,
familienname: options.lastName,
vorname: options.firstName,
Expand Down
6 changes: 3 additions & 3 deletions src/modules/person/api/person.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { PersonUc } from '../api/person.uc.js';
import { CreatePersonBodyParams } from './create-person.body.params.js';
import { CreatePersonDto } from '../domain/create-person.dto.js';
import { PersonByIdParams } from './person-by-id.param.js';
import { PersonenQueryParam } from './personen-query.param.js';
import { PersonenQueryParams } from './personen-query.param.js';
import { FindPersonDatensatzDTO } from './finde-persondatensatz-dto.js';
import { PersonenDatensatz } from './personendatensatz.js';
import { Paged, PagedResponse } from '../../../shared/paging/index.js';
Expand Down Expand Up @@ -57,10 +57,10 @@ export class PersonController {
@ApiUnauthorizedResponse({ description: 'Not authorized to get persons.' })
@ApiForbiddenResponse({ description: 'Insufficient permissions to get persons.' })
@ApiInternalServerErrorResponse({ description: 'Internal server error while getting all persons.' })
public async findPersons(@Query() queryParams: PersonenQueryParam): Promise<PagedResponse<PersonenDatensatz>> {
public async findPersons(@Query() queryParams: PersonenQueryParams): Promise<PagedResponse<PersonenDatensatz>> {
const personDatensatzDTO: FindPersonDatensatzDTO = this.mapper.map(
queryParams,
PersonenQueryParam,
PersonenQueryParams,
FindPersonDatensatzDTO,
);
const persons: Paged<PersonenDatensatz> = await this.uc.findAll(personDatensatzDTO);
Expand Down
6 changes: 5 additions & 1 deletion src/modules/person/api/person.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ export class PersonUc {

public async findAll(personDto: FindPersonDatensatzDto): Promise<Paged<PersonenDatensatz>> {
const personDo: PersonDo<false> = this.mapper.map(personDto, FindPersonDatensatzDto, PersonDo);
const result: Paged<PersonDo<true>> = await this.personService.findAllPersons(undefined, undefined, personDo);
const result: Paged<PersonDo<true>> = await this.personService.findAllPersons(
personDto.offset,
personDto.limit,
personDo,
);

if (result.total === 0) {
return {
Expand Down
21 changes: 2 additions & 19 deletions src/modules/person/api/personen-query.param.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsOptional, IsString } from 'class-validator';
import { AutoMap } from '@automapper/classes';
import { PagedQueryParams } from '../../../shared/paging/index.js';

export enum SichtfreigabeType {
JA = 'ja',
NEIN = 'nein',
}

export class PersonenQueryParam {
export class PersonenQueryParams extends PagedQueryParams {
@AutoMap()
@IsOptional()
@IsString()
Expand Down Expand Up @@ -49,22 +50,4 @@ export class PersonenQueryParam {
nullable: true,
})
public readonly sichtfreigabe: SichtfreigabeType = SichtfreigabeType.NEIN;*/

@AutoMap()
@IsOptional({})
@ApiProperty({
default: 0,
required: false,
nullable: false,
})
public readonly offset: number = 0;

@AutoMap()
@IsOptional({})
@ApiProperty({
default: 0,
required: false,
nullable: false,
})
public readonly limit: number = 100;
}
1 change: 1 addition & 0 deletions src/shared/paging/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './global-pagination-headers.interceptor.js';
export * from './paged.dto.js';
export * from './paged.js';
export * from './paged.query.params.js';
export * from './paged.response.js';
9 changes: 9 additions & 0 deletions src/shared/paging/paged.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AutoMap } from '@automapper/classes';

export abstract class PagedDto {
@AutoMap()
public readonly offset?: number;

@AutoMap()
public readonly limit?: number;
}
10 changes: 8 additions & 2 deletions src/shared/paging/paged.query.params.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { AutoMap } from '@automapper/classes';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional } from 'class-validator';

export abstract class PagedQueryParams {
@AutoMap()
@IsOptional()
@ApiPropertyOptional({
description: 'The offset of the paginated list.',
required: false,
})
public readonly offset?: number;

@AutoMap()
@IsOptional()
@ApiPropertyOptional({
description: 'The requested limit for the page size.',
required: false,
})
public readonly limit?: number;
}


1 change: 0 additions & 1 deletion src/shared/persistence/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// export * from './repo-base.js';
export * from './scope-base.js';
export * from './scope.enums.js';
16 changes: 0 additions & 16 deletions src/shared/persistence/repo-base.ts

This file was deleted.

0 comments on commit 13b9df9

Please sign in to comment.