[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 | |
---|
[455] | 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 | }, |
---|
[464] | 23 | |
---|
[455] | 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 | } |
---|
| 38 | }, |
---|
[464] | 39 | |
---|
[455] | 40 | "qed/_design/questions": { |
---|
| 41 | __configAction: "replace", |
---|
| 42 | _id: "_design/questions", |
---|
| 43 | language: "javascript", |
---|
| 44 | views: { |
---|
| 45 | all: { |
---|
| 46 | map: function(doc){ |
---|
| 47 | if ( doc.type !== 'Question' ) { return; } |
---|
| 48 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
| 49 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
| 50 | emit([doc.categories[i],doc.topic||null],1); |
---|
| 51 | } |
---|
| 52 | } else { |
---|
| 53 | emit([null,null],1); |
---|
| 54 | } |
---|
| 55 | }, |
---|
| 56 | reduce: function(keys,values){ return sum(values); } |
---|
| 57 | }, |
---|
| 58 | published: { |
---|
| 59 | map: function(doc){ |
---|
| 60 | if ( doc.type!=='Question' || !doc.publicationDate ) { 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||null],1); |
---|
| 64 | } |
---|
| 65 | } else { |
---|
| 66 | emit([null,null],1); |
---|
| 67 | } |
---|
| 68 | }, |
---|
| 69 | reduce: function(keys,values){ return sum(values); } |
---|
| 70 | }, |
---|
| 71 | all_topics: { |
---|
| 72 | map: function(doc){ |
---|
| 73 | if( doc.type !== 'Question' ){ return; } |
---|
| 74 | emit(doc.topic); |
---|
| 75 | }, |
---|
| 76 | reduce: function(key, values, rereduce) { return null; } |
---|
| 77 | }, |
---|
| 78 | published_topics: { |
---|
| 79 | map: function(doc){ |
---|
| 80 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
| 81 | emit(doc.topic); |
---|
| 82 | }, |
---|
| 83 | reduce: function(key, values, rereduce) { return null; } |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | }, |
---|
[464] | 87 | |
---|
[455] | 88 | "qed/_design/surveys": { |
---|
| 89 | __configAction: "replace", |
---|
| 90 | _id: "_design/surveys", |
---|
| 91 | language: "javascript", |
---|
| 92 | views: { |
---|
| 93 | drafts: { |
---|
| 94 | map: function(doc){ |
---|
| 95 | if ( doc.type !== 'Survey' || doc.publicationDate ) { return; } |
---|
| 96 | emit(doc._id,doc); |
---|
| 97 | } |
---|
| 98 | }, |
---|
| 99 | published: { |
---|
| 100 | map: function(doc){ |
---|
| 101 | if ( doc.type !== 'Survey' || !doc.publicationDate ) { return; } |
---|
| 102 | emit(doc._id,doc); |
---|
| 103 | } |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | }, |
---|
[464] | 107 | |
---|
[455] | 108 | "qed/_design/responses": { |
---|
| 109 | __configAction: "replace", |
---|
| 110 | _id: "_design/responses", |
---|
| 111 | language: "javascript", |
---|
| 112 | views: { |
---|
| 113 | by_surveyrun: { |
---|
| 114 | map: function(doc){ |
---|
| 115 | if ( doc.type !== 'Response' ) { return; } |
---|
| 116 | emit(doc.surveyRunId, doc); |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | } |
---|
| 120 | } |
---|
[464] | 121 | |
---|
[455] | 122 | }; |
---|