(input: TaskCreationDataInput)
| 38 | } |
| 39 | |
| 40 | export function buildTaskCreationData(input: TaskCreationDataInput): TaskCreationData { |
| 41 | const now = getCurrentTimestamp(); |
| 42 | const contextList = input.contexts |
| 43 | .split(",") |
| 44 | .map((context) => context.trim()) |
| 45 | .filter((context) => context.length > 0); |
| 46 | const projectList = splitListPreservingLinksAndQuotes(input.projects); |
| 47 | const tagList = sanitizeTags(input.tags) |
| 48 | .split(",") |
| 49 | .map((tag) => tag.trim()) |
| 50 | .filter((tag) => tag.length > 0); |
| 51 | |
| 52 | if ( |
| 53 | input.taskIdentificationMethod === "tag" && |
| 54 | input.taskTag && |
| 55 | !tagList.includes(input.taskTag) |
| 56 | ) { |
| 57 | tagList.push(input.taskTag); |
| 58 | } |
| 59 | |
| 60 | const taskData: TaskCreationData = { |
| 61 | title: input.title.trim(), |
| 62 | due: input.dueDate || undefined, |
| 63 | scheduled: input.scheduledDate || undefined, |
| 64 | priority: input.priority, |
| 65 | status: input.status, |
| 66 | contexts: contextList.length > 0 ? contextList : undefined, |
| 67 | projects: projectList.length > 0 ? projectList : undefined, |
| 68 | tags: tagList.length > 0 ? tagList : undefined, |
| 69 | timeEstimate: input.timeEstimate > 0 ? input.timeEstimate : undefined, |
| 70 | recurrence: input.recurrenceRule || undefined, |
| 71 | recurrence_anchor: input.recurrenceRule ? input.recurrenceAnchor : undefined, |
| 72 | reminders: input.reminders.length > 0 ? input.reminders : undefined, |
| 73 | creationContext: input.creationContext || "manual-creation", |
| 74 | dateCreated: now, |
| 75 | dateModified: now, |
| 76 | customFrontmatter: buildCustomFrontmatter(input.userFields), |
| 77 | }; |
| 78 | |
| 79 | const blockedDependencies = input.blockedByItems.map((item) => ({ |
| 80 | ...item.dependency, |
| 81 | })); |
| 82 | if (blockedDependencies.length > 0) { |
| 83 | taskData.blockedBy = blockedDependencies; |
| 84 | } |
| 85 | |
| 86 | const normalizedDetails = input.normalizeDetails(input.details).trimEnd(); |
| 87 | if (normalizedDetails.length > 0) { |
| 88 | taskData.details = normalizedDetails; |
| 89 | } |
| 90 | |
| 91 | return taskData; |
| 92 | } |
| 93 | |
| 94 | export function buildCreationBlockingUpdates( |
| 95 | blockingItems: DependencyItem[] |
no test coverage detected