Ignore:
Timestamp:
03/05/14 22:44:48 (11 years ago)
Author:
hendrikvanantwerpen
Message:

Completed migration to API, without CouchDB proxy.

Move to API is now completed. The full API is password protected, a very
limited API is exposed for respondents, which works with secrets that
are passed in URLs.

Serverside the HTTPResult class was introduced, which is similar to
Promises, but specifically for HTTP. It carries a status code and
response and makes it easier to extract parts of async handling in
separate functions.

Fixed a bug in our schema (it seems optional attributes don't exist but
a required list does). Verification of our schema by grunt-tv4 didn't
work yet. Our schema is organized the wrong way (this is fixable),
but the json-schema schema has problems with simple types and $refs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/server/config/couchdb-design-docs.js

    r480 r487  
    1111
    1212    "qed/schemaInfo": {
    13         version: "1"
     13        version: "2"
    1414    },
    1515
     
    3131        language: "javascript",
    3232        validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) {
    33             if ( oldDoc && oldDoc.publicationDate ) { throw({forbidden:'Published documents cannot be modified.'}); }
     33            if ( oldDoc && oldDoc.publicationDate ) {
     34                throw({forbidden:'Published documents cannot be modified.'});
     35            }
    3436        },
    3537        views: {
     
    5961                    if ( doc.categories && doc.categories.length > 0 ) {
    6062                        for ( var i = 0; i < doc.categories.length; i++ ) {
    61                             emit([doc.categories[i],doc.topic||null],1);
     63                            emit([doc.categories[i],doc.topic||"(default)"],1);
    6264                        }
    6365                    } else {
    64                         emit([null,null],1);
     66                        emit(["(default)","(default)"],1);
    6567                    }
    6668                },
     
    7274                    if ( doc.categories && doc.categories.length > 0 ) {
    7375                        for ( var i = 0; i < doc.categories.length; i++ ) {
    74                             emit([doc.categories[i],doc.topic||null],1);
     76                            emit([doc.categories[i],doc.topic||"(default)"],1);
    7577                        }
    7678                    } else {
    77                         emit([null,null],1);
     79                        emit(["(default)","(default)"],1);
    7880                    }
    7981                },
     
    8385                map: function(doc){
    8486                    if( doc.type !== 'Question' ){ return; }
    85                     emit(doc.topic);
     87                    emit(doc.topic||"(default)",1);
    8688                },
    87                 reduce: function(key, values, rereduce) { return null; }
     89                reduce: function(key, values, rereduce) { return sum(values); }
    8890            },
    8991            published_topics: {
    9092                map: function(doc){
    9193                    if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
    92                     emit(doc.topic);
     94                    emit(doc.topic||"(default)",1);
    9395                },
    94                 reduce: function(key, values, rereduce) { return null; }
     96                reduce: function(key, values, rereduce) { return sum(values); }
     97            },
     98            by_code: {
     99                map: function(doc){
     100                    if ( doc.type !== 'Question' ) { return; }
     101                    emit(doc.code,doc);
     102                }
    95103            }
    96104        }
Note: See TracChangeset for help on using the changeset viewer.