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: "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 | all_by_code: { |
---|
99 | map: function(doc){ |
---|
100 | if ( doc.type !== 'Question' ) { return; } |
---|
101 | emit(doc.code,doc); |
---|
102 | } |
---|
103 | }, |
---|
104 | published_by_code: { |
---|
105 | map: function(doc){ |
---|
106 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
107 | emit(doc.code,doc); |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | }, |
---|
112 | |
---|
113 | "qed/_design/surveys": { |
---|
114 | __configAction: "replace", |
---|
115 | _id: "_design/surveys", |
---|
116 | language: "javascript", |
---|
117 | views: { |
---|
118 | drafts: { |
---|
119 | map: function(doc){ |
---|
120 | if ( doc.type !== 'Survey' || doc.publicationDate ) { return; } |
---|
121 | emit(doc._id,doc); |
---|
122 | } |
---|
123 | }, |
---|
124 | published: { |
---|
125 | map: function(doc){ |
---|
126 | if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; } |
---|
127 | emit(doc._id,doc); |
---|
128 | } |
---|
129 | } |
---|
130 | } |
---|
131 | }, |
---|
132 | |
---|
133 | "qed/_design/surveyRuns": { |
---|
134 | __configAction: "replace", |
---|
135 | _id: "_design/surveys", |
---|
136 | language: "javascript", |
---|
137 | views: { |
---|
138 | by_dates: { |
---|
139 | map: function(doc){ |
---|
140 | if ( doc.type !== 'SurveyRun' ) { return; } |
---|
141 | var startDate = doc.startDate || ""; |
---|
142 | var endDate = doc.endDate || {}; |
---|
143 | emit([startDate,endDate,doc.liveName||null],doc); |
---|
144 | } |
---|
145 | } |
---|
146 | } |
---|
147 | }, |
---|
148 | |
---|
149 | "qed/_design/responses": { |
---|
150 | __configAction: "replace", |
---|
151 | _id: "_design/responses", |
---|
152 | language: "javascript", |
---|
153 | views: { |
---|
154 | by_surveyrun: { |
---|
155 | map: function(doc){ |
---|
156 | if ( doc.type !== 'Response' ) { return; } |
---|
157 | emit(doc.surveyRunId, doc); |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|
163 | }; |
---|