diff --git a/src/modules/person/api/person.controller.ts b/src/modules/person/api/person.controller.ts index 49cba7bb7..3f6acd250 100644 --- a/src/modules/person/api/person.controller.ts +++ b/src/modules/person/api/person.controller.ts @@ -1,6 +1,6 @@ import { Mapper } from '@automapper/core'; import { getMapperToken } from '@automapper/nestjs'; -import { Body, Controller, Get, Inject, Post, Param, HttpException, HttpStatus, Query, Res } from '@nestjs/common'; +import { Body, Controller, Get, Inject, Post, Param, HttpException, HttpStatus, Query } from '@nestjs/common'; import { ApiBadRequestResponse, ApiCreatedResponse, @@ -18,8 +18,7 @@ import { PersonByIdParams } from './person-by-id.param.js'; import { PersonenQueryParam } from './personen-query.param.js'; import { FindPersonDatensatzDTO } from './finde-persondatensatz-dto.js'; import { PersonenDatensatz } from './personendatensatz.js'; -import { Paged, setPaginationHeaders } from '../../../shared/paging/index.js'; -import { Response } from 'express'; +import { Paged, PagedResponse } from '../../../shared/paging/index.js'; @ApiTags('person') @Controller({ path: 'person' }) @@ -58,19 +57,15 @@ 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, - @Res() res: Response, - ): Promise { - const persondatensatzDTO: FindPersonDatensatzDTO = this.mapper.map( + public async findPersons(@Query() queryParams: PersonenQueryParam): Promise> { + const personDatensatzDTO: FindPersonDatensatzDTO = this.mapper.map( queryParams, PersonenQueryParam, FindPersonDatensatzDTO, ); - const persons: Paged = await this.uc.findAll(persondatensatzDTO); + const persons: Paged = await this.uc.findAll(personDatensatzDTO); + const response: PagedResponse = new PagedResponse(persons); - setPaginationHeaders(res, persons); - - return persons.items; + return response; } } diff --git a/src/shared/paging/global-pagination-headers.interceptor.ts b/src/shared/paging/global-pagination-headers.interceptor.ts index e75cba70b..4e60d8495 100644 --- a/src/shared/paging/global-pagination-headers.interceptor.ts +++ b/src/shared/paging/global-pagination-headers.interceptor.ts @@ -1,6 +1,5 @@ import { Observable, map } from 'rxjs'; import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common'; -import { setPaginationHeaders } from './helpers.js'; import { PagedResponse } from './paged.response.js'; import { Response } from 'express'; @@ -11,7 +10,7 @@ export class GlobalPaginationHeadersInterceptor implements NestInterceptor { if (value instanceof PagedResponse) { const response: Response = context.switchToHttp().getResponse(); - setPaginationHeaders(response, value); + GlobalPaginationHeadersInterceptor.setPaginationHeaders(response, value); return value.items as unknown[]; } @@ -20,4 +19,10 @@ export class GlobalPaginationHeadersInterceptor implements NestInterceptor { }), ); } + + private static setPaginationHeaders(response: Response, payload: PagedResponse): void { + response.setHeader('Pagination-Total', payload.total); + response.setHeader('Pagination-Offset', payload.offset); + response.setHeader('Pagination-Limit', payload.limit); + } } diff --git a/src/shared/paging/helpers.ts b/src/shared/paging/helpers.ts deleted file mode 100644 index 1d3fcfb31..000000000 --- a/src/shared/paging/helpers.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Response } from 'express'; -import { PagedResponse } from './paged.response.js'; - -export function setPaginationHeaders(response: Response, payload: PagedResponse): void { - response.setHeader('Pagination-Total', payload.total); - response.setHeader('Pagination-Offset', payload.offset); - response.setHeader('Pagination-Limit', payload.limit); -} diff --git a/src/shared/paging/index.ts b/src/shared/paging/index.ts index f4e621e97..ebc686b20 100644 --- a/src/shared/paging/index.ts +++ b/src/shared/paging/index.ts @@ -1,5 +1,4 @@ export * from './global-pagination-headers.interceptor.js'; -export * from './helpers.js'; export * from './paged.js'; export * from './paged.query.params.js'; export * from './paged.response.js';