Compare commits
2 Commits
7750c1b75c
...
faae6b0b93
Author | SHA1 | Date | |
---|---|---|---|
faae6b0b93 | |||
fc1773b5a6 |
@ -1,24 +1,40 @@
|
|||||||
import { ApiProperty } from "@nestjs/swagger"
|
import { ApiProperty } from "@nestjs/swagger"
|
||||||
|
import { Type } from "class-transformer"
|
||||||
|
import { IsDate, IsLatitude, IsLongitude, IsNumber } from "class-validator"
|
||||||
|
|
||||||
export class CreateGeolocationDto {
|
export class CreateGeolocationDto {
|
||||||
@ApiProperty({description: "Longitude en degrés"})
|
@IsLongitude()
|
||||||
|
@Type(() => Number)
|
||||||
|
@ApiProperty({description: "Longitude en degrés", required: true})
|
||||||
longitude: number
|
longitude: number
|
||||||
|
|
||||||
|
@IsLatitude()
|
||||||
|
@Type(() => Number)
|
||||||
@ApiProperty({description: "Latitude en degrés"})
|
@ApiProperty({description: "Latitude en degrés"})
|
||||||
latitude: number
|
latitude: number
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
@Type(() => Number)
|
||||||
@ApiProperty({description: "Vitesse en mètres par seconde"})
|
@ApiProperty({description: "Vitesse en mètres par seconde"})
|
||||||
speed: number
|
speed: number
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
@Type(() => Number)
|
||||||
@ApiProperty({description: "Précision en mètres de la position obtenue"})
|
@ApiProperty({description: "Précision en mètres de la position obtenue"})
|
||||||
accuracy: number
|
accuracy: number
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
@Type(() => Number)
|
||||||
@ApiProperty({description: "Altitude en mètres"})
|
@ApiProperty({description: "Altitude en mètres"})
|
||||||
altitude: number
|
altitude: number
|
||||||
|
|
||||||
|
@IsNumber()
|
||||||
|
@Type(() => Number)
|
||||||
@ApiProperty({description: "Précision de l'altitude en mètres"})
|
@ApiProperty({description: "Précision de l'altitude en mètres"})
|
||||||
altitudeAccuracy: number
|
altitudeAccuracy: number
|
||||||
|
|
||||||
|
@IsDate()
|
||||||
|
@Type(() => Date)
|
||||||
@ApiProperty({description: "Date et heure de capture de la géolocalisation"})
|
@ApiProperty({description: "Date et heure de capture de la géolocalisation"})
|
||||||
timestamp: Date
|
timestamp: Date
|
||||||
}
|
}
|
||||||
|
@ -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…
x
Reference in New Issue
Block a user