Last change
on this file since 525 was
525,
checked in by hendrikvanantwerpen, 11 years ago
|
- Allow empty subcodes.
- Use HTTPResult exclusively on server (no more q).
- Set readonly & disabled on ourselves as well in _ComplexValueMixin
- Split server into several modules.
- Check codes on the variable level, not question level.
- We can add modules in design documents now.
|
File size:
1.2 KB
|
Line | |
---|
1 | var HTTPResult = require('../util/http-result') |
---|
2 | , _ = require('underscore') |
---|
3 | , CouchDB = require('../util/couch') |
---|
4 | ; |
---|
5 | |
---|
6 | var schema = require('./couchdb-schema'); |
---|
7 | |
---|
8 | module.exports = function(couchServerURL,dbName,upgrade) { |
---|
9 | var server = new CouchDB(couchServerURL,dbName); |
---|
10 | var designRe = /^_design\//; |
---|
11 | return server.get('/_all_docs') |
---|
12 | .then(function(allDocs){ |
---|
13 | return _.chain(allDocs.rows) |
---|
14 | .filter(function(doc){ |
---|
15 | return doc.id.match(designRe) === null; |
---|
16 | }) |
---|
17 | .reduce(function(memo, doc){ |
---|
18 | return memo.then(function(result){ |
---|
19 | return server.get(doc.id) |
---|
20 | .then(function(doc){ |
---|
21 | HTTPResult.when(200,upgrade(doc)) |
---|
22 | .then(function(newDoc){ |
---|
23 | return server.put(doc._id,newDoc) |
---|
24 | .then(function(){ |
---|
25 | result[doc._id] = true; |
---|
26 | return result; |
---|
27 | }); |
---|
28 | },function(){ |
---|
29 | result[doc._id] = false; |
---|
30 | }); |
---|
31 | return result; |
---|
32 | }); |
---|
33 | }); |
---|
34 | }, new HTTPResult(200,{})) |
---|
35 | .value(); |
---|
36 | }).all(); |
---|
37 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.