Ajout structure de jeu
This commit is contained in:
@ -8,9 +8,10 @@ import { ChallengesModule } from './challenges/challenges.module'
|
||||
import { ChallengeActionsModule } from './challenge-actions/challenge-actions.module'
|
||||
import { TrainsModule } from './trains/trains.module'
|
||||
import { MoneyUpdatesModule } from './money-updates/money-updates.module'
|
||||
import { GameModule } from './game/game.module'
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule, PlayersModule, AuthModule, GeolocationsModule, ChallengesModule, ChallengeActionsModule, TrainsModule, MoneyUpdatesModule],
|
||||
imports: [PrismaModule, AuthModule, PlayersModule, GameModule, GeolocationsModule, ChallengesModule, ChallengeActionsModule, TrainsModule, MoneyUpdatesModule],
|
||||
providers: [PrismaService],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
@ -4,8 +4,8 @@ import { ApiOkResponse, ApiTags } from '@nestjs/swagger'
|
||||
import { AuthEntity } from './entity/auth.entity'
|
||||
import { LoginDto } from './dto/login.dto'
|
||||
|
||||
@Controller('auth')
|
||||
@ApiTags('auth')
|
||||
@Controller('auth')
|
||||
export class AuthController {
|
||||
constructor(private readonly authService: AuthService) {}
|
||||
|
||||
|
17
server/src/game/entities/game.entity.ts
Normal file
17
server/src/game/entities/game.entity.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { ApiProperty } from "@nestjs/swagger"
|
||||
import { Game } from "@prisma/client"
|
||||
|
||||
export class GameEntity implements Game {
|
||||
constructor(partial: Partial<GameEntity>) {
|
||||
Object.assign(this, partial)
|
||||
}
|
||||
|
||||
@ApiProperty({ description: "Identifiant unique du jeu" })
|
||||
id: number
|
||||
|
||||
@ApiProperty({ description: "Est-ce que la partie est en cours" })
|
||||
started: boolean
|
||||
|
||||
@ApiProperty({ description: "Identifiant de læ joueur⋅se en course" })
|
||||
currentRunnerId: number
|
||||
}
|
20
server/src/game/game.controller.spec.ts
Normal file
20
server/src/game/game.controller.spec.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'
|
||||
import { GameController } from './game.controller'
|
||||
import { GameService } from './game.service'
|
||||
|
||||
describe('GameController', () => {
|
||||
let controller: GameController
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [GameController],
|
||||
providers: [GameService],
|
||||
}).compile()
|
||||
|
||||
controller = module.get<GameController>(GameController)
|
||||
})
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined()
|
||||
})
|
||||
})
|
19
server/src/game/game.controller.ts
Normal file
19
server/src/game/game.controller.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common'
|
||||
import { GameService } from './game.service'
|
||||
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard'
|
||||
import { ApiBearerAuth, ApiOkResponse, ApiUnauthorizedResponse } from '@nestjs/swagger'
|
||||
import { GameEntity } from './entities/game.entity'
|
||||
|
||||
@Controller('game')
|
||||
export class GameController {
|
||||
constructor(private readonly gameService: GameService) {}
|
||||
|
||||
@Get()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiOkResponse({ type: GameEntity })
|
||||
@ApiUnauthorizedResponse({ description: "Non authentifié⋅e" })
|
||||
async find() {
|
||||
return new GameEntity(await this.gameService.find())
|
||||
}
|
||||
}
|
11
server/src/game/game.module.ts
Normal file
11
server/src/game/game.module.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { GameService } from './game.service'
|
||||
import { GameController } from './game.controller'
|
||||
import { PrismaModule } from 'src/prisma/prisma.module'
|
||||
|
||||
@Module({
|
||||
controllers: [GameController],
|
||||
providers: [GameService],
|
||||
imports: [PrismaModule],
|
||||
})
|
||||
export class GameModule {}
|
18
server/src/game/game.service.spec.ts
Normal file
18
server/src/game/game.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'
|
||||
import { GameService } from './game.service'
|
||||
|
||||
describe('GameService', () => {
|
||||
let service: GameService
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [GameService],
|
||||
}).compile()
|
||||
|
||||
service = module.get<GameService>(GameService)
|
||||
})
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined()
|
||||
})
|
||||
})
|
11
server/src/game/game.service.ts
Normal file
11
server/src/game/game.service.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { PrismaService } from 'src/prisma/prisma.service'
|
||||
|
||||
@Injectable()
|
||||
export class GameService {
|
||||
constructor (private prisma: PrismaService) {}
|
||||
|
||||
async find() {
|
||||
return await this.prisma.game.findUnique({ where: { id: 1 } })
|
||||
}
|
||||
}
|
@ -18,7 +18,4 @@ export class PlayerEntity implements Player {
|
||||
|
||||
@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
|
||||
}
|
||||
|
Reference in New Issue
Block a user