From 7fd2c4d7fecf13f01f2dac9a6d7b86ec69ee096f Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Sun, 8 Dec 2024 01:52:16 +0100 Subject: [PATCH] =?UTF-8?q?Filtrage=20historique=20trajets=20par=20utilisa?= =?UTF-8?q?teur=E2=8B=85rice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/trains/trains.controller.ts | 5 +++-- server/src/trains/trains.service.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server/src/trains/trains.controller.ts b/server/src/trains/trains.controller.ts index f4e214a..5988e0f 100644 --- a/server/src/trains/trains.controller.ts +++ b/server/src/trains/trains.controller.ts @@ -9,6 +9,7 @@ import { ApiOkResponsePaginated, paginateOutput } from 'src/common/utils/paginat import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto' import { PaginateOutputDto } from 'src/common/dto/pagination-output.dto' import { ImportTrainDto } from './dto/import-train.dto' +import { UserFilterDto } from 'src/common/dto/user_filter.dto' @Controller('trains') export class TrainsController { @@ -32,8 +33,8 @@ export class TrainsController { @ApiOkResponsePaginated(TrainEntity) @ApiUnauthorizedResponse({ description: "Non authentifié⋅e" }) @ApiForbiddenResponse({ description: "Permission refusée" }) - async findAll(@Query() queryPagination?: QueryPaginationDto): Promise> { - const [trains, total] = await this.trainsService.findAll(queryPagination) + async findAll(@Query() queryPagination: QueryPaginationDto, @Query() userFilter: UserFilterDto): Promise> { + const [trains, total] = await this.trainsService.findAll(queryPagination, userFilter) return paginateOutput(trains.map(train => new TrainEntity(train)), total, queryPagination) } diff --git a/server/src/trains/trains.service.ts b/server/src/trains/trains.service.ts index 382be91..1c42dbc 100644 --- a/server/src/trains/trains.service.ts +++ b/server/src/trains/trains.service.ts @@ -8,6 +8,7 @@ import { paginate } from 'src/common/utils/pagination.utils' import { ImportTrainDto } from './dto/import-train.dto' import { InterrailJourney, InterrailLegInfo, InterrailTravelInfo } from './dto/interrail-api.dto' import { distanceCoordinates } from 'src/common/utils/calculus.utils' +import { UserFilterDto } from 'src/common/dto/user_filter.dto' @Injectable() export class TrainsService { @@ -17,12 +18,15 @@ export class TrainsService { return await this.prisma.trainTrip.create({ data: createTrainDto }) } - async findAll(queryPagination?: QueryPaginationDto): Promise<[TrainTrip[], number]> { + async findAll(queryPagination: QueryPaginationDto, userFilter: UserFilterDto): Promise<[TrainTrip[], number]> { return [ await this.prisma.trainTrip.findMany({ + where: userFilter, ...paginate(queryPagination), }), - await this.prisma.trainTrip.count(), + await this.prisma.trainTrip.count({ + where: userFilter, + }), ] }