-
Notifications
You must be signed in to change notification settings - Fork 0
/
lowlevel.go
72 lines (64 loc) · 1.69 KB
/
lowlevel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package statemanager
import (
"context"
"github.com/minskylab/tisp"
p "github.com/minskylab/tisp/repository"
)
func (db *StateManager) constructTaskTree(task tisp.NewTaskInformation) (*p.Task, error) {
var leader *p.ResourceCreateOneWithoutTaskLeaderOfInput
if task.Leader != nil {
leader = &p.ResourceCreateOneWithoutTaskLeaderOfInput{
Connect: &p.ResourceWhereUniqueInput{
ID: p.Str(*task.Leader),
},
}
}
var resourcesInput *p.ResourceCreateManyWithoutWorkingOnInput
if task.Resources != nil {
resources := make([]p.ResourceWhereUniqueInput, 0)
for _, id := range *task.Resources {
resources = append(resources, p.ResourceWhereUniqueInput{
ID: p.Str(id),
})
}
resourcesInput = &p.ResourceCreateManyWithoutWorkingOnInput{
Connect: resources,
}
}
newTask, err := db.client.CreateTask(p.TaskCreateInput{
Selector: task.Selector,
Title: task.Title,
Description: task.Description,
Leader: leader,
Resources: resourcesInput,
}).Exec(context.Background())
if err != nil {
return nil, err
}
if task.Children != nil {
for _, c := range *task.Children {
var children *p.TaskUpdateManyWithoutParentInput
if c.Children != nil {
newChild, err := db.constructTaskTree(c)
if err != nil {
return nil, err
}
children = &p.TaskUpdateManyWithoutParentInput{
Connect: []p.TaskWhereUniqueInput{
{ID: p.Str(newChild.ID)},
},
}
}
_, err := db.client.UpdateTask(p.TaskUpdateParams{
Where: p.TaskWhereUniqueInput{ID: p.Str(newTask.ID)},
Data: p.TaskUpdateInput{
Children: children,
},
}).Exec(context.Background())
if err != nil {
return nil, err
}
}
}
return newTask, nil
}