From 608e62d6620c05934d49900112907ad269a93fa0 Mon Sep 17 00:00:00 2001 From: Julien Martin Date: Mon, 5 Oct 2026 15:17:08 +0200 Subject: [PATCH] =?UTF-8?q?fix(cards):=20=C3=A9viter=20save()=20qui=20null?= =?UTF-8?q?ifie=20id=5Fcard=20des=20responses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TypeORM resynchronisait les relations au save(card) après accept/refuse et faisait UPDATE card_responses SET id_card=null → 500. Co-authored-by: Cursor --- backend/src/modules/cards/cards.service.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/src/modules/cards/cards.service.ts b/backend/src/modules/cards/cards.service.ts index de315df..29a8ba2 100644 --- a/backend/src/modules/cards/cards.service.ts +++ b/backend/src/modules/cards/cards.service.ts @@ -252,7 +252,12 @@ export class CardsService { } card.purge_at = this.purgeAt(card.type.retention_days, card.statut); - await this.cardsRepo.save(card); + // update() et non save() : save() avec relations responses/audience + // resynchronise les FK et tente UPDATE card_responses SET id_card=null. + await this.cardsRepo.update( + { id: card.id }, + { statut: card.statut, purge_at: card.purge_at }, + ); const full = await this.loadCard(cardId); const dtoOut = this.toDto(full, userId); this.emitAudience(full, 'response.added', { @@ -304,7 +309,12 @@ export class CardsService { }; card.statut = CardInstanceStatutType.OUVERTE; card.purge_at = this.purgeAt(card.type.retention_days, card.statut); - await this.cardsRepo.save(card); + await this.cardsRepo.manager.query( + `UPDATE card_instances + SET statut = $1, purge_at = $2, payload = $3::jsonb, modifie_le = now() + WHERE id = $4`, + [card.statut, card.purge_at, JSON.stringify(card.payload), card.id], + ); const full = await this.loadCard(cardId); const dtoOut = this.toDto(full, userId); this.emitAudience(full, 'card.updated', dtoOut);