fix(cards): éviter save() qui nullifie id_card des responses
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 <cursoragent@cursor.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user