fix(cards): FK card_responses via relation JoinColumn + save(create)

Double mapping @Column/@JoinColumn sur id_card ; persist response via
card/user relations. Garde update() sur l’instance (évite save parent
qui nullifiait les FK enfants).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-05 15:18:43 +02:00
co-authored by Cursor
parent 608e62d662
commit 1d3ec0b759
3 changed files with 73 additions and 14 deletions
+10 -8
View File
@@ -227,12 +227,14 @@ export class CardsService {
throw new BadRequestException('Motivation obligatoire en cas de refus');
}
await this.responsesRepo.insert({
id_card: card.id,
id_utilisateur: userId,
action: dto.action,
comment: dto.comment?.trim() || undefined,
});
await this.responsesRepo.save(
this.responsesRepo.create({
card: { id: card.id },
user: { id: userId },
action: dto.action,
comment: dto.comment?.trim() || undefined,
}),
);
if (card.id_evenement) {
if (dto.action === CardResponseActionType.ACCEPT || dto.action === CardResponseActionType.ACK) {
@@ -252,8 +254,8 @@ export class CardsService {
}
card.purge_at = this.purgeAt(card.type.retention_days, card.statut);
// update() et non save() : save() avec relations responses/audience
// resynchronise les FK et tente UPDATE card_responses SET id_card=null.
// Ne pas cardsRepo.save(card) avec relations chargées : TypeORM peut
// resynchroniser les FK enfants (UPDATE … SET id_card=null).
await this.cardsRepo.update(
{ id: card.id },
{ statut: card.statut, purge_at: card.purge_at },