From 67fd88a08310daeb1bd60c73fcd5b0823c4db011 Mon Sep 17 00:00:00 2001 From: TaprootFreak <142087526+TaprootFreak@users.noreply.github.com> Date: Fri, 22 May 2026 11:36:33 +0200 Subject: [PATCH] fix: circular JSON in buyCrypto update response BuyCryptoController.update and manualPassAmlCheck returned the raw BuyCrypto entity loaded with transaction.userData.kycSteps. TypeORM populates the KycStep.userData inverse back-reference, producing a circular object graph that JSON.stringify rejects -> 500 on PUT /v1/buyCrypto/:id. The kycSteps relation is required by the update logic, so reload the entity without the cyclic userData collections for the response. --- .../process/services/buy-crypto.service.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/subdomains/core/buy-crypto/process/services/buy-crypto.service.ts b/src/subdomains/core/buy-crypto/process/services/buy-crypto.service.ts index 2fb3307965..4f9a46900b 100644 --- a/src/subdomains/core/buy-crypto/process/services/buy-crypto.service.ts +++ b/src/subdomains/core/buy-crypto/process/services/buy-crypto.service.ts @@ -414,7 +414,21 @@ export class BuyCryptoService implements OnModuleInit { await this.updateCryptoRouteVolume([cryptoRouteIdBefore, entity.cryptoRoute?.id]); if (dto.usedRef || dto.amountInEur) await this.updateRefVolume([usedRefBefore, entity.usedRef]); - return entity; + // reload without userData.kycSteps/users: TypeORM sets the inverse back-reference on those + // collections, producing a circular graph that breaks JSON serialization of the response + return this.buyCryptoRepo.findOne({ + where: { id }, + relations: { + buy: true, + cryptoRoute: true, + cryptoInput: true, + bankTx: true, + checkoutTx: true, + transaction: { user: { wallet: true }, userData: true }, + chargebackOutput: true, + bankData: true, + }, + }); } private async changeRoute(entity: BuyCrypto, route: Buy | Swap) {