feat(children): generalize CreateChildAsync for any parent + CreatedBy stamp
This commit is contained in:
@@ -196,6 +196,7 @@ public sealed class TaskRepository
|
||||
string title,
|
||||
string? description,
|
||||
string? commitType,
|
||||
string? createdBy = null,
|
||||
CancellationToken ct = default)
|
||||
{
|
||||
// AsNoTracking: SetPlanningStartedAsync mutates via ExecuteUpdate which
|
||||
@@ -204,9 +205,6 @@ public sealed class TaskRepository
|
||||
.FirstOrDefaultAsync(t => t.Id == parentId, ct);
|
||||
if (parent is null)
|
||||
throw new InvalidOperationException($"Parent task {parentId} not found.");
|
||||
if (parent.PlanningPhase == PlanningPhase.None)
|
||||
throw new InvalidOperationException(
|
||||
$"Parent task {parentId} is not in a planning phase; cannot attach children.");
|
||||
|
||||
var maxSort = await _context.Tasks
|
||||
.Where(t => t.ListId == parent.ListId)
|
||||
@@ -224,6 +222,7 @@ public sealed class TaskRepository
|
||||
CommitType = string.IsNullOrEmpty(commitType) ? parent.CommitType : commitType,
|
||||
ParentTaskId = parentId,
|
||||
SortOrder = (maxSort ?? -1) + 1,
|
||||
CreatedBy = createdBy,
|
||||
};
|
||||
_context.Tasks.Add(child);
|
||||
await _context.SaveChangesAsync(ct);
|
||||
|
||||
Reference in New Issue
Block a user