source: Dev/branches/rest-dojo-ui/server/couchdb-admin/config/data/design-docs.js @ 415

Last change on this file since 415 was 415, checked in by hendrikvanantwerpen, 12 years ago

Support data validation and increase dendency separation.

Added json-schema validation before documents are saved. Acts both as
a safe-guard and as a reference of the data model.

Added directory for server related material. For now it contains scripts
to configure CouchDB and check validity of documents against the schema.

Started separating out parts that depend on the data model from parts
that do not.

File size: 3.8 KB
Line 
1define([],function(){
2    return {
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        "qed/_security": {
12            __configAction: "ignore",
13            admins: {
14                names: [],
15                roles: ["qed_admin"]
16            },
17            readers: {
18                names: [],
19                roles: ["qed_user"]
20            }
21        },
22        "qed/_design/default": {
23            __configAction: "replace",
24            _id: "_design/default",
25            language: "javascript",
26            validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) {
27                if ( oldDoc && oldDoc.publicationDate ) { throw({forbidden:'Published documents cannot be modified.'}); }
28            },
29            views: {
30                by_type: {
31                    map: function(doc){
32                        emit(doc.type, doc);
33                    }
34                }
35            }
36        },
37        "qed/_design/questions": {
38            __configAction: "replace",
39            _id: "_design/questions",
40            language: "javascript",
41            views: {
42                all: {
43                    map: function(doc){
44                        if ( doc.type !== 'Question' ) { return; }
45                        if ( doc.categories && doc.categories.length > 0 ) {
46                            for ( var i = 0; i < doc.categories.length; i++ ) {
47                                emit([doc.categories[i],doc.topic||null],1);
48                            }
49                        } else {
50                            emit([null,null],1);
51                        }
52                    },
53                    reduce: function(keys,values){ return sum(values); }
54                },
55                published: {
56                    map: function(doc){
57                        if ( doc.type!=='Question' || !doc.publicationDate ) { return; }
58                        if ( doc.categories && doc.categories.length > 0 ) {
59                            for ( var i = 0; i < doc.categories.length; i++ ) {
60                                emit([doc.categories[i],doc.topic||null],1);
61                            }
62                        } else {
63                            emit([null,null],1);
64                        }
65                    },
66                    reduce: function(keys,values){ return sum(values); }
67                },
68                all_topics: {
69                    map: function(doc){
70                        if( doc.type !== 'Question' ){ return; }
71                        emit(doc.topic);
72                    },
73                    reduce: function(key, values, rereduce) { return null; }
74                },
75                published_topics: {
76                    map: function(doc){
77                        if ( doc.type !== 'Question' || !doc.publicationDate ) { return; }
78                        emit(doc.topic);
79                    },
80                    reduce: function(key, values, rereduce) { return null; }
81                }
82            }
83        },
84        "qed/_design/surveys": {
85            __configAction: "replace",
86            _id: "_design/surveys",
87            language: "javascript",
88            views: {
89                drafts: {
90                    map: function(doc){
91                        if ( doc.type !== 'Survey' || doc.publicationDate ) { return; }
92                        emit(doc._id,doc);
93                    }
94                },
95                published: {
96                    map: function(doc){
97                        if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; }
98                        emit(doc._id,doc);
99                    }
100                }
101            }
102        }
103    };
104});
Note: See TracBrowser for help on using the repository browser.