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