-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfolderProvider.js
46 lines (38 loc) · 1012 Bytes
/
folderProvider.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
var error = require('./error');
var Backend = require('./backend/backend').Backend;
FolderProvider = function(folders){
var onGotId = function (error, id, forBackend) {
if (!error && id) {
f[id] = forBackend;
} else {
console.log('could not add folder; no id returned: ' + error);
}
};
for (var i = 0; i < folders.length; i++) {
var backend = new Backend(folders[i]);
var f = this.folders;
backend.getId(onGotId, backend);
}
};
FolderProvider.prototype.folders = {};
FolderProvider.prototype.findAll = function(next) {
var f = {};
for (var id in this.folders) {
if (this.folders.hasOwnProperty(id)) {
f[id] = this.folders[id];
}
}
next(null, f);
};
FolderProvider.prototype.findById = function(id, next) {
var result = null;
if (id in this.folders) {
result = this.folders[id];
}
if (!result) {
next(new error.NotFound('No such folder'));
} else {
next(null, result);
}
};
exports.FolderProvider = FolderProvider;