forked from Netflix/falcor-router-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
title-service.js
33 lines (31 loc) · 857 Bytes
/
title-service.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
var PouchDB = require('pouchdb');
var batch = require('./batch');
var path = require('path');
var titlesDB = new PouchDB(path.join(__dirname, 'titles_db'));
// titles service
function TitleService() {}
TitleService.prototype = {
getTitles: batch(function(titleIds) {
return titlesDB.allDocs({
keys: titleIds.map(function(x) { return x.toString(); }),
include_docs: true
}).then(function(dbResponse) {
var titles = {};
dbResponse.rows.forEach(function (row) {
if (row.error) {
if (row.error == "not_found") {
titles[row.key] = {doc: null};
} else {
titles[row.key] = {error: row.error};
}
} else if (row.doc) {
titles[row.key] = row;
} else {
titles[row.key] = {doc: null};
}
});
return titles;
});
})
};
module.exports = new TitleService();