Skip to content

Commit

Permalink
refactor: Move some lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Clashsoft committed Jun 16, 2024
1 parent b0698cb commit 6a0ea3b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/system/system.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ export class SystemService extends MongooseRepository<System> {
const {upgrade, districts, buildings, ...rest} = dto;
system.set(rest);
if (upgrade) {
const upgrades = Object.keys(SYSTEM_UPGRADES);
if (upgrades.indexOf(upgrade) !== upgrades.indexOf(system.upgrade) + 1) {
throw new BadRequestException(`Invalid upgrade ${upgrade} for system ${system._id}`);
}
await this.upgradeSystem(system, upgrade, empire);
}
if (districts) {
Expand All @@ -62,6 +58,11 @@ export class SystemService extends MongooseRepository<System> {
}

private async upgradeSystem(system: SystemDocument, upgrade: SystemUpgradeName, empire: EmpireDocument) {
const upgrades = Object.keys(SYSTEM_UPGRADES);
if (upgrades.indexOf(upgrade) !== upgrades.indexOf(system.upgrade) + 1) {
throw new BadRequestException(`Invalid upgrade ${upgrade} for system ${system._id}`);
}

system.upgrade = upgrade;
system.capacity *= SYSTEM_UPGRADES[upgrade].capacity_multiplier;

Expand Down

0 comments on commit 6a0ea3b

Please sign in to comment.