Compare commits
No commits in common. "b93b8b4c04d5e861cc77d6b8b8b6aad12d3d5ab5" and "65576fc5b1d5472a16ef4d68a2dcc3b8ebc9bb51" have entirely different histories.
b93b8b4c04
...
65576fc5b1
@ -7,19 +7,11 @@ CREATE TABLE "Player" (
|
|||||||
"name" TEXT NOT NULL,
|
"name" TEXT NOT NULL,
|
||||||
"password" TEXT NOT NULL,
|
"password" TEXT NOT NULL,
|
||||||
"money" INTEGER NOT NULL DEFAULT 0,
|
"money" INTEGER NOT NULL DEFAULT 0,
|
||||||
|
"currentRunner" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
|
||||||
CONSTRAINT "Player_pkey" PRIMARY KEY ("id")
|
CONSTRAINT "Player_pkey" PRIMARY KEY ("id")
|
||||||
);
|
);
|
||||||
|
|
||||||
-- CreateTable
|
|
||||||
CREATE TABLE "Game" (
|
|
||||||
"id" SERIAL NOT NULL,
|
|
||||||
"started" BOOLEAN NOT NULL DEFAULT false,
|
|
||||||
"currentRunnerId" INTEGER,
|
|
||||||
|
|
||||||
CONSTRAINT "Game_pkey" PRIMARY KEY ("id")
|
|
||||||
);
|
|
||||||
|
|
||||||
-- CreateTable
|
-- CreateTable
|
||||||
CREATE TABLE "Geolocation" (
|
CREATE TABLE "Geolocation" (
|
||||||
"id" SERIAL NOT NULL,
|
"id" SERIAL NOT NULL,
|
||||||
@ -90,9 +82,6 @@ CREATE TABLE "MoneyUpdate" (
|
|||||||
-- CreateIndex
|
-- CreateIndex
|
||||||
CREATE UNIQUE INDEX "Player_name_key" ON "Player"("name");
|
CREATE UNIQUE INDEX "Player_name_key" ON "Player"("name");
|
||||||
|
|
||||||
-- CreateIndex
|
|
||||||
CREATE UNIQUE INDEX "Game_currentRunnerId_key" ON "Game"("currentRunnerId");
|
|
||||||
|
|
||||||
-- CreateIndex
|
-- CreateIndex
|
||||||
CREATE UNIQUE INDEX "Challenge_title_key" ON "Challenge"("title");
|
CREATE UNIQUE INDEX "Challenge_title_key" ON "Challenge"("title");
|
||||||
|
|
||||||
@ -105,9 +94,6 @@ CREATE UNIQUE INDEX "MoneyUpdate_actionId_key" ON "MoneyUpdate"("actionId");
|
|||||||
-- CreateIndex
|
-- CreateIndex
|
||||||
CREATE UNIQUE INDEX "MoneyUpdate_tripId_key" ON "MoneyUpdate"("tripId");
|
CREATE UNIQUE INDEX "MoneyUpdate_tripId_key" ON "MoneyUpdate"("tripId");
|
||||||
|
|
||||||
-- AddForeignKey
|
|
||||||
ALTER TABLE "Game" ADD CONSTRAINT "Game_currentRunnerId_fkey" FOREIGN KEY ("currentRunnerId") REFERENCES "Player"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
||||||
|
|
||||||
-- AddForeignKey
|
-- AddForeignKey
|
||||||
ALTER TABLE "Geolocation" ADD CONSTRAINT "Geolocation_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "Player"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
ALTER TABLE "Geolocation" ADD CONSTRAINT "Geolocation_playerId_fkey" FOREIGN KEY ("playerId") REFERENCES "Player"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||||
|
|
@ -12,18 +12,11 @@ model Player {
|
|||||||
name String @unique
|
name String @unique
|
||||||
password String
|
password String
|
||||||
money Int @default(0)
|
money Int @default(0)
|
||||||
|
currentRunner Boolean @default(false)
|
||||||
actions ChallengeAction[]
|
actions ChallengeAction[]
|
||||||
geolocations Geolocation[]
|
geolocations Geolocation[]
|
||||||
moneyUpdates MoneyUpdate[]
|
moneyUpdates MoneyUpdate[]
|
||||||
trips TrainTrip[]
|
trips TrainTrip[]
|
||||||
runningGame Game?
|
|
||||||
}
|
|
||||||
|
|
||||||
model Game {
|
|
||||||
id Int @id @default(autoincrement())
|
|
||||||
started Boolean @default(false)
|
|
||||||
currentRunner Player? @relation(fields: [currentRunnerId], references: [id])
|
|
||||||
currentRunnerId Int? @unique
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model Geolocation {
|
model Geolocation {
|
||||||
|
@ -4,7 +4,6 @@ import * as bcrypt from 'bcrypt'
|
|||||||
const prisma = new PrismaClient()
|
const prisma = new PrismaClient()
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const game = await prisma.game.create({ data: {} })
|
|
||||||
const emmyPassword = await bcrypt.hash("Emmy", 10)
|
const emmyPassword = await bcrypt.hash("Emmy", 10)
|
||||||
const emmy = await prisma.player.upsert({
|
const emmy = await prisma.player.upsert({
|
||||||
where: { id: 1 },
|
where: { id: 1 },
|
||||||
@ -18,7 +17,7 @@ async function main() {
|
|||||||
update: { name: 'Tamina' },
|
update: { name: 'Tamina' },
|
||||||
create: { name: 'Tamina', password: taminaPassword },
|
create: { name: 'Tamina', password: taminaPassword },
|
||||||
})
|
})
|
||||||
console.log({ game, emmy, tamina })
|
console.log({ emmy, tamina })
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
@ -8,10 +8,9 @@ import { ChallengesModule } from './challenges/challenges.module'
|
|||||||
import { ChallengeActionsModule } from './challenge-actions/challenge-actions.module'
|
import { ChallengeActionsModule } from './challenge-actions/challenge-actions.module'
|
||||||
import { TrainsModule } from './trains/trains.module'
|
import { TrainsModule } from './trains/trains.module'
|
||||||
import { MoneyUpdatesModule } from './money-updates/money-updates.module'
|
import { MoneyUpdatesModule } from './money-updates/money-updates.module'
|
||||||
import { GameModule } from './game/game.module'
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [PrismaModule, AuthModule, PlayersModule, GameModule, GeolocationsModule, ChallengesModule, ChallengeActionsModule, TrainsModule, MoneyUpdatesModule],
|
imports: [PrismaModule, PlayersModule, AuthModule, GeolocationsModule, ChallengesModule, ChallengeActionsModule, TrainsModule, MoneyUpdatesModule],
|
||||||
providers: [PrismaService],
|
providers: [PrismaService],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
@ -4,8 +4,8 @@ import { ApiOkResponse, ApiTags } from '@nestjs/swagger'
|
|||||||
import { AuthEntity } from './entity/auth.entity'
|
import { AuthEntity } from './entity/auth.entity'
|
||||||
import { LoginDto } from './dto/login.dto'
|
import { LoginDto } from './dto/login.dto'
|
||||||
|
|
||||||
@ApiTags('auth')
|
|
||||||
@Controller('auth')
|
@Controller('auth')
|
||||||
|
@ApiTags('auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
constructor(private readonly authService: AuthService) {}
|
constructor(private readonly authService: AuthService) {}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async validate(payload: { playerId: number }): Promise<Player> {
|
async validate(payload: { playerId: number }): Promise<Player> {
|
||||||
|
console.log(payload)
|
||||||
const player = await this.playersService.findOne(payload.playerId)
|
const player = await this.playersService.findOne(payload.playerId)
|
||||||
if (!player) {
|
if (!player) {
|
||||||
throw new UnauthorizedException()
|
throw new UnauthorizedException()
|
||||||
|
@ -19,6 +19,7 @@ export class ChallengeActionsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findAll(queryPagination: QueryPaginationDto, filterChallengeActions: FilterChallengeActionsDto): Promise<[ChallengeAction[], number]> {
|
async findAll(queryPagination: QueryPaginationDto, filterChallengeActions: FilterChallengeActionsDto): Promise<[ChallengeAction[], number]> {
|
||||||
|
console.log(filterChallengeActions)
|
||||||
return [
|
return [
|
||||||
await this.prisma.challengeAction.findMany({
|
await this.prisma.challengeAction.findMany({
|
||||||
...paginate(queryPagination),
|
...paginate(queryPagination),
|
||||||
@ -35,6 +36,7 @@ export class ChallengeActionsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async update(id: number, updateChallengeActionDto: UpdateChallengeActionDto): Promise<ChallengeAction> {
|
async update(id: number, updateChallengeActionDto: UpdateChallengeActionDto): Promise<ChallengeAction> {
|
||||||
|
console.log(updateChallengeActionDto)
|
||||||
return await this.prisma.challengeAction.update({
|
return await this.prisma.challengeAction.update({
|
||||||
where: { id },
|
where: { id },
|
||||||
data: updateChallengeActionDto,
|
data: updateChallengeActionDto,
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
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()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,19 +0,0 @@
|
|||||||
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())
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
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 {}
|
|
@ -1,18 +0,0 @@
|
|||||||
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()
|
|
||||||
})
|
|
||||||
})
|
|
@ -1,11 +0,0 @@
|
|||||||
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,4 +18,7 @@ export class PlayerEntity implements Player {
|
|||||||
|
|
||||||
@ApiProperty({description: "Nombre de jetons dont dispose actuellement læ joueur⋅se"})
|
@ApiProperty({description: "Nombre de jetons dont dispose actuellement læ joueur⋅se"})
|
||||||
money: number
|
money: number
|
||||||
|
|
||||||
|
@ApiProperty({description: "Est-ce que cet⋅te joueur⋅se est cellui actuellement en course"})
|
||||||
|
currentRunner: boolean
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user