Ajout endpoint dernière localisation utilisateur⋅rice
This commit is contained in:
parent
fc1773b5a6
commit
faae6b0b93
@ -47,12 +47,26 @@ export class GeolocationsController {
|
|||||||
@ApiForbiddenResponse({ description: "Permission refusée" })
|
@ApiForbiddenResponse({ description: "Permission refusée" })
|
||||||
@ApiNotFoundResponse({ description: "Objet non trouvé" })
|
@ApiNotFoundResponse({ description: "Objet non trouvé" })
|
||||||
async findOne(@Param('id', ParseIntPipe) id: number): Promise<GeolocationEntity> {
|
async findOne(@Param('id', ParseIntPipe) id: number): Promise<GeolocationEntity> {
|
||||||
const geolocation = await this.geolocationsService.findOne(+id)
|
const geolocation = await this.geolocationsService.findOne(id)
|
||||||
if (!geolocation)
|
if (!geolocation)
|
||||||
throw new NotFoundException(`Géolocalisation inexistante avec l'identifiant ${id}`)
|
throw new NotFoundException(`Géolocalisation inexistante avec l'identifiant ${id}`)
|
||||||
return new GeolocationEntity(geolocation)
|
return new GeolocationEntity(geolocation)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('/last-location/:userId')
|
||||||
|
@UseGuards(JwtAuthGuard)
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@ApiOkResponse({ type: GeolocationEntity })
|
||||||
|
@ApiUnauthorizedResponse({ description: "Non authentifié⋅e" })
|
||||||
|
@ApiForbiddenResponse({ description: "Permission refusée" })
|
||||||
|
@ApiNotFoundResponse({ description: "Aucune localisation trouvée" })
|
||||||
|
async findLastLocation(@Param('userId', ParseIntPipe) userId: number): Promise<GeolocationEntity> {
|
||||||
|
const geolocation = await this.geolocationsService.findLastLocation(userId)
|
||||||
|
if (!geolocation)
|
||||||
|
throw new NotFoundException(`Géolocalisation inexistante pour l'utilisateur⋅rice ${userId}`)
|
||||||
|
return new GeolocationEntity(geolocation)
|
||||||
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
|
@ -32,6 +32,14 @@ export class GeolocationsService {
|
|||||||
return await this.prisma.geolocation.findUnique({ where: { id } })
|
return await this.prisma.geolocation.findUnique({ where: { id } })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findLastLocation(userId: number): Promise<Geolocation> {
|
||||||
|
return await this.prisma.geolocation.findFirst({
|
||||||
|
where: { userId: userId },
|
||||||
|
orderBy: { timestamp: "desc" },
|
||||||
|
take: 1
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async remove(id: number): Promise<Geolocation> {
|
async remove(id: number): Promise<Geolocation> {
|
||||||
return await this.prisma.geolocation.delete({ where: { id } })
|
return await this.prisma.geolocation.delete({ where: { id } })
|
||||||
|
Loading…
Reference in New Issue
Block a user