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/schemaInfo": { |
---|
13 | version: "4" |
---|
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/protectPublished": { |
---|
29 | __configAction: "replace", |
---|
30 | _id: "_design/protectPublished", |
---|
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 | }, |
---|
38 | |
---|
39 | "qed/_design/default": { |
---|
40 | __configAction: "replace", |
---|
41 | _id: "_design/default", |
---|
42 | language: "javascript", |
---|
43 | views: { |
---|
44 | by_type: { |
---|
45 | map: function(doc){ |
---|
46 | emit(doc.type, doc); |
---|
47 | } |
---|
48 | }, |
---|
49 | typeless: { |
---|
50 | map: function(doc){ |
---|
51 | if ( !doc.type ) { |
---|
52 | emit(doc._id, doc); |
---|
53 | } |
---|
54 | } |
---|
55 | } |
---|
56 | } |
---|
57 | }, |
---|
58 | |
---|
59 | "qed/_design/questions": { |
---|
60 | __configAction: "replace", |
---|
61 | _id: "_design/questions", |
---|
62 | language: "javascript", |
---|
63 | views: { |
---|
64 | all: { |
---|
65 | map: function(doc){ |
---|
66 | if ( doc.type !== 'Question' ) { return; } |
---|
67 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
68 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
69 | emit([doc.categories[i],doc.topic||"(default)"],1); |
---|
70 | } |
---|
71 | } else { |
---|
72 | emit(["(default)","(default)"],1); |
---|
73 | } |
---|
74 | }, |
---|
75 | reduce: function(keys,values){ return sum(values); } |
---|
76 | }, |
---|
77 | published: { |
---|
78 | map: function(doc){ |
---|
79 | if ( doc.type!=='Question' || !doc.publicationDate ) { return; } |
---|
80 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
81 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
82 | emit([doc.categories[i],doc.topic||"(default)"],1); |
---|
83 | } |
---|
84 | } else { |
---|
85 | emit(["(default)","(default)"],1); |
---|
86 | } |
---|
87 | }, |
---|
88 | reduce: function(keys,values){ return sum(values); } |
---|
89 | }, |
---|
90 | all_topics: { |
---|
91 | map: function(doc){ |
---|
92 | if( doc.type !== 'Question' ){ return; } |
---|
93 | emit(doc.topic||"(default)",1); |
---|
94 | }, |
---|
95 | reduce: function(key, values, rereduce) { return sum(values); } |
---|
96 | }, |
---|
97 | published_topics: { |
---|
98 | map: function(doc){ |
---|
99 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
100 | emit(doc.topic||"(default)",1); |
---|
101 | }, |
---|
102 | reduce: function(key, values, rereduce) { return sum(values); } |
---|
103 | }, |
---|
104 | all_by_code: { |
---|
105 | map: function(doc){ |
---|
106 | if ( doc.type !== 'Question' ) { return; } |
---|
107 | emit(doc.code,doc); |
---|
108 | } |
---|
109 | }, |
---|
110 | published_by_code: { |
---|
111 | map: function(doc){ |
---|
112 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
113 | emit(doc.code,doc); |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | }, |
---|
118 | |
---|
119 | "qed/_design/surveys": { |
---|
120 | __configAction: "replace", |
---|
121 | _id: "_design/surveys", |
---|
122 | language: "javascript", |
---|
123 | views: { |
---|
124 | drafts: { |
---|
125 | map: function(doc){ |
---|
126 | if ( doc.type !== 'Survey' || doc.publicationDate ) { return; } |
---|
127 | emit(doc._id,doc); |
---|
128 | } |
---|
129 | }, |
---|
130 | published: { |
---|
131 | map: function(doc){ |
---|
132 | if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; } |
---|
133 | emit(doc._id,doc); |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | }, |
---|
138 | |
---|
139 | "qed/_design/surveyRuns": { |
---|
140 | __configAction: "replace", |
---|
141 | _id: "_design/surveys", |
---|
142 | language: "javascript", |
---|
143 | views: { |
---|
144 | by_dates: { |
---|
145 | map: function(doc){ |
---|
146 | if ( doc.type !== 'SurveyRun' ) { return; } |
---|
147 | var startDate = doc.startDate || ""; |
---|
148 | var endDate = doc.endDate || {}; |
---|
149 | emit([startDate,endDate,doc.liveName||null],doc); |
---|
150 | } |
---|
151 | } |
---|
152 | } |
---|
153 | }, |
---|
154 | |
---|
155 | "qed/_design/responses": { |
---|
156 | __configAction: "replace", |
---|
157 | _id: "_design/responses", |
---|
158 | language: "javascript", |
---|
159 | views: { |
---|
160 | by_surveyrun: { |
---|
161 | map: function(doc){ |
---|
162 | if ( doc.type !== 'Response' ) { return; } |
---|
163 | emit(doc.surveyRunId, doc); |
---|
164 | } |
---|
165 | } |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | }; |
---|