Filtrage historique trajets par utilisateur⋅rice

This commit is contained in:
Emmy D'Anello 2024-12-08 01:52:16 +01:00
parent 11ab6f66f7
commit 7fd2c4d7fe
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 9 additions and 4 deletions

View File

@ -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<PaginateOutputDto<TrainEntity>> {
const [trains, total] = await this.trainsService.findAll(queryPagination)
async findAll(@Query() queryPagination: QueryPaginationDto, @Query() userFilter: UserFilterDto): Promise<PaginateOutputDto<TrainEntity>> {
const [trains, total] = await this.trainsService.findAll(queryPagination, userFilter)
return paginateOutput<TrainEntity>(trains.map(train => new TrainEntity(train)), total, queryPagination)
}

View File

@ -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,
}),
]
}