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 { ApiProperty } from "@nestjs/swagger"
|
||||||
import { Type } from "class-transformer"
|
|
||||||
import { IsDate, IsLatitude, IsLongitude, IsNumber } from "class-validator"
|
|
||||||
|
|
||||||
export class CreateGeolocationDto {
|
export class CreateGeolocationDto {
|
||||||
@IsLongitude()
|
@ApiProperty({description: "Longitude en degrés"})
|
||||||
@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,26 +47,12 @@ 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,14 +32,6 @@ 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