diff --git a/src/entities/organisation.ts b/src/entities/organisation.ts index 9364a46a..f4b772fe 100644 --- a/src/entities/organisation.ts +++ b/src/entities/organisation.ts @@ -13,7 +13,7 @@ export default class Organisation { @Property() name!: string - @OneToMany(() => Game, (game) => game.organisation, { eager: true }) + @OneToMany(() => Game, (game) => game.organisation) games = new Collection(this) @OneToOne({ orphanRemoval: true, eager: true }) diff --git a/src/policies/policy.ts b/src/policies/policy.ts index 85e339ca..6470280c 100644 --- a/src/policies/policy.ts +++ b/src/policies/policy.ts @@ -40,9 +40,9 @@ export default class Policy extends ServicePolicy { } async canAccessGame(gameId: number): Promise { - const game = await this.em.getRepository(Game).findOne(gameId, { + const game = await this.em.repo(Game).findOne(gameId, { ...getResultCacheOptions(`can-access-game-${gameId}`), - populate: ['organisation'] + populate: ['organisation.id'] }) if (!game) this.ctx.throw(404, 'Game not found') diff --git a/src/services/user.service.ts b/src/services/user.service.ts index bfe66521..ac8b14fd 100644 --- a/src/services/user.service.ts +++ b/src/services/user.service.ts @@ -91,7 +91,10 @@ export default class UserService extends Service { path: '/me' }) async me(req: Request): Promise { + const em: EntityManager = req.ctx.em const user = await getUserFromToken(req.ctx) + // cache doesn't include the full organisation + await em.populate(user, ['organisation.games']) return { status: 200, diff --git a/tests/services/_api/game-channel-api/members.test.ts b/tests/services/_api/game-channel-api/members.test.ts index 1d1a24d4..4a2e9c5d 100644 --- a/tests/services/_api/game-channel-api/members.test.ts +++ b/tests/services/_api/game-channel-api/members.test.ts @@ -313,7 +313,7 @@ describe('Game channel API service - members', () => { it('should filter by player groups', async () => { const [apiKey, token] = await createAPIKeyAndToken([APIKeyScope.READ_GAME_CHANNELS]) - const rule = new PlayerGroupRule(PlayerGroupRuleName.GTE, 'props.currentLevel') + const rule = new PlayerGroupRule(PlayerGroupRuleName.GTE, 'props.someRandomProp') rule.castType = PlayerGroupRuleCastType.DOUBLE rule.operands = ['60'] @@ -324,7 +324,7 @@ describe('Game channel API service - members', () => { const player = await new PlayerFactory([apiKey.game]).state((player) => ({ props: new Collection(player, [ - new PlayerProp(player, 'currentLevel', '60') + new PlayerProp(player, 'someRandomProp', '60') ]) })).one() const otherPlayer = await new PlayerFactory([apiKey.game]).one()