Correction de l'endpoint qui récupère les dernières géolocalisations
This commit is contained in:
parent
20b4f2e7e8
commit
a0fd6ca6ab
@ -42,6 +42,20 @@ export class GeolocationsController {
|
|||||||
return paginateOutput<GeolocationEntity>(geolocations.map(geolocation => new GeolocationEntity(geolocation)), total, queryPagination)
|
return paginateOutput<GeolocationEntity>(geolocations.map(geolocation => new GeolocationEntity(geolocation)), total, queryPagination)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupération des dernières posititons de tout le monde
|
||||||
|
*
|
||||||
|
* @throws {401} Non authentifié⋅e
|
||||||
|
* @throws {404} Aucune localisation envoyée
|
||||||
|
*/
|
||||||
|
@Get('/last-locations')
|
||||||
|
@UseGuards(JwtAuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
async findLastLocations(): Promise<GeolocationEntity[]> {
|
||||||
|
const lastGeolocations = await this.geolocationsService.findLastLocations()
|
||||||
|
return lastGeolocations.map(geolocation => new GeolocationEntity(geolocation))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recherche d'une géolocalisation par identifiant
|
* Recherche d'une géolocalisation par identifiant
|
||||||
*
|
*
|
||||||
@ -58,22 +72,6 @@ export class GeolocationsController {
|
|||||||
return new GeolocationEntity(geolocation)
|
return new GeolocationEntity(geolocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Récupération de la dernière posititon
|
|
||||||
*
|
|
||||||
* @throws {401} Non authentifié⋅e
|
|
||||||
* @throws {404} Aucune localisation envoyée
|
|
||||||
*/
|
|
||||||
@Get('/last-location/:playerId')
|
|
||||||
@UseGuards(JwtAuthGuard)
|
|
||||||
@ApiBearerAuth()
|
|
||||||
async findLastLocation(@Param('playerId', ParseIntPipe) playerId: number): Promise<GeolocationEntity> {
|
|
||||||
const geolocation = await this.geolocationsService.findLastLocation(playerId)
|
|
||||||
if (!geolocation)
|
|
||||||
throw new NotFoundException(`Géolocalisation inexistante pour læ joueur⋅se ${playerId}`)
|
|
||||||
return new GeolocationEntity(geolocation)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suppression d'une localisation
|
* Suppression d'une localisation
|
||||||
*
|
*
|
||||||
|
@ -33,14 +33,20 @@ export class GeolocationsService {
|
|||||||
return await this.prisma.geolocation.findUnique({ where: { id } })
|
return await this.prisma.geolocation.findUnique({ where: { id } })
|
||||||
}
|
}
|
||||||
|
|
||||||
async findLastLocation(playerId: number): Promise<Geolocation> {
|
async findLastLocations(): Promise<Geolocation[]> {
|
||||||
return await this.prisma.geolocation.findFirst({
|
const players = await this.prisma.player.findMany()
|
||||||
where: { playerId: playerId },
|
const lastGeolocations = []
|
||||||
orderBy: { timestamp: Prisma.SortOrder.desc },
|
for (const player of players) {
|
||||||
take: 1
|
const lastGeolocationPlayer = await this.prisma.geolocation.findFirst({
|
||||||
|
where: { playerId: player.id },
|
||||||
|
orderBy: { timestamp: 'desc' },
|
||||||
|
take: 1,
|
||||||
})
|
})
|
||||||
|
if (lastGeolocationPlayer)
|
||||||
|
lastGeolocations.push(lastGeolocationPlayer)
|
||||||
|
}
|
||||||
|
return lastGeolocations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async remove(id: number): Promise<Geolocation> {
|
async remove(id: number): Promise<Geolocation> {
|
||||||
if (!this.findOne(id))
|
if (!this.findOne(id))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user