Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Commit dd314c7

Browse files
committed
refactor: update aggregation pipeline in BadgeRepository and add localField in UserService
1 parent a2b746c commit dd314c7

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/repositories/BadgeRepository.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ export class BadgeRepository {
3737
const db = await this.databaseService.getDb();
3838
const result = await db.collection('game_badges').aggregate([
3939
{ $match: { gameId: gameId, expires_at: { $gt: new Date() } } },
40+
// use pipeline style lookup to avoid driver errors and give us more control
4041
{ $lookup: {
4142
from: 'badge_types',
42-
localField: 'badgeId',
43-
foreignField: 'id',
43+
let: { badgeId: '$badgeId' },
44+
pipeline: [
45+
{ $match: { $expr: { $eq: ['$id', '$$badgeId'] } } }
46+
],
4447
as: 'badge_info'
4548
}
4649
},

src/services/UserService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ export class UserService implements IUserService {
268268
{
269269
$lookup: {
270270
from: 'items',
271+
localField: 'item_id',
271272
foreignField: 'itemId',
272273
as: 'item'
273274
}

0 commit comments

Comments
 (0)