Compare commits
No commits in common. "faae6b0b9358292ebc6e56d8e2a26f7c7b396c79" and "7750c1b75c7ac1d7c77fa0efa6edfbddbde52103" have entirely different histories.
faae6b0b93
...
7750c1b75c
@ -1,40 +1,24 @@
|
||||
import { ApiProperty } from "@nestjs/swagger"
|
||||
import { Type } from "class-transformer"
|
||||
import { IsDate, IsLatitude, IsLongitude, IsNumber } from "class-validator"
|
||||
|
||||
export class CreateGeolocationDto {
|
||||
@IsLongitude()
|
||||
@Type(() => Number)
|
||||
@ApiProperty({description: "Longitude en degrés", required: true})
|
||||
@ApiProperty({description: "Longitude en degrés"})
|
||||
longitude: number
|
||||
|
||||
@IsLatitude()
|
||||
@Type(() => Number)
|
||||
@ApiProperty({description: "Latitude en degrés"})
|
||||
latitude: number
|
||||
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
@ApiProperty({description: "Vitesse en mètres par seconde"})
|
||||
speed: number
|
||||
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
@ApiProperty({description: "Précision en mètres de la position obtenue"})
|
||||
accuracy: number
|
||||
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
@ApiProperty({description: "Altitude en mètres"})
|
||||
altitude: number
|
||||
|
||||
@IsNumber()
|
||||
@Type(() => Number)
|
||||
@ApiProperty({description: "Précision de l'altitude en mètres"})
|
||||
altitudeAccuracy: number
|
||||
|
||||
@IsDate()
|
||||
@Type(() => Date)
|
||||
@ApiProperty({description: "Date et heure de capture de la géolocalisation"})
|
||||
timestamp: Date
|
||||
}
|
||||
|
@ -47,26 +47,12 @@ export class GeolocationsController {
|
||||
@ApiForbiddenResponse({ description: "Permission refusée" })
|
||||
@ApiNotFoundResponse({ description: "Objet non trouvé" })
|
||||
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)
|
||||
throw new NotFoundException(`Géolocalisation inexistante avec l'identifiant ${id}`)
|
||||
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')
|
||||
@HttpCode(204)
|
||||
@UseGuards(JwtAuthGuard)
|
||||
|
@ -32,14 +32,6 @@ export class GeolocationsService {
|
||||
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> {
|
||||
return await this.prisma.geolocation.delete({ where: { id } })
|
||||
|
Loading…
x
Reference in New Issue
Block a user