File tree Expand file tree Collapse file tree 2 files changed +91
-0
lines changed Expand file tree Collapse file tree 2 files changed +91
-0
lines changed Original file line number Diff line number Diff line change 21
21
/**
22
22
* @module history
23
23
* @requires db
24
+ * @requires log
24
25
* @description This module manages the history of all components lifecycle
25
26
*/
26
27
27
28
'use strict' ;
28
29
29
30
var $db = require ( './db.js' ) ;
31
+ var $log = require ( './log.js' ) ;
30
32
31
33
/* Private property */
32
34
@@ -93,9 +95,15 @@ exports.back = function back() {
93
95
$db [ state . collection ] . remove ( {
94
96
_id : state . id
95
97
} ) ;
98
+ $log . historyDocumentRemoved ( state . id , state . collection ) ;
96
99
break ;
97
100
case 'remove' :
98
101
$db [ state . collection ] . insert ( JSON . parse ( state . oldValue ) ) ;
102
+ $log . historyDocumentInserted (
103
+ state . id ,
104
+ state . collection ,
105
+ state . oldValue
106
+ ) ;
99
107
break ;
100
108
case 'update' :
101
109
update [ state . field ] = JSON . parse ( state . oldValue ) ;
@@ -106,6 +114,12 @@ exports.back = function back() {
106
114
} ,
107
115
update
108
116
) ;
117
+ $log . historyDocumentUpdated (
118
+ state . id ,
119
+ state . collection ,
120
+ state . field ,
121
+ state . oldValue
122
+ ) ;
109
123
break ;
110
124
default :
111
125
break ;
@@ -129,11 +143,13 @@ exports.forward = function forward() {
129
143
switch ( state . action ) {
130
144
case 'insert' :
131
145
$db [ state . collection ] . insert ( JSON . parse ( state . value ) ) ;
146
+ $log . historyDocumentInserted ( state . id , state . collection , state . value ) ;
132
147
break ;
133
148
case 'remove' :
134
149
$db [ state . collection ] . remove ( {
135
150
_id : state . id
136
151
} ) ;
152
+ $log . historyDocumentRemoved ( state . id , state . collection ) ;
137
153
break ;
138
154
case 'update' :
139
155
update [ state . field ] = JSON . parse ( state . value ) ;
@@ -144,6 +160,12 @@ exports.forward = function forward() {
144
160
} ,
145
161
update
146
162
) ;
163
+ $log . historyDocumentUpdated (
164
+ state . id ,
165
+ state . collection ,
166
+ state . field ,
167
+ state . value
168
+ ) ;
147
169
break ;
148
170
default :
149
171
break ;
Original file line number Diff line number Diff line change @@ -1137,3 +1137,72 @@ exports.unknownContext = function unknownContext(className, methodName) {
1137
1137
"' without a valid context"
1138
1138
) ;
1139
1139
} ;
1140
+
1141
+ /**
1142
+ * @method historyDocumentInserted
1143
+ * @param {Object } id id of the component
1144
+ * @param {String } collectionName collectionName of the component
1145
+ * @param {String } document
1146
+ * @description Created document from history
1147
+ */
1148
+ exports . historyDocumentInserted = function historyDocumentInserted (
1149
+ id ,
1150
+ collectionName ,
1151
+ doc
1152
+ ) {
1153
+ getLogger ( ) . debug (
1154
+ "Created component of id '" +
1155
+ id +
1156
+ "' (collection '" +
1157
+ collectionName +
1158
+ "') with document '" +
1159
+ doc +
1160
+ "'"
1161
+ ) ;
1162
+ } ;
1163
+
1164
+ /**
1165
+ * @method historyDocumentRemoved
1166
+ * @param {Object } id id of the component
1167
+ * @param {String } collectionName collectionName of the component
1168
+ * @description Removed document from history
1169
+ */
1170
+ exports . historyDocumentRemoved = function historyDocumentRemoved (
1171
+ id ,
1172
+ collectionName
1173
+ ) {
1174
+ getLogger ( ) . debug (
1175
+ "Destroyed component of id '" +
1176
+ id +
1177
+ "' (collection '" +
1178
+ collectionName +
1179
+ "')"
1180
+ ) ;
1181
+ } ;
1182
+
1183
+ /**
1184
+ * @method historyDocumentUpdated
1185
+ * @param {Object } id id of the component
1186
+ * @param {String } collectionName collectionName of the component
1187
+ * @param {String } fieldName field name of the component
1188
+ * @param {String } value value of the field
1189
+ * @description Updated document from history
1190
+ */
1191
+ exports . historyDocumentUpdated = function historyDocumentRemoved (
1192
+ id ,
1193
+ collectionName ,
1194
+ fieldName ,
1195
+ value
1196
+ ) {
1197
+ getLogger ( ) . debug (
1198
+ "Updated field '" +
1199
+ fieldName +
1200
+ "' of component of id '" +
1201
+ id +
1202
+ "' (collection '" +
1203
+ collectionName +
1204
+ "') with value '" +
1205
+ value +
1206
+ "'"
1207
+ ) ;
1208
+ } ;
You can’t perform that action at this time.
0 commit comments