-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditors.js
38 lines (27 loc) · 1 KB
/
editors.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
/* The EditorsDAO must be constructed with a connected database object */
function EditorsDAO(db) {
"use strict";
/* If this constructor is called without the "new" operator, "this" points
* to the global object. Log a warning and call it correctly. */
if (false === (this instanceof EditorsDAO)) {
console.log('Warning: EditorsDAO constructor called without "new" operator');
return new EditorsDAO(db);
}
var editors = db.collection("editors");
var posts = db.collection("posts");
this.getEditors = function(callback) {
"use strict";
editors.find().toArray(function(err, items) {
"use strict";
if (err) return callback(err, null);
console.log("Found " + items.length + " editors");
callback(err, items);
});
}
this.getTotalEditors = function(){
editors.count(function(error, nbDocs) {
return nbDocs;
});
}
}
module.exports.EditorsDAO = EditorsDAO;