Gestion des heures de fin des tentatives

This commit is contained in:
Emmy D'Anello 2024-12-08 22:49:47 +01:00
parent 50a9f3369c
commit 33689d9c76
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
3 changed files with 17 additions and 6 deletions

View File

@ -9,9 +9,10 @@ import { ChallengeActionsModule } from './challenge-actions/challenge-actions.mo
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' import { GameModule } from './game/game.module'
import { RunsModule } from './runs/runs.module'
@Module({ @Module({
imports: [PrismaModule, AuthModule, PlayersModule, GameModule, GeolocationsModule, ChallengesModule, ChallengeActionsModule, TrainsModule, MoneyUpdatesModule], imports: [PrismaModule, AuthModule, PlayersModule, GameModule, RunsModule, GeolocationsModule, ChallengesModule, ChallengeActionsModule, TrainsModule, MoneyUpdatesModule],
providers: [PrismaService], providers: [PrismaService],
}) })
export class AppModule {} export class AppModule {}

View File

@ -87,7 +87,7 @@ export class ChallengeActionsService {
active: false, active: false,
end: now, end: now,
penaltyStart: now, penaltyStart: now,
penaltyEnd: new Date(now.getTime() + 45 * 60 * 1000), penaltyEnd: new Date(now.getTime() + 30 * 60 * 1000),
} }
} }
return await this.prisma.challengeAction.update({ return await this.prisma.challengeAction.update({

View File

@ -37,7 +37,10 @@ export class GameService {
}) })
} }
else { else {
run = game.currentRun run = await this.prisma.playerRun.update({
where: { id: game.currentRunId },
data: { end: null },
})
} }
return await this.prisma.game.update({ return await this.prisma.game.update({
where: { id: 1 }, where: { id: 1 },
@ -66,6 +69,11 @@ export class GameService {
}, },
}) })
await this.prisma.playerRun.update({
where: { id: game.currentRunId },
data: { end: new Date() },
})
const newRunnerId = game.currentRun.runnerId == 1 ? 2 : 1 const newRunnerId = game.currentRun.runnerId == 1 ? 2 : 1
const firstRun = await this.prisma.playerRun.findFirst({ where: { runnerId: newRunnerId } }) !== null const firstRun = await this.prisma.playerRun.findFirst({ where: { runnerId: newRunnerId } }) !== null
const newRun = await this.prisma.playerRun.create({ const newRun = await this.prisma.playerRun.create({
@ -95,11 +103,13 @@ export class GameService {
const game = await this.find() const game = await this.find()
if (!game.started) if (!game.started)
throw new ConflictException("La partie n'a pas encore démarré.") throw new ConflictException("La partie n'a pas encore démarré.")
await this.prisma.playerRun.update({
where: { id: game.currentRunId },
data: { end: new Date() },
})
return await this.prisma.game.update({ return await this.prisma.game.update({
where: { id: 1 }, where: { id: 1 },
data: { data: { started: false },
started: false,
},
}) })
} }