Compare commits
	
		
			2 Commits
		
	
	
		
			7750c1b75c
			...
			faae6b0b93
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| faae6b0b93 | |||
| fc1773b5a6 | 
| @@ -1,24 +1,40 @@ | ||||
| import { ApiProperty } from "@nestjs/swagger" | ||||
| import { Type } from "class-transformer" | ||||
| import { IsDate, IsLatitude, IsLongitude, IsNumber } from "class-validator" | ||||
|  | ||||
| export class CreateGeolocationDto { | ||||
|     @ApiProperty({description: "Longitude en degrés"}) | ||||
|     @IsLongitude() | ||||
|     @Type(() => Number) | ||||
|     @ApiProperty({description: "Longitude en degrés", required: true}) | ||||
|     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,12 +47,26 @@ 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,6 +32,14 @@ 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 } }) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user