Documentation endpoint user

This commit is contained in:
Emmy D'Anello 2024-12-07 12:20:57 +01:00
parent 4486e99225
commit 376c297eda
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
6 changed files with 72 additions and 24 deletions

View File

@ -10,10 +10,11 @@
"license": "UNLICENSED", "license": "UNLICENSED",
"dependencies": { "dependencies": {
"@nestjs/common": "^10.0.0", "@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0", "@nestjs/core": "^10.4.13",
"@nestjs/platform-express": "^10.0.0", "@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^8.1.0", "@nestjs/swagger": "^8.1.0",
"@prisma/client": "^6.0.1", "@prisma/client": "^6.0.1",
"class-validator": "^0.14.1",
"prisma": "^6.0.1", "prisma": "^6.0.1",
"reflect-metadata": "^0.2.0", "reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1", "rxjs": "^7.8.1",
@ -22,7 +23,7 @@
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^10.0.0", "@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0", "@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0", "@nestjs/testing": "^10.4.13",
"@types/express": "^5.0.0", "@types/express": "^5.0.0",
"@types/jest": "^29.5.2", "@types/jest": "^29.5.2",
"@types/node": "^20.3.1", "@types/node": "^20.3.1",
@ -1661,9 +1662,9 @@
} }
}, },
"node_modules/@nestjs/core": { "node_modules/@nestjs/core": {
"version": "10.4.12", "version": "10.4.13",
"resolved": "https://registry.npmjs.org/@nestjs/core/-/core-10.4.12.tgz", "resolved": "https://registry.npmjs.org/@nestjs/core/-/core-10.4.13.tgz",
"integrity": "sha512-2qENES1U0VxCOfW45jVIV7g38edcvuU5aaLpZWOhb3nzehdvmeYoovUe8LTTHFrLWsDVY1v9FPfEhFQGsZfopQ==", "integrity": "sha512-zivGEaq9tmwdeQi/RK0nUVdvhdIwcIsytBvEGTmDBFkmEnxEMp3T0Ia4BTFlTFrjLAb5D2cNUQZBZZj1vqfXtw==",
"hasInstallScript": true, "hasInstallScript": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -1719,9 +1720,9 @@
} }
}, },
"node_modules/@nestjs/platform-express": { "node_modules/@nestjs/platform-express": {
"version": "10.4.12", "version": "10.4.13",
"resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.4.12.tgz", "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.4.13.tgz",
"integrity": "sha512-+m8BQas9mnY29Y6rZv8EUqIYwcta99/dTiGIUy48LB/+YoAyDTEHpsLd2+rpetk54niGgKJYclCZRUwRcjrYYA==", "integrity": "sha512-9Uar9t5NZebI9Y8P8B6OYTfj6p5DuUHM/nk2zGwbL3SLdnieP4O2K1DuePo3SWiYBStmPoTAlXyl6L2zDtrLjQ==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"body-parser": "1.20.3", "body-parser": "1.20.3",
@ -1797,9 +1798,9 @@
} }
}, },
"node_modules/@nestjs/testing": { "node_modules/@nestjs/testing": {
"version": "10.4.12", "version": "10.4.13",
"resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-10.4.12.tgz", "resolved": "https://registry.npmjs.org/@nestjs/testing/-/testing-10.4.13.tgz",
"integrity": "sha512-Q1ZpzmIqzem6Q9pBwT1qQRYE050HhvSh8U7AbdIavOHCI063GbXOy/erXEpUnE0o46mqT+y88Nn9NjTXAQt4nQ==", "integrity": "sha512-07PIDxZbr5sHq+1bHFtMqAyZuxvCqu041OU6pyCR3O76sspFizZg1oxIE2TYzPCKeCbNZavjQ2Zn1K9j+rnjvQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -2311,6 +2312,12 @@
"@types/superagent": "^8.1.0" "@types/superagent": "^8.1.0"
} }
}, },
"node_modules/@types/validator": {
"version": "13.12.2",
"resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.12.2.tgz",
"integrity": "sha512-6SlHBzUW8Jhf3liqrGGXyTJSIFe4nqlJ5A5KaMZ2l/vbM3Wh3KSybots/wfWVzNLK4D1NZluDlSQIbIEPx6oyA==",
"license": "MIT"
},
"node_modules/@types/yargs": { "node_modules/@types/yargs": {
"version": "17.0.33", "version": "17.0.33",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.33.tgz", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.33.tgz",
@ -3463,6 +3470,25 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/class-transformer": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.4.0.tgz",
"integrity": "sha512-ETWD/H2TbWbKEi7m9N4Km5+cw1hNcqJSxlSYhsLsNjQzWWiZIYA1zafxpK9PwVfaZ6AqR5rrjPVUBGESm5tQUA==",
"license": "MIT",
"optional": true,
"peer": true
},
"node_modules/class-validator": {
"version": "0.14.1",
"resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.14.1.tgz",
"integrity": "sha512-2VEG9JICxIqTpoK1eMzZqaV+u/EiwEJkMGzTrZf6sU/fwsnOITVgYJ8yojSy6CaXtO9V0Cc6ZQZ8h8m4UBuLwQ==",
"license": "MIT",
"dependencies": {
"@types/validator": "^13.11.8",
"libphonenumber-js": "^1.10.53",
"validator": "^13.9.0"
}
},
"node_modules/cli-cursor": { "node_modules/cli-cursor": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
@ -6478,6 +6504,12 @@
"node": ">= 0.8.0" "node": ">= 0.8.0"
} }
}, },
"node_modules/libphonenumber-js": {
"version": "1.11.16",
"resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.11.16.tgz",
"integrity": "sha512-Noyazmt0yOvnG0OeRY45Cd1ur8G7Z0HWVkuCuKe+yysGNxPQwBAODBQQ40j0AIagi9ZWurfmmZWNlpg4h4W+XQ==",
"license": "MIT"
},
"node_modules/lines-and-columns": { "node_modules/lines-and-columns": {
"version": "1.2.4", "version": "1.2.4",
"resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
@ -8973,6 +9005,15 @@
"node": ">=10.12.0" "node": ">=10.12.0"
} }
}, },
"node_modules/validator": {
"version": "13.12.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.12.0.tgz",
"integrity": "sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==",
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
},
"node_modules/vary": { "node_modules/vary": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",

View File

@ -21,10 +21,11 @@
}, },
"dependencies": { "dependencies": {
"@nestjs/common": "^10.0.0", "@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0", "@nestjs/core": "^10.4.13",
"@nestjs/platform-express": "^10.0.0", "@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^8.1.0", "@nestjs/swagger": "^8.1.0",
"@prisma/client": "^6.0.1", "@prisma/client": "^6.0.1",
"class-validator": "^0.14.1",
"prisma": "^6.0.1", "prisma": "^6.0.1",
"reflect-metadata": "^0.2.0", "reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1", "rxjs": "^7.8.1",
@ -33,7 +34,7 @@
"devDependencies": { "devDependencies": {
"@nestjs/cli": "^10.0.0", "@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0", "@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0", "@nestjs/testing": "^10.4.13",
"@types/express": "^5.0.0", "@types/express": "^5.0.0",
"@types/jest": "^29.5.2", "@types/jest": "^29.5.2",
"@types/node": "^20.3.1", "@types/node": "^20.3.1",

View File

@ -1,9 +1,11 @@
import { NestFactory } from '@nestjs/core' import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module' import { AppModule } from './app.module'
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger' import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
import { ValidationPipe } from '@nestjs/common'
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule) const app = await NestFactory.create(AppModule)
app.useGlobalPipes(new ValidationPipe())
const config = new DocumentBuilder() const config = new DocumentBuilder()
.setTitle('Traintrape-moi') .setTitle('Traintrape-moi')
.setDescription('API permettant de stocker les données de Traintrape-moi') .setDescription('API permettant de stocker les données de Traintrape-moi')

View File

@ -1,5 +1,5 @@
import { ApiProperty } from "@nestjs/swagger"; import { ApiProperty } from "@nestjs/swagger"
import { User } from "@prisma/client"; import { User } from "@prisma/client"
export class UserEntity implements User { export class UserEntity implements User {
@ApiProperty({description: "Identifiant unique"}) @ApiProperty({description: "Identifiant unique"})

View File

@ -1,6 +1,6 @@
import { Controller, Get, Param } from '@nestjs/common' import { Controller, Get, NotFoundException, Param, ParseIntPipe } from '@nestjs/common'
import { UsersService } from './users.service' import { UsersService } from './users.service'
import { ApiOkResponse } from '@nestjs/swagger' import { ApiNotFoundResponse, ApiOkResponse } from '@nestjs/swagger'
import { UserEntity } from './entities/user.entity' import { UserEntity } from './entities/user.entity'
@Controller('users') @Controller('users')
@ -9,13 +9,17 @@ export class UsersController {
@Get() @Get()
@ApiOkResponse({ type: UserEntity, isArray: true }) @ApiOkResponse({ type: UserEntity, isArray: true })
findAll() { async findAll() {
return this.usersService.findAll() return this.usersService.findAll()
} }
@Get(':id') @Get(':id')
@ApiOkResponse({ type: UserEntity }) @ApiOkResponse({ type: UserEntity })
findOne(@Param('id') id: string) { @ApiNotFoundResponse({ description: "Utilisateur⋅rice non trouvé⋅e" })
return this.usersService.findOne(+id) async findOne(@Param('id', ParseIntPipe) id: number) {
const user = await this.usersService.findOne(id)
if (!user)
throw new NotFoundException(`L'utilisateur⋅rice avec l'identifiant ${id} n'existe pas`)
return user
} }
} }

View File

@ -5,11 +5,11 @@ import { PrismaService } from 'src/prisma/prisma.service'
export class UsersService { export class UsersService {
constructor(private prisma: PrismaService) {} constructor(private prisma: PrismaService) {}
findAll() { async findAll() {
return this.prisma.user.findMany() return await this.prisma.user.findMany()
} }
findOne(id: number) { async findOne(id: number) {
return this.prisma.user.findUnique({ where: { id } }) return await this.prisma.user.findUnique({ where: { id } })
} }
} }