[455] | 1 | module.exports = { |
---|
[464] | 2 | |
---|
[519] | 3 | "schemaInfo": { |
---|
| 4 | _id: "schemaInfo", |
---|
[508] | 5 | version: "4" |
---|
[480] | 6 | }, |
---|
| 7 | |
---|
[519] | 8 | "_design/protectPublished": { |
---|
[455] | 9 | __configAction: "replace", |
---|
| 10 | language: "javascript", |
---|
| 11 | validate_doc_update: function(newDoc, oldDoc, userCtx, secObj) { |
---|
[487] | 12 | if ( oldDoc && oldDoc.publicationDate ) { |
---|
| 13 | throw({forbidden:'Published documents cannot be modified.'}); |
---|
| 14 | } |
---|
[516] | 15 | } |
---|
| 16 | }, |
---|
| 17 | |
---|
[519] | 18 | "_design/default": { |
---|
[516] | 19 | __configAction: "replace", |
---|
| 20 | language: "javascript", |
---|
[455] | 21 | views: { |
---|
| 22 | by_type: { |
---|
| 23 | map: function(doc){ |
---|
| 24 | emit(doc.type, doc); |
---|
| 25 | } |
---|
[477] | 26 | }, |
---|
| 27 | typeless: { |
---|
| 28 | map: function(doc){ |
---|
| 29 | if ( !doc.type ) { |
---|
| 30 | emit(doc._id, doc); |
---|
| 31 | } |
---|
| 32 | } |
---|
[455] | 33 | } |
---|
| 34 | } |
---|
| 35 | }, |
---|
[464] | 36 | |
---|
[519] | 37 | "_design/questions": { |
---|
[455] | 38 | __configAction: "replace", |
---|
| 39 | language: "javascript", |
---|
| 40 | views: { |
---|
| 41 | all: { |
---|
| 42 | map: function(doc){ |
---|
| 43 | if ( doc.type !== 'Question' ) { return; } |
---|
| 44 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
| 45 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
[487] | 46 | emit([doc.categories[i],doc.topic||"(default)"],1); |
---|
[455] | 47 | } |
---|
| 48 | } else { |
---|
[487] | 49 | emit(["(default)","(default)"],1); |
---|
[455] | 50 | } |
---|
| 51 | }, |
---|
| 52 | reduce: function(keys,values){ return sum(values); } |
---|
| 53 | }, |
---|
| 54 | published: { |
---|
| 55 | map: function(doc){ |
---|
| 56 | if ( doc.type!=='Question' || !doc.publicationDate ) { return; } |
---|
| 57 | if ( doc.categories && doc.categories.length > 0 ) { |
---|
| 58 | for ( var i = 0; i < doc.categories.length; i++ ) { |
---|
[487] | 59 | emit([doc.categories[i],doc.topic||"(default)"],1); |
---|
[455] | 60 | } |
---|
| 61 | } else { |
---|
[487] | 62 | emit(["(default)","(default)"],1); |
---|
[455] | 63 | } |
---|
| 64 | }, |
---|
| 65 | reduce: function(keys,values){ return sum(values); } |
---|
| 66 | }, |
---|
| 67 | all_topics: { |
---|
| 68 | map: function(doc){ |
---|
| 69 | if( doc.type !== 'Question' ){ return; } |
---|
[487] | 70 | emit(doc.topic||"(default)",1); |
---|
[455] | 71 | }, |
---|
[487] | 72 | reduce: function(key, values, rereduce) { return sum(values); } |
---|
[455] | 73 | }, |
---|
| 74 | published_topics: { |
---|
| 75 | map: function(doc){ |
---|
| 76 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
[487] | 77 | emit(doc.topic||"(default)",1); |
---|
[455] | 78 | }, |
---|
[487] | 79 | reduce: function(key, values, rereduce) { return sum(values); } |
---|
| 80 | }, |
---|
[501] | 81 | all_by_code: { |
---|
[487] | 82 | map: function(doc){ |
---|
| 83 | if ( doc.type !== 'Question' ) { return; } |
---|
| 84 | emit(doc.code,doc); |
---|
| 85 | } |
---|
[501] | 86 | }, |
---|
| 87 | published_by_code: { |
---|
| 88 | map: function(doc){ |
---|
| 89 | if ( doc.type !== 'Question' || !doc.publicationDate ) { return; } |
---|
| 90 | emit(doc.code,doc); |
---|
| 91 | } |
---|
[455] | 92 | } |
---|
| 93 | } |
---|
| 94 | }, |
---|
[464] | 95 | |
---|
[519] | 96 | "_design/surveys": { |
---|
[455] | 97 | __configAction: "replace", |
---|
| 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 | }, |
---|
[464] | 114 | |
---|
[519] | 115 | "_design/surveyRuns": { |
---|
[492] | 116 | __configAction: "replace", |
---|
| 117 | language: "javascript", |
---|
| 118 | views: { |
---|
| 119 | by_dates: { |
---|
| 120 | map: function(doc){ |
---|
| 121 | if ( doc.type !== 'SurveyRun' ) { return; } |
---|
| 122 | var startDate = doc.startDate || ""; |
---|
| 123 | var endDate = doc.endDate || {}; |
---|
| 124 | emit([startDate,endDate,doc.liveName||null],doc); |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | }, |
---|
| 129 | |
---|
[519] | 130 | "_design/responses": { |
---|
[455] | 131 | __configAction: "replace", |
---|
| 132 | language: "javascript", |
---|
| 133 | views: { |
---|
| 134 | by_surveyrun: { |
---|
| 135 | map: function(doc){ |
---|
| 136 | if ( doc.type !== 'Response' ) { return; } |
---|
| 137 | emit(doc.surveyRunId, doc); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | } |
---|
[464] | 142 | |
---|
[455] | 143 | }; |
---|