Stockage des constants dans un fichier à part pour tout centraliser
This commit is contained in:
parent
a0fd6ca6ab
commit
4a4233925d
@ -6,6 +6,7 @@ import { PrismaService } from 'src/prisma/prisma.service'
|
|||||||
import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto'
|
import { QueryPaginationDto } from 'src/common/dto/pagination-query.dto'
|
||||||
import { paginate } from 'src/common/utils/pagination.utils'
|
import { paginate } from 'src/common/utils/pagination.utils'
|
||||||
import { FilterChallengeActionsDto } from './dto/filter-challenge-action.dto'
|
import { FilterChallengeActionsDto } from './dto/filter-challenge-action.dto'
|
||||||
|
import { Constants } from 'src/common/utils/constants.utils'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ChallengeActionsService {
|
export class ChallengeActionsService {
|
||||||
@ -87,7 +88,7 @@ export class ChallengeActionsService {
|
|||||||
active: false,
|
active: false,
|
||||||
end: now,
|
end: now,
|
||||||
penaltyStart: now,
|
penaltyStart: now,
|
||||||
penaltyEnd: new Date(now.getTime() + 30 * 60 * 1000),
|
penaltyEnd: new Date(now.getTime() + Constants.PENALTY_TIME * 60 * 1000),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return await this.prisma.challengeAction.update({
|
return await this.prisma.challengeAction.update({
|
||||||
|
21
server/src/common/utils/constants.utils.ts
Normal file
21
server/src/common/utils/constants.utils.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
export const Constants = {
|
||||||
|
/**
|
||||||
|
* Nombre de points attribués au début de la partie
|
||||||
|
*/
|
||||||
|
INITIAL_MONEY: 2000,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nombre de points attribués lors d'une nouvelle tentative
|
||||||
|
*/
|
||||||
|
NEW_RUN_MONEY: 300,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Nombre de points requis pour l'achat d'un train par kilomètre (arrondi au supérieur)
|
||||||
|
*/
|
||||||
|
PRICE_PER_KILOMETER: 10,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Temps de pénalité en minutes en cas d'échec d'un défi
|
||||||
|
*/
|
||||||
|
PENALTY_TIME: 30,
|
||||||
|
}
|
@ -2,6 +2,7 @@ import { ConflictException, Injectable } from '@nestjs/common'
|
|||||||
import { Game, MoneyUpdate, MoneyUpdateType } from '@prisma/client'
|
import { Game, MoneyUpdate, MoneyUpdateType } from '@prisma/client'
|
||||||
import { PrismaService } from 'src/prisma/prisma.service'
|
import { PrismaService } from 'src/prisma/prisma.service'
|
||||||
import { RepairGame } from './dto/repair-game.dto'
|
import { RepairGame } from './dto/repair-game.dto'
|
||||||
|
import { Constants } from 'src/common/utils/constants.utils'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GameService {
|
export class GameService {
|
||||||
@ -23,7 +24,7 @@ export class GameService {
|
|||||||
await this.prisma.moneyUpdate.create({
|
await this.prisma.moneyUpdate.create({
|
||||||
data: {
|
data: {
|
||||||
playerId: player.id,
|
playerId: player.id,
|
||||||
amount: 2000,
|
amount: Constants.INITIAL_MONEY,
|
||||||
reason: MoneyUpdateType.START,
|
reason: MoneyUpdateType.START,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -87,7 +88,7 @@ export class GameService {
|
|||||||
await this.prisma.moneyUpdate.create({
|
await this.prisma.moneyUpdate.create({
|
||||||
data: {
|
data: {
|
||||||
playerId: newRunnerId,
|
playerId: newRunnerId,
|
||||||
amount: 300,
|
amount: Constants.NEW_RUN_MONEY,
|
||||||
reason: MoneyUpdateType.NEW_RUN,
|
reason: MoneyUpdateType.NEW_RUN,
|
||||||
runId: newRun.id,
|
runId: newRun.id,
|
||||||
}
|
}
|
||||||
@ -139,7 +140,7 @@ export class GameService {
|
|||||||
const trainMoneyUpdate = await this.prisma.moneyUpdate.create({
|
const trainMoneyUpdate = await this.prisma.moneyUpdate.create({
|
||||||
data: {
|
data: {
|
||||||
playerId: train.playerId,
|
playerId: train.playerId,
|
||||||
amount: -10 * Math.ceil(train.distance / 1000),
|
amount: -Constants.PRICE_PER_KILOMETER * Math.ceil(train.distance / 1000),
|
||||||
reason: MoneyUpdateType.BUY_TRAIN,
|
reason: MoneyUpdateType.BUY_TRAIN,
|
||||||
tripId: train.id,
|
tripId: train.id,
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import { ImportTrainDto } from './dto/import-train.dto'
|
|||||||
import { InterrailJourney, InterrailLegInfo, InterrailTravelInfo } from './dto/interrail-api.dto'
|
import { InterrailJourney, InterrailLegInfo, InterrailTravelInfo } from './dto/interrail-api.dto'
|
||||||
import { distanceCoordinates } from 'src/common/utils/calculus.utils'
|
import { distanceCoordinates } from 'src/common/utils/calculus.utils'
|
||||||
import { PlayerFilterDto } from 'src/common/dto/player_filter.dto'
|
import { PlayerFilterDto } from 'src/common/dto/player_filter.dto'
|
||||||
|
import { Constants } from 'src/common/utils/constants.utils'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TrainsService {
|
export class TrainsService {
|
||||||
@ -87,7 +88,7 @@ export class TrainsService {
|
|||||||
const oldCoordinates = legInfoJson.trainStopStations.at(index - 1).coordinates
|
const oldCoordinates = legInfoJson.trainStopStations.at(index - 1).coordinates
|
||||||
return distance + distanceCoordinates({ from: oldCoordinates, to: coordinates })
|
return distance + distanceCoordinates({ from: oldCoordinates, to: coordinates })
|
||||||
}, 0)
|
}, 0)
|
||||||
const cost = 10 * 10 * Math.ceil(distance / 1000)
|
const cost = Constants.PRICE_PER_KILOMETER * Math.ceil(distance / 1000)
|
||||||
|
|
||||||
const train = await this.prisma.trainTrip.create({
|
const train = await this.prisma.trainTrip.create({
|
||||||
data: {
|
data: {
|
||||||
|
Loading…
Reference in New Issue
Block a user