Skip to content

Commit 9af201b

Browse files
committed
safer and more reliable player merging
1 parent 515d7c8 commit 9af201b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/services/api/player-api.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,17 @@ export default class PlayerAPIService extends APIService {
190190
], (a, b) => a.key === b.key)
191191

192192
player1.setProps(mergedProps)
193-
player2.aliases.getItems().forEach((alias) => alias.player = player1)
193+
player1.aliases.add(player2.aliases)
194+
player2.setProps([])
194195

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

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

201-
await em.removeAndFlush(player2)
202+
await em.flush()
203+
await em.getRepository(Player).nativeDelete(player2)
202204

203205
return {
204206
status: 200,

0 commit comments

Comments
 (0)