Auto-close preceding active rounds when closing a later round
Some checks failed
Build and Push Docker Image / build (push) Has been cancelled

When closing round N, any active rounds with lower sortOrder in the
same competition are automatically closed. Each cascade closure is
recorded in DecisionAuditLog with closedBy: 'cascade' reference.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matt
2026-02-17 13:55:44 +01:00
parent b3b3bbb8b3
commit cf3c7631cb

View File

@@ -235,6 +235,42 @@ export async function closeRound(
// Expire pending intents // Expire pending intents
await expireIntentsForRound(roundId, actorId) await expireIntentsForRound(roundId, actorId)
// Auto-close any preceding active rounds (lower sortOrder, same competition)
const precedingActiveRounds = await tx.round.findMany({
where: {
competitionId: round.competitionId,
sortOrder: { lt: round.sortOrder },
status: 'ROUND_ACTIVE',
},
orderBy: { sortOrder: 'asc' },
})
for (const prev of precedingActiveRounds) {
await tx.round.update({
where: { id: prev.id },
data: { status: 'ROUND_CLOSED' },
})
await tx.decisionAuditLog.create({
data: {
eventType: 'round.closed',
entityType: 'Round',
entityId: prev.id,
actorId,
detailsJson: {
roundName: prev.name,
roundType: prev.roundType,
previousStatus: 'ROUND_ACTIVE',
closedBy: 'cascade',
triggeringRoundId: roundId,
},
snapshotJson: {
timestamp: new Date().toISOString(),
emittedBy: 'round-engine',
},
},
})
}
await tx.decisionAuditLog.create({ await tx.decisionAuditLog.create({
data: { data: {
eventType: 'round.closed', eventType: 'round.closed',
@@ -245,6 +281,7 @@ export async function closeRound(
roundName: round.name, roundName: round.name,
roundType: round.roundType, roundType: round.roundType,
previousStatus: 'ROUND_ACTIVE', previousStatus: 'ROUND_ACTIVE',
cascadeClosed: precedingActiveRounds.map((r: any) => r.name),
}, },
snapshotJson: { snapshotJson: {
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),