Skip to content

Commit

Permalink
safer and more reliable player merging
Browse files Browse the repository at this point in the history
  • Loading branch information
tudddorrr committed Oct 28, 2024
1 parent 515d7c8 commit 9af201b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/services/api/player-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,17 @@ export default class PlayerAPIService extends APIService {
], (a, b) => a.key === b.key)

player1.setProps(mergedProps)
player2.aliases.getItems().forEach((alias) => alias.player = player1)
player1.aliases.add(player2.aliases)
player2.setProps([])

const saves = await em.getRepository(GameSave).find({ player: player2 })
saves.forEach((save) => save.player = player1)

const stats = await em.getRepository(PlayerGameStat).find({ player: player2 })
stats.forEach((stat) => stat.player = player1)

await em.removeAndFlush(player2)
await em.flush()
await em.getRepository(Player).nativeDelete(player2)

return {
status: 200,
Expand Down

0 comments on commit 9af201b

Please sign in to comment.