Ajout endpoints défis

This commit is contained in:
2024-12-07 19:29:38 +01:00
parent faae6b0b93
commit 572a04130f
20 changed files with 429 additions and 8 deletions

View File

@ -20,7 +20,6 @@ export class GeolocationsController {
@ApiCreatedResponse({ type: GeolocationEntity, description: "Objet créé avec succès" })
@ApiUnauthorizedResponse({ description: "Non authentifié⋅e" })
@ApiForbiddenResponse({ description: "Permission refusée" })
@ApiNotFoundResponse({ description: "Object non trouvé" })
async create(@Req() request: AuthenticatedRequest, @Body() createGeolocationDto: CreateGeolocationDto): Promise<GeolocationEntity> {
const user = request.user
const geolocation = await this.geolocationsService.create(user, createGeolocationDto)
@ -33,7 +32,6 @@ export class GeolocationsController {
@ApiOkResponsePaginated(GeolocationEntity)
@ApiUnauthorizedResponse({ description: "Non authentifié⋅e" })
@ApiForbiddenResponse({ description: "Permission refusée" })
@ApiNotFoundResponse({ description: "Objet non trouvé" })
async findAll(@Query() queryPagination?: QueryPaginationDto, @Query() userFilter?: UserFilterDto): Promise<PaginateOutputDto<GeolocationEntity>> {
const [geolocations, total] = await this.geolocationsService.findAll(queryPagination, userFilter)
return paginateOutput<GeolocationEntity>(geolocations.map(geolocation => new GeolocationEntity(geolocation)), total, queryPagination)

View File

@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common'
import { CreateGeolocationDto } from './dto/create-geolocation.dto'
import { PrismaService } from 'src/prisma/prisma.service'
import { Geolocation, User } from '@prisma/client'
import { Geolocation, Prisma, User } from '@prisma/client'
import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto'
import { paginate } from 'src/common/utils/pagination.utils'
import { UserFilterDto } from 'src/common/dto/user_filter.dto'
@ -17,7 +17,8 @@ export class GeolocationsService {
async findAll(queryPagination?: QueryPaginationDto, userFilter?: UserFilterDto): Promise<[Geolocation[], number]> {
const filter = {
where: userFilter?.userId ? { userId: userFilter.userId } : {}
where: (userFilter?.userId ? { userId: userFilter.userId } : {}),
orderBy: { timestamp: Prisma.SortOrder.desc },
}
return [
await this.prisma.geolocation.findMany({
@ -35,7 +36,7 @@ export class GeolocationsService {
async findLastLocation(userId: number): Promise<Geolocation> {
return await this.prisma.geolocation.findFirst({
where: { userId: userId },
orderBy: { timestamp: "desc" },
orderBy: { timestamp: Prisma.SortOrder.desc },
take: 1
})
}