diff --git a/server/src/app.module.ts b/server/src/app.module.ts index c93660b..b00281e 100644 --- a/server/src/app.module.ts +++ b/server/src/app.module.ts @@ -1,9 +1,10 @@ import { Module } from '@nestjs/common' import { PrismaService } from './prisma/prisma.service' import { PrismaModule } from './prisma/prisma.module' +import { UsersModule } from './users/users.module' @Module({ - imports: [PrismaModule], + imports: [PrismaModule, UsersModule], providers: [PrismaService], }) export class AppModule {} diff --git a/server/src/prisma/prisma.service.ts b/server/src/prisma/prisma.service.ts index ff36ace..a18770c 100644 --- a/server/src/prisma/prisma.service.ts +++ b/server/src/prisma/prisma.service.ts @@ -1,4 +1,5 @@ import { Injectable } from '@nestjs/common' +import { PrismaClient } from '@prisma/client' @Injectable() -export class PrismaService {} +export class PrismaService extends PrismaClient {} diff --git a/server/src/users/entities/user.entity.ts b/server/src/users/entities/user.entity.ts new file mode 100644 index 0000000..4502acc --- /dev/null +++ b/server/src/users/entities/user.entity.ts @@ -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 +} diff --git a/server/src/users/users.controller.spec.ts b/server/src/users/users.controller.spec.ts new file mode 100644 index 0000000..a76d310 --- /dev/null +++ b/server/src/users/users.controller.spec.ts @@ -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); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/server/src/users/users.controller.ts b/server/src/users/users.controller.ts new file mode 100644 index 0000000..f602df0 --- /dev/null +++ b/server/src/users/users.controller.ts @@ -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) + } +} diff --git a/server/src/users/users.module.ts b/server/src/users/users.module.ts new file mode 100644 index 0000000..9dfdd54 --- /dev/null +++ b/server/src/users/users.module.ts @@ -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 {} diff --git a/server/src/users/users.service.spec.ts b/server/src/users/users.service.spec.ts new file mode 100644 index 0000000..b87ef3c --- /dev/null +++ b/server/src/users/users.service.spec.ts @@ -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) + }) + + it('should be defined', () => { + expect(service).toBeDefined() + }) +}) diff --git a/server/src/users/users.service.ts b/server/src/users/users.service.ts new file mode 100644 index 0000000..47720ec --- /dev/null +++ b/server/src/users/users.service.ts @@ -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 } }) + } +}