-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
t6otahistory.js
46 lines (43 loc) · 1.34 KB
/
t6otahistory.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
"use strict";
var t6otahistory = module.exports = {};
t6otahistory.addEvent = function(user_id, object_id, object_attributes, source_id, version, event, status, duration) {
let OtaHistory = dbOtaHistory.getCollection("otahistory");
OtaHistory.insert({
user_id: user_id,
object_id: object_id,
object_attributes: object_attributes,
source_id: source_id,
source_version: version,
event: event,
status: status,
date: new Date(),
duration: duration,
});
dbOtaHistory.save();
t6console.log(user_id, object_id, object_attributes, source_id, version, event, status, duration);
};
t6otahistory.getLastEvent = function(user_id, object_id, source_id=null, event=null, status=null) {
let OtaHistory = dbOtaHistory.getCollection("otahistory");
let params = new Array();
params.push({ "user_id": user_id });
params.push({ "object_id": object_id });
if (source_id!==null) {
params.push({ "source_id": source_id });
}
if (event!==null) {
params.push({ "event": event });
}
if (source_id!==null) {
params.push({ "status": status });
}
let query = {"$and": params};
let hist = OtaHistory.chain().find(query).simplesort("meta.created", true).offset(0).limit(1).data();
if (typeof hist!=="undefined" && hist[0]) {
delete hist[0]["meta"];
delete hist[0]["$loki"];
return hist[0];
} else {
return {};
}
};
module.exports = t6otahistory;