source: Dev/trunk/src/server/config/check-couchdb.js @ 531

Last change on this file since 531 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.4 KB
RevLine 
[525]1var _ = require('underscore')
2  , HTTPResult = require('../util/http-result')
[492]3  , validator = require('../util/validator')
[525]4  , CouchDB = require('../util/couch')
5  , objF = require('../util/object')
[479]6  ;
7
8var schema = require('./couchdb-schema');
9
[487]10module.exports = function(couchServerURL,dbName) {
11    var server = new CouchDB(couchServerURL,dbName);
[479]12    var designRe = /^_design\//;
[492]13
[479]14    return server.get('/_all_docs')
15    .then(function(allDocs){
16        return _.chain(allDocs.rows)
17        .filter(function(doc){
18            return doc.id.match(designRe) === null;
19        })
20        .reduce(function(memo, doc){
21            return memo.then(function(result){
22                return server.get(doc.id)
23                .then(function(doc){
[492]24                    var valid = validator(doc,schema);
[479]25                    result[doc._id] = valid;
26                    return result;
27                });
28            });
[525]29        }, new HTTPResult(200,{}))
[479]30        .value();
[525]31    }).then(function(result){
32        return server.get('_design/questions/_view/all_variables')
33        .then(function(variables){
34            var dups = objF.findDuplicates(
35                variables.rows,
36                function(row){ return row.key; });
37            result._duplicateVariables = _.groupBy(
38                dups,
39                function(dup){ return dup.key; });
40            return result;
41        });
42    });
[479]43};
Note: See TracBrowser for help on using the repository browser.