-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathoperation.model.ts
More file actions
119 lines (102 loc) · 2.71 KB
/
operation.model.ts
File metadata and controls
119 lines (102 loc) · 2.71 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {Node} from "./node.model";
import {Trainrun} from "./trainrun.model";
import {Label} from "./label.model";
import {Note} from "./note.model";
import {
FreeFloatingTextDto,
LabelDto,
NodeDto,
TrainrunDto,
} from "../data-structures/business.data.structures";
enum OperationType {
create = "create",
update = "update",
delete = "delete",
}
enum OperationObjectType {
trainrun = "trainrun",
node = "node",
label = "label",
note = "note",
}
abstract class Operation {
readonly type: OperationType;
readonly objectType: OperationObjectType;
constructor(type: OperationType, objectType: OperationObjectType) {
this.type = type;
this.objectType = objectType;
}
}
abstract class TrainrunOperation extends Operation {
readonly trainrun: TrainrunDto;
constructor(operationType: OperationType, trainrun: Trainrun) {
super(operationType, OperationObjectType.trainrun);
this.trainrun = trainrun.getDto();
}
}
type TrainrunUpdateTag =
| "nodes"
| "times"
| "numberOfStops"
| "name"
| "categoryId"
| "frequencyId"
| "timeCategoryId"
| "labelIds"
| "direction";
class TrainrunUpdateOperation extends TrainrunOperation {
readonly tags: TrainrunUpdateTag[];
readonly oneWayDirection?: "forward" | "backward";
constructor(
trainrun: Trainrun,
tags: TrainrunUpdateTag[],
oneWayDirection?: "forward" | "backward",
) {
super(OperationType.update, trainrun);
this.tags = tags;
this.oneWayDirection = oneWayDirection;
}
}
class TrainrunCreateOperation extends TrainrunOperation {
readonly duplicatedTrainrunId?: number;
constructor(trainrun: Trainrun, duplicatedTrainrunId?: number) {
super(OperationType.create, trainrun);
this.duplicatedTrainrunId = duplicatedTrainrunId;
}
}
class TrainrunDeleteOperation extends TrainrunOperation {
constructor(trainrun: Trainrun) {
super(OperationType.delete, trainrun);
}
}
class NodeOperation extends Operation {
readonly node: NodeDto;
constructor(operationType: OperationType, node: Node) {
super(operationType, OperationObjectType.node);
this.node = node.getDto();
}
}
class LabelOperation extends Operation {
readonly label: LabelDto;
constructor(operationType: OperationType, label: Label) {
super(operationType, OperationObjectType.label);
this.label = label.getDto();
}
}
class NoteOperation extends Operation {
readonly note: FreeFloatingTextDto;
constructor(operationType: OperationType, note: Note) {
super(operationType, OperationObjectType.note);
this.note = note.getDto();
}
}
export {
OperationType,
Operation,
TrainrunUpdateOperation,
TrainrunCreateOperation,
TrainrunDeleteOperation,
NodeOperation,
LabelOperation,
NoteOperation,
};