1 | module.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/_security": { |
---|
13 | __configAction: "ignore", |
---|
14 | admins: { |
---|
15 | names: [], |
---|
16 | roles: ["qed_admin"] |
---|
17 | }, |
---|
18 | readers: { |
---|
19 | names: [], |
---|
20 | roles: ["qed_user"] |
---|
21 | } |
---|
22 | }, |
---|
23 | |
---|
24 | "qed/_design/default": { |
---|
25 | __configAction: "replace", |
---|
26 | _id: "_design/default", |
---|
27 | language: "javascript", |
---|
28 | validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) { |
---|
29 | if ( oldDoc && oldDoc.publicationDate ) { throw({forbidden:'Published documents cannot be modified.'}); } |
---|
30 | }, |
---|
31 | views: { |
---|
32 | by_type: { |
---|
33 | map: function(doc){ |
---|
34 | emit(doc.type, doc); |
---|
35 | } |
---|
36 | }, |
---|
37 | typeless: { |
---|
38 | map: function(doc){ |
---|
39 | if ( !doc.type ) { |
---|
40 | emit(doc._id, doc); |
---|
41 | } |
---|
42 | } |
---|
43 | } |
---|
44 | } |
---|
45 | }, |
---|
46 | |
---|
47 | "qed/_design/questions": { |
---|
48 | __configAction: "replace", |
---|
49 | _id: "_design/questions", |
---|
50 | language: "javascript", |
---|
51 | views: { |
---|
52 | all: { |
---|
53 | map: function(doc){ |
---|
54 | if ( doc.type !== 'Question' ) { return; } |
---|
55 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
56 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
57 | emit([doc.categories[i],doc.topic||null],1); |
---|
58 | } |
---|
59 | } else { |
---|
60 | emit([null,null],1); |
---|
61 | } |
---|
62 | }, |
---|
63 | reduce: function(keys,values){ return sum(values); } |
---|
64 | }, |
---|
65 | published: { |
---|
66 | map: function(doc){ |
---|
67 | if ( doc.type!=='Question' || !doc.publicationDate ) { return; } |
---|
68 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
69 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
70 | emit([doc.categories[i],doc.topic||null],1); |
---|
71 | } |
---|
72 | } else { |
---|
73 | emit([null,null],1); |
---|
74 | } |
---|
75 | }, |
---|
76 | reduce: function(keys,values){ return sum(values); } |
---|
77 | }, |
---|
78 | all_topics: { |
---|
79 | map: function(doc){ |
---|
80 | if( doc.type !== 'Question' ){ return; } |
---|
81 | emit(doc.topic); |
---|
82 | }, |
---|
83 | reduce: function(key, values, rereduce) { return null; } |
---|
84 | }, |
---|
85 | published_topics: { |
---|
86 | map: function(doc){ |
---|
87 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
88 | emit(doc.topic); |
---|
89 | }, |
---|
90 | reduce: function(key, values, rereduce) { return null; } |
---|
91 | } |
---|
92 | } |
---|
93 | }, |
---|
94 | |
---|
95 | "qed/_design/surveys": { |
---|
96 | __configAction: "replace", |
---|
97 | _id: "_design/surveys", |
---|
98 | language: "javascript", |
---|
99 | views: { |
---|
100 | drafts: { |
---|
101 | map: function(doc){ |
---|
102 | if ( doc.type !== 'Survey' || doc.publicationDate ) { return; } |
---|
103 | emit(doc._id,doc); |
---|
104 | } |
---|
105 | }, |
---|
106 | published: { |
---|
107 | map: function(doc){ |
---|
108 | if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; } |
---|
109 | emit(doc._id,doc); |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | }, |
---|
114 | |
---|
115 | "qed/_design/responses": { |
---|
116 | __configAction: "replace", |
---|
117 | _id: "_design/responses", |
---|
118 | language: "javascript", |
---|
119 | views: { |
---|
120 | by_surveyrun: { |
---|
121 | map: function(doc){ |
---|
122 | if ( doc.type !== 'Response' ) { return; } |
---|
123 | emit(doc.surveyRunId, doc); |
---|
124 | } |
---|
125 | } |
---|
126 | } |
---|
127 | } |
---|
128 | |
---|
129 | }; |
---|