// Separate closure because we need to wait for the results of the user search if users were entered in the
// task create request. Because _that_ happens in a promise, we'll need something to call when it resolves.
constcreateTask=()=>{
consttask=newTaskModel({
title:parsedTask.text,
listId:listId,
dueDate:parsedTask.date!==null?formatISO(parsedTask.date):null,// I don't know why, but it all goes up in flames when I just pass in the date normally.
priority:parsedTask.priority,
assignees:assignees,
bucketId:bucketId,
})
returnthis.taskService.create(task)
.then(task=>{
if(parsedTask.labels.length>0){
constlabelAddsToWaitFor=[]
constaddLabelToTask=label=>{
constlabelTask=newLabelTask({
taskId:task.id,
labelId:label.id,
})
returnthis.labelTaskService.create(labelTask)
.then(result=>{
task.labels.push(label)
returnPromise.resolve(result)
})
.catch(e=>Promise.reject(e))
}
// Then do everything that is involved in finding, creating and adding the label to the task