Ajout des endpoints API User
This commit is contained in:
parent
9b3fe93f4f
commit
4486e99225
@ -1,9 +1,10 @@
|
|||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { PrismaService } from './prisma/prisma.service'
|
import { PrismaService } from './prisma/prisma.service'
|
||||||
import { PrismaModule } from './prisma/prisma.module'
|
import { PrismaModule } from './prisma/prisma.module'
|
||||||
|
import { UsersModule } from './users/users.module'
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [PrismaModule],
|
imports: [PrismaModule, UsersModule],
|
||||||
providers: [PrismaService],
|
providers: [PrismaService],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
|
import { PrismaClient } from '@prisma/client'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PrismaService {}
|
export class PrismaService extends PrismaClient {}
|
||||||
|
16
server/src/users/entities/user.entity.ts
Normal file
16
server/src/users/entities/user.entity.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { ApiProperty } from "@nestjs/swagger";
|
||||||
|
import { User } from "@prisma/client";
|
||||||
|
|
||||||
|
export class UserEntity implements User {
|
||||||
|
@ApiProperty({description: "Identifiant unique"})
|
||||||
|
id: number
|
||||||
|
|
||||||
|
@ApiProperty({description: "Nom de læ joueur⋅se"})
|
||||||
|
name: string
|
||||||
|
|
||||||
|
@ApiProperty({description: "Nombre de jetons dont dispose actuellement læ joueur⋅se"})
|
||||||
|
money: number
|
||||||
|
|
||||||
|
@ApiProperty({description: "Est-ce que cet⋅te joueur⋅se est cellui actuellement en course"})
|
||||||
|
currentRunner: boolean
|
||||||
|
}
|
20
server/src/users/users.controller.spec.ts
Normal file
20
server/src/users/users.controller.spec.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { UsersController } from './users.controller';
|
||||||
|
import { UsersService } from './users.service';
|
||||||
|
|
||||||
|
describe('UsersController', () => {
|
||||||
|
let controller: UsersController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [UsersController],
|
||||||
|
providers: [UsersService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<UsersController>(UsersController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
21
server/src/users/users.controller.ts
Normal file
21
server/src/users/users.controller.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { Controller, Get, Param } from '@nestjs/common'
|
||||||
|
import { UsersService } from './users.service'
|
||||||
|
import { ApiOkResponse } from '@nestjs/swagger'
|
||||||
|
import { UserEntity } from './entities/user.entity'
|
||||||
|
|
||||||
|
@Controller('users')
|
||||||
|
export class UsersController {
|
||||||
|
constructor(private readonly usersService: UsersService) {}
|
||||||
|
|
||||||
|
@Get()
|
||||||
|
@ApiOkResponse({ type: UserEntity, isArray: true })
|
||||||
|
findAll() {
|
||||||
|
return this.usersService.findAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
@ApiOkResponse({ type: UserEntity })
|
||||||
|
findOne(@Param('id') id: string) {
|
||||||
|
return this.usersService.findOne(+id)
|
||||||
|
}
|
||||||
|
}
|
11
server/src/users/users.module.ts
Normal file
11
server/src/users/users.module.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { Module } from '@nestjs/common'
|
||||||
|
import { UsersService } from './users.service'
|
||||||
|
import { UsersController } from './users.controller'
|
||||||
|
import { PrismaModule } from 'src/prisma/prisma.module'
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [UsersController],
|
||||||
|
providers: [UsersService],
|
||||||
|
imports: [PrismaModule],
|
||||||
|
})
|
||||||
|
export class UsersModule {}
|
18
server/src/users/users.service.spec.ts
Normal file
18
server/src/users/users.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { Test, TestingModule } from '@nestjs/testing'
|
||||||
|
import { UsersService } from './users.service'
|
||||||
|
|
||||||
|
describe('UsersService', () => {
|
||||||
|
let service: UsersService
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [UsersService],
|
||||||
|
}).compile()
|
||||||
|
|
||||||
|
service = module.get<UsersService>(UsersService)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined()
|
||||||
|
})
|
||||||
|
})
|
15
server/src/users/users.service.ts
Normal file
15
server/src/users/users.service.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { Injectable } from '@nestjs/common'
|
||||||
|
import { PrismaService } from 'src/prisma/prisma.service'
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class UsersService {
|
||||||
|
constructor(private prisma: PrismaService) {}
|
||||||
|
|
||||||
|
findAll() {
|
||||||
|
return this.prisma.user.findMany()
|
||||||
|
}
|
||||||
|
|
||||||
|
findOne(id: number) {
|
||||||
|
return this.prisma.user.findUnique({ where: { id } })
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user