From 9af201b6f3f565efa83a05e54a7b6d3f159d5bd0 Mon Sep 17 00:00:00 2001 From: tudor <7089284+tudddorrr@users.noreply.github.com> Date: Mon, 28 Oct 2024 23:09:44 +0000 Subject: [PATCH] safer and more reliable player merging --- src/services/api/player-api.service.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/services/api/player-api.service.ts b/src/services/api/player-api.service.ts index c84fd55c..c0703cd8 100644 --- a/src/services/api/player-api.service.ts +++ b/src/services/api/player-api.service.ts @@ -190,7 +190,8 @@ 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) @@ -198,7 +199,8 @@ export default class PlayerAPIService extends APIService { 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,