Skip to content

Commit

Permalink
fix: removing gameserver-specific expired roles (#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
niekcandaele authored Jul 18, 2024
1 parent 89c0a5b commit ee84917
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/app-api/src/db/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,14 @@ export class PlayerRepo extends ITakaroRepo<PlayerModel, PlayerOutputDTO, Player
whereObj.gameServerId = null;
}

await roleOnPlayerModel.query().delete().where(whereObj);
const res = await roleOnPlayerModel.query().delete().where(whereObj);
if (res === 0) {
this.log.warn(`Tried to remove role from player ${playerId} but it was not assigned`, {
roleId,
gameServerId,
playerId,
});
}
}

async getPlayersToRefreshSteam(): Promise<string[]> {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-api/src/service/PlayerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class PlayerService extends TakaroService<PlayerModel, PlayerOutputDTO, P
const expired = player.roleAssignments.filter((item) => item.expiresAt && new Date(item.expiresAt) < now);

if (expired.length) this.log.info('Removing expired roles', { expired: expired.map((item) => item.roleId) });
await Promise.all(expired.map((item) => this.removeRole(item.roleId, player.id)));
await Promise.all(expired.map((item) => this.removeRole(item.roleId, player.id, item.gameServerId)));

// Delete expired roles from original object
player.roleAssignments = player.roleAssignments.filter((item) => !expired.includes(item));
Expand Down

0 comments on commit ee84917

Please sign in to comment.