fix: Add changeset reconciliation to deleteTask and fix missing invalidation
Same orphaned-changeset pattern as deletePhase: manually deleting all tasks from a detail changeset now marks it reverted. Also added deleteTask to the invalidation map (was missing entirely).
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
requireInitiativeRepository,
|
||||
requirePhaseRepository,
|
||||
requireDispatchManager,
|
||||
requireChangeSetRepository,
|
||||
} from './_helpers.js';
|
||||
|
||||
export function taskProcedures(publicProcedure: ProcedureBuilder) {
|
||||
@@ -152,6 +153,29 @@ export function taskProcedures(publicProcedure: ProcedureBuilder) {
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const taskRepository = requireTaskRepository(ctx);
|
||||
await taskRepository.delete(input.id);
|
||||
|
||||
// Reconcile any applied changesets that created this task.
|
||||
// If all created tasks in a changeset are now deleted, mark it reverted.
|
||||
if (ctx.changeSetRepository) {
|
||||
try {
|
||||
const csRepo = requireChangeSetRepository(ctx);
|
||||
const affectedChangeSets = await csRepo.findAppliedByCreatedEntity('task', input.id);
|
||||
for (const cs of affectedChangeSets) {
|
||||
const createdTaskIds = cs.entries
|
||||
.filter(e => e.entityType === 'task' && e.action === 'create')
|
||||
.map(e => e.entityId);
|
||||
const survivingTasks = await Promise.all(
|
||||
createdTaskIds.map(id => taskRepository.findById(id)),
|
||||
);
|
||||
if (survivingTasks.every(t => t === null)) {
|
||||
await csRepo.markReverted(cs.id);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Best-effort reconciliation — don't fail the delete
|
||||
}
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
}),
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ const INVALIDATION_MAP: Partial<Record<MutationName, QueryName[]>> = {
|
||||
createChildTasks: ["listTasks", "listInitiativeTasks", "listPhaseTasks"],
|
||||
queueTask: ["listTasks", "listInitiativeTasks", "listPhaseTasks"],
|
||||
|
||||
deleteTask: ["listTasks", "listInitiativeTasks", "listPhaseTasks", "listChangeSets"],
|
||||
|
||||
// --- Change Sets ---
|
||||
revertChangeSet: ["listPhases", "listPhaseTasks", "listInitiativeTasks", "listPages", "getPage", "listChangeSets", "getRootPage"],
|
||||
|
||||
|
||||
Reference in New Issue
Block a user