Compare commits
	
		
			2 Commits
		
	
	
		
			481400d404
			...
			a1b5fccc98
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a1b5fccc98 | |||
| 8681752888 | 
| @@ -1,7 +1,7 @@ | ||||
| import { BadRequestException, Injectable, NotFoundException, UnprocessableEntityException } from '@nestjs/common' | ||||
| import { BadRequestException, Injectable, NotFoundException } from '@nestjs/common' | ||||
| import { CreateChallengeActionDto } from './dto/create-challenge-action.dto' | ||||
| import { UpdateChallengeActionDto } from './dto/update-challenge-action.dto' | ||||
| import { ChallengeAction, Player } from '@prisma/client' | ||||
| import { ChallengeAction, MoneyUpdateType, Player } from '@prisma/client' | ||||
| import { PrismaService } from 'src/prisma/prisma.service' | ||||
| import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto' | ||||
| import { paginate } from 'src/common/utils/pagination.utils' | ||||
| @@ -68,6 +68,17 @@ export class ChallengeActionsService { | ||||
|         active: false, | ||||
|         end: now, | ||||
|       } | ||||
|  | ||||
|       // Crédit du nombre de points remportés grâce au défi | ||||
|       const challenge = await this.prisma.challenge.findUnique({ where: { id: challengeAction.challengeId } }) | ||||
|       await this.prisma.moneyUpdate.create({ | ||||
|         data: { | ||||
|           playerId: player.id, | ||||
|           amount: challenge.reward, | ||||
|           reason: MoneyUpdateType.WIN_CHALLENGE, | ||||
|           actionId: challengeAction.id, | ||||
|         } | ||||
|       }) | ||||
|     } | ||||
|     else { | ||||
|       data = { | ||||
|   | ||||
| @@ -27,7 +27,7 @@ export class GameService { | ||||
|         }) | ||||
|       } | ||||
|     } | ||||
|     const runnerId = alreadyStarted ? game.currentRunnerId : players[Math.trunc(players.length * Math.random())].id | ||||
|     const runnerId = alreadyStarted ? game.currentRunnerId : players[Math.floor(players.length * Math.random())].id | ||||
|     return await this.prisma.game.update({ | ||||
|       where: { id: 1 }, | ||||
|       data: { | ||||
|   | ||||
| @@ -95,6 +95,7 @@ export class TrainsController { | ||||
|    * Importation d'un trajet en train à partir de Rail Planner | ||||
|    *  | ||||
|    * @throws {401} Non authentifié⋅e | ||||
|    * @throws {409} Le voyage Interrail est déjà importé | ||||
|    * @throws {422} Le voyage Interrail à importer contient plusieurs trajets ou plusieurs trains | ||||
|    */ | ||||
|   @Post("/import") | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| import { Injectable, NotFoundException, UnprocessableEntityException } from '@nestjs/common' | ||||
| import { ConflictException, HttpException, Injectable, NotFoundException, UnprocessableEntityException } from '@nestjs/common' | ||||
| import { CreateTrainDto } from './dto/create-train.dto' | ||||
| import { UpdateTrainDto } from './dto/update-train.dto' | ||||
| import { PrismaService } from 'src/prisma/prisma.service' | ||||
| import { Player, TrainTrip } from '@prisma/client' | ||||
| import { MoneyUpdateType, Player, TrainTrip } from '@prisma/client' | ||||
| import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto' | ||||
| import { paginate } from 'src/common/utils/pagination.utils' | ||||
| import { ImportTrainDto } from './dto/import-train.dto' | ||||
| @@ -54,6 +54,9 @@ export class TrainsService { | ||||
|   } | ||||
|  | ||||
|   async import(player: Player, { id: trainId }: ImportTrainDto): Promise<TrainTrip> { | ||||
|     if (this.findOne(trainId)) | ||||
|       throw new ConflictException(`Le train avec l'identifiant ${trainId} est déjà importé`) | ||||
|  | ||||
|     const interrailResult: InterrailJourney = await fetch(`https://3uiwjsimnh.execute-api.eu-central-1.amazonaws.com/Prod/journey-import?id=${trainId}`) | ||||
|       .then(data => data.json()) | ||||
|     if (interrailResult.data.travels.length !== 1) | ||||
| @@ -80,12 +83,10 @@ export class TrainsService { | ||||
|           const oldCoordinates = legInfoJson.trainStopStations.at(index - 1).coordinates | ||||
|           return distance + distanceCoordinates({ from: oldCoordinates, to: coordinates }) | ||||
|         }, 0) | ||||
|     const cost = 10 * 10 * Math.ceil(distance / 1000) | ||||
|  | ||||
|     return this.prisma.trainTrip.upsert({ | ||||
|       where: { | ||||
|         id: trainId, | ||||
|       }, | ||||
|       create: { | ||||
|     const train = await this.prisma.trainTrip.create({ | ||||
|       data: { | ||||
|         id: trainId, | ||||
|         playerId: player.id, | ||||
|         distance: distance, | ||||
| @@ -95,15 +96,16 @@ export class TrainsService { | ||||
|         arrivalTime: arrival, | ||||
|         infoJson: leg.infoJson, | ||||
|       }, | ||||
|       update: { | ||||
|     }) | ||||
|     // Ajout du trajet en points | ||||
|     await this.prisma.moneyUpdate.create({ | ||||
|       data: { | ||||
|         playerId: player.id, | ||||
|         distance: distance, | ||||
|         from: travel.from, | ||||
|         to: travel.to, | ||||
|         departureTime: departure, | ||||
|         arrivalTime: arrival, | ||||
|         infoJson: leg.infoJson, | ||||
|         amount: -cost, | ||||
|         reason: MoneyUpdateType.BUY_TRAIN, | ||||
|         tripId: train.id, | ||||
|       } | ||||
|     }) | ||||
|     return train | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user