Skip to content

Commit

Permalink
fix(api): internal ids for market and fight should work better
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Sep 14, 2023
1 parent 417fe1c commit 32204ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
15 changes: 4 additions & 11 deletions server/src/modules/fight/fight.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TrackedStat,
UserResponse,
} from '@interfaces';
import { EntityManager, EntityRepository, ObjectId } from '@mikro-orm/mongodb';
import { EntityManager, EntityRepository } from '@mikro-orm/mongodb';
import { InjectRepository } from '@mikro-orm/nestjs';
import { ConstantsService } from '@modules/content/constants.service';
import { ContentService } from '@modules/content/content.service';
Expand Down Expand Up @@ -90,7 +90,7 @@ export class FightService {
}

public async getFightById(fightId: string): Promise<Fight | null> {
return this.fights.findOne({ _id: new ObjectId(fightId) });
return this.fights.findOne({ internalId: fightId });
}

public async getFightForUser(userId: string): Promise<Fight | null> {
Expand Down Expand Up @@ -126,13 +126,6 @@ export class FightService {
return this.em.remove<Fight>(fight);
}

public async removeFightById(fightId: string) {
const fight = await this.getFightById(fightId);
if (!fight) return;

return this.removeFight(fight);
}

private async convertPlayerToFightCharacter(
player: Player,
): Promise<IFightCharacter> {
Expand Down Expand Up @@ -271,7 +264,7 @@ export class FightService {
}

async endFight(fight: Fight, actions: any[] = []): Promise<void> {
const checkFight = await this.getFightById(fight.id);
const checkFight = await this.getFightById(fight.internalId);
if (!checkFight) return;

this.logger.verbose(`Ending fight ${fight._id}`);
Expand Down Expand Up @@ -853,7 +846,7 @@ export class FightService {
}

async saveFight(fight: Fight): Promise<void> {
await this.em.nativeUpdate(Fight, { _id: new ObjectId(fight.id) }, fight);
await this.em.nativeUpdate(Fight, { internalId: fight.internalId }, fight);
await this.em.flush();
}

Expand Down
12 changes: 6 additions & 6 deletions server/src/modules/market/market.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
IPagination,
UserResponse,
} from '@interfaces';
import { EntityManager, EntityRepository, ObjectId } from '@mikro-orm/mongodb';
import { EntityManager, EntityRepository } from '@mikro-orm/mongodb';
import { InjectRepository } from '@mikro-orm/nestjs';
import { ContentService } from '@modules/content/content.service';
import { PlayerHelperService } from '@modules/content/playerhelper.service';
Expand Down Expand Up @@ -279,7 +279,7 @@ export class MarketService {
const items = await this.marketItem.find(resultQuery, {
limit,
offset: page * limit,
fields: ['_id', 'itemId', 'price', 'quantity'],
fields: ['internalId', 'itemId', 'price', 'quantity'],
});

return {
Expand Down Expand Up @@ -335,7 +335,7 @@ export class MarketService {

async buyItem(userId: string, listingId: string): Promise<UserResponse> {
const listing = await this.marketItem.findOne({
_id: new ObjectId(listingId),
internalId: listingId,
});
if (!listing) throw new NotFoundException('Listing not found');

Expand Down Expand Up @@ -435,7 +435,7 @@ export class MarketService {
if (!user) throw new NotFoundException('User not found');

const listing = await this.marketItem.findOne({
_id: new ObjectId(listingId),
internalId: listingId,
});
if (!listing) throw new NotFoundException('Listing not found');

Expand Down Expand Up @@ -504,7 +504,7 @@ export class MarketService {
if (!user) throw new NotFoundException('User not found');

const listing = await this.marketItem.findOne({
_id: new ObjectId(listingId),
internalId: listingId,
});
if (!listing) throw new NotFoundException('Listing not found');

Expand All @@ -527,7 +527,7 @@ export class MarketService {
}

await this.em.nativeDelete<MarketItem>(MarketItem, {
_id: new ObjectId(listingId),
internalId: listingId,
});

this.logger.verbose(`User ${userId} unlisted ${listing.itemId}.`);
Expand Down

0 comments on commit 32204ac

Please sign in to comment.