-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.esdl
81 lines (64 loc) · 2.49 KB
/
default.esdl
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
73
74
75
76
77
78
79
80
81
module default {
global currentUserId -> uuid;
global currentUser := (
select User filter .id = global currentUserId
);
abstract type Timestamps {
required property createdAt -> datetime {
default := datetime_of_transaction();
readonly := true;
};
required property updatedAt -> datetime {
default := datetime_of_transaction();
};
}
type User {
required property givenName -> str;
required property familyName -> str;
property name := .givenName ++ ' ' ++ .familyName;
}
type Task extending Timestamps {
required property title -> str;
required property dueAt -> datetime;
required multi link assignees -> User;
link lastAction := (select Task.<task[is TaskAction] order by .createdAt desc limit 1);
# datetime_of_statement is non-volatile (datetime_current will raise compilation error)
property status := (select
TaskStatus.Completed if .lastAction.kind = TaskActionKind.Closed else
TaskStatus.PastDue if .dueAt <= datetime_of_statement() else
TaskStatus.InProgress
);
link lastSeenEvent := (
select Task.<task[is TaskSeenEvent]
filter .user = global currentUser
order by .createdAt desc limit 1
);
link lastNotificationEvent := (
select Task.<task[is TaskNotificationEvent]
filter .user != global currentUser
order by .createdAt desc limit 1
);
property hasNotification := (
select .lastSeenEvent.createdAt < .lastNotificationEvent.createdAt if exists .lastSeenEvent else exists .lastNotificationEvent
);
}
scalar type TaskStatus extending enum<InProgress, PastDue, Completed>;
type TaskSeenEvent extending Timestamps {
annotation description := 'Tracks meta state when each user entered the task detail.';
required link task -> Task;
required link user -> User;
}
abstract type TaskNotificationEvent extending Timestamps {
annotation description := 'Task will have notification based on all subtype events compared with TaskSeenEvent.';
required link task -> Task;
required link user -> User;
}
scalar type TaskActionKind extending enum<Opened, Closed, Edited>;
type TaskAction extending TaskNotificationEvent {
required property kind -> TaskActionKind;
property reason -> str;
}
type TaskComment extending TaskNotificationEvent {
required property note -> str;
}
}