source: Dev/trunk/src/server/config/couchdb-design-docs.js @ 487

Last change on this file since 487 was 487, checked in by hendrikvanantwerpen, 11 years ago

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 size: 4.3 KB
Line 
1module.exports = {
2
3    "_users/qed_admin": {
4        __configAction: "ignore",
5        _id: "org.couchdb.user:qed_admin",
6        name: "qed_admin",
7        password: "Welkom01",
8        roles: [ "qed_admin" ],
9        type: "user"
10    },
11
12    "qed/schemaInfo": {
13        version: "2"
14    },
15
16    "qed/_security": {
17        __configAction: "ignore",
18        admins: {
19            names: [],
20            roles: ["qed_admin"]
21        },
22        readers: {
23            names: [],
24            roles: ["qed_user"]
25        }
26    },
27
28    "qed/_design/default": {
29        __configAction: "replace",
30        _id: "_design/default",
31        language: "javascript",
32        validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) {
33            if ( oldDoc && oldDoc.publicationDate ) {
34                throw({forbidden:'Published documents cannot be modified.'});
35            }
36        },
37        views: {
38            by_type: {
39                map: function(doc){
40                    emit(doc.type, doc);
41                }
42            },
43            typeless: {
44                map: function(doc){
45                    if ( !doc.type ) {
46                        emit(doc._id, doc);
47                    }
48                }
49            }
50        }
51    },
52
53    "qed/_design/questions": {
54        __configAction: "replace",
55        _id: "_design/questions",
56        language: "javascript",
57        views: {
58            all: {
59                map: function(doc){
60                    if ( doc.type !== 'Question' ) { return; }
61                    if ( doc.categories && doc.categories.length > 0 ) {
62                        for ( var i = 0; i < doc.categories.length; i++ ) {
63                            emit([doc.categories[i],doc.topic||"(default)"],1);
64                        }
65                    } else {
66                        emit(["(default)","(default)"],1);
67                    }
68                },
69                reduce: function(keys,values){ return sum(values); }
70            },
71            published: {
72                map: function(doc){
73                    if ( doc.type!=='Question' || !doc.publicationDate ) { return; }
74                    if ( doc.categories && doc.categories.length > 0 ) {
75                        for ( var i = 0; i < doc.categories.length; i++ ) {
76                            emit([doc.categories[i],doc.topic||"(default)"],1);
77                        }
78                    } else {
79                        emit(["(default)","(default)"],1);
80                    }
81                },
82                reduce: function(keys,values){ return sum(values); }
83            },
84            all_topics: {
85                map: function(doc){
86                    if( doc.type !== 'Question' ){ return; }
87                    emit(doc.topic||"(default)",1);
88                },
89                reduce: function(key, values, rereduce) { return sum(values); }
90            },
91            published_topics: {
92                map: function(doc){
93                    if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
94                    emit(doc.topic||"(default)",1);
95                },
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                }
103            }
104        }
105    },
106
107    "qed/_design/surveys": {
108        __configAction: "replace",
109        _id: "_design/surveys",
110        language: "javascript",
111        views: {
112            drafts: {
113                map: function(doc){
114                    if ( doc.type !== 'Survey' || doc.publicationDate ) { return; }
115                    emit(doc._id,doc);
116                }
117            },
118            published: {
119                map: function(doc){
120                    if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; }
121                    emit(doc._id,doc);
122                }
123            }
124        }
125    },
126
127    "qed/_design/responses": {
128        __configAction: "replace",
129        _id: "_design/responses",
130        language: "javascript",
131        views: {
132            by_surveyrun: {
133                map: function(doc){
134                    if ( doc.type !== 'Response' ) { return; }
135                    emit(doc.surveyRunId, doc);
136                }
137            }
138        }
139    }
140
141};
Note: See TracBrowser for help on using the repository browser.