-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskStatusQuery.ts
41 lines (38 loc) · 1.01 KB
/
taskStatusQuery.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
40
41
import e from '../edgedb/builder'
export const schemaTaskStatusQuery = e.params({ id: e.uuid }, ({ id }) =>
e.select(e.Task, () => ({
status: true,
filter_single: { id },
}))
)
export const taskStatusQuery = e.params({ id: e.uuid }, ({ id }) => {
const lastAction = e.select(e.Task['<task[is TaskAction]'], (action) => ({
order_by: {
expression: action.createdAt,
direction: e.DESC,
},
limit: 1,
}))
return e.with(
[lastAction],
e.select(e.Task, (task) => ({
// TODO: should infer Cardinality.One without need for assert_single
computedStatus: e.assert_single(
e.op(
e.TaskStatus.Completed,
'if',
e.op(lastAction.kind, '=', e.TaskActionKind.Closed),
'else',
e.op(
e.TaskStatus.PastDue,
'if',
e.op(task.dueAt, '<=', e.datetime_of_statement()),
'else',
e.TaskStatus.InProgress
)
)
),
filter_single: { id },
}))
)
})