-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaskmanager.js
75 lines (61 loc) · 2.3 KB
/
taskmanager.js
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
// task status -open, in-progress, peer-review, Resolve conflict, verified
class TaskManager {
constructor() {
this.defaultStatus = {
OPEN : "Open",
INPROGRESS:"InProgress",
PEERREVIEW:"PeerReview",
RESOLVECONFLICT:"ResolveConflict",
VERIFIED:"Verified"
}
this.userDefinedStatus = {}
this.defaultTransitions = {
"Open": ["InProgress"],
"InProgress": ["PeerReview", "ResolveConflict"],
"PeerReview": ["ResolveConflict", "Verified"],
"ResolveConflict": ["InProgress", "PeerReview"],
"Verified": []
};
this.customTransistions = {};
this.defaultTransitionsEnabled = true
}
addUserDefinedStatus(name) {
// Once user defined staus is added, new transistions should be addded, so defaultTransitionsEnabled is set as false here
if (!name || typeof name != 'string') {
throw new Error('Invalid Status')
}
this.defaultTransitionsEnabled = false
this.userDefinedStatus[name.toUpperCase()] = name
}
getAllStatus() {
return [...Object.entries(this.defaultStatus),...Object.entries(this.userDefinedStatus)]
}
setCustomTransistions(key,value) {
let allStatues = this.getAllStatus()
// has objects or dictionaries
// check if the key and value are valid statuses then add it
// Since we will be showing the list of available transistions, should i validate it?
if(this.validStatus(key) && this.validStatus(value)) {
if (!this.customTransistions[key]) {
this.customTransistions[key] = [value]
} else {
this.customTransistions[key].push(value)
}
}
}
getValidTransistion(status) {
if (this.validStatus(status) && !this.defaultTransitionsEnabled) {
return this.customTransistions[status]
} else {
return this.defaultTransitions[status]
}
}
validStatus(status) {
let inputStatus = status.toUpperCase()
let allStatues = this.getAllStatus()
return allStatues.some(([key,value])=> key === inputStatus || value === inputStatus)
}
makeTransactions() {
}
}
module.exports = TaskManager;