-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
64 lines (51 loc) · 2.2 KB
/
index.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
const constants = require("./constants");
const MongoHandler = require("./MongoHandler");
var settings;
var mongoHandler;
var storageModule = {
init: function(_settings) {
settings = _settings;
if(settings.storageModuleOptions == null || settings.storageModuleOptions.mongoUrl == null || settings.storageModuleOptions.database == null){
throw new Error("mongo storage module's required parameters are not defined");
}
this.collectionNames = Object.assign(constants.DefaultCollectionNames);
if(settings.storageModuleOptions.collectionNames != null){
for(let settingsColName of Object.keys(settings.storageModuleOptions.collectionNames)){
this.collectionNames[settingsColName] = settings.storageModuleOptions.collectionNames[settingsColName];
}
}
mongoHandler = new MongoHandler(settings.storageModuleOptions.mongoUrl, settings.storageModuleOptions.database);
return mongoHandler.connect();
},
getFlows: function() {
return mongoHandler.findAll(this.collectionNames.flows);
},
saveFlows: function(flows) {
return mongoHandler.saveAll(this.collectionNames.flows, flows);
},
getCredentials: function() {
return mongoHandler.findAll(this.collectionNames.credentials);
},
saveCredentials: function(credentials) {
return mongoHandler.saveAll(this.collectionNames.credentials, credentials);
},
getSettings: function() {
return mongoHandler.findAll(this.collectionNames.settings);
},
saveSettings: function(settings) {
return mongoHandler.saveAll(this.collectionNames.settings, settings);
},
getSessions: function() {
return mongoHandler.findAll(this.collectionNames.sessions);
},
saveSessions: function(sessions) {
return mongoHandler.saveAll(this.collectionNames.sessions, sessions);
},
getLibraryEntry: function(type, path) {
return mongoHandler.findOneByPath(type, path);
},
saveLibraryEntry: function(type, path, meta, body) {
return mongoHandler.saveOrUpdateByPath(type, path, meta, body) ;
}
};
module.exports = storageModule;