-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateTaskQuery.ts
39 lines (36 loc) · 973 Bytes
/
createTaskQuery.ts
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
import e from '../edgedb/builder'
export const createTaskQuery = e.params(
{
title: e.str,
dueAt: e.optional(e.datetime),
deadline: e.optional(e.cal.date_duration),
assignees: e.array(e.uuid),
},
({ assignees, dueAt, deadline, ...params }) => {
const task = e.insert(e.Task, {
...params,
dueAt: e.op(
e.op(e.datetime_current(), '+', deadline),
'if',
e.op('exists', deadline),
'else',
e.op(
dueAt,
'if',
e.op('exists', dueAt),
'else',
e.op(e.datetime_current(), '+', e.cal.date_duration('2 weeks'))
)
),
assignees: e.select(e.User, (u) => ({
filter: e.op(u.id, 'in', e.array_unpack(assignees)),
})),
})
const action = e.insert(e.TaskAction, {
kind: e.TaskActionKind.Opened,
user: e.global.currentUser,
task,
})
return e.with([task, action], e.select({ task, action }))
}
)