Changeset 531 for Dev/trunk/src/server/api
- Timestamp:
- 03/27/14 14:44:36 (11 years ago)
- Location:
- Dev/trunk/src/server/api
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Dev/trunk/src/server/api/responses.js
r527 r531 13 13 14 14 var getResponsesBySurveyRunId = exports.getResponsesBySurveyRunId = function(surveyRunId) { 15 var url = '_design/responses/_view/by_surveyrun?key='+JSON.stringify(surveyRunId);16 return couch.get(url)15 return couch.get('_design/responses/_view/by_surveyrun', 16 {query:{key:surveyRunId,reduce:false,include_docs:true}}) 17 17 .handle({ 18 18 '-1': _.identity, 19 200: util.handleRow Values,19 200: util.handleRowDocs, 20 20 default: util.handleUnknownResponse 21 21 }); -
Dev/trunk/src/server/api/surveyRuns.js
r527 r531 15 15 app.get('/', 16 16 util.ensureMIME(util.JSON_MIME), 17 util.makeDocsGet('SurveyRun')); 17 function(req,res) { 18 var qs = {reduce:false,include_docs:true}; 19 var now = new Date().toISOString(); 20 var hr; 21 if ( 'current' in req.query ) { 22 // we make the assumption that there will be fewer 23 // runs with no or a future enddate than with a 24 // startdate in the past, i.e. we assume fewer future 25 // surveys are planned than past surveys are run. 26 hr = couch.get('_design/surveyRuns/_view/by_end_date',{ 27 query: {startkey:now,reduce:false,include_docs:true} 28 }).handle({ 29 '-1': _.identity, 30 200: function(result) { 31 return _.filter( 32 util.handleRowDocs(result), 33 function(doc){ 34 return !doc.startDate || 35 doc.startDate <= now; 36 }); 37 }, 38 default: util.handleUnknownResponse 39 }); 40 } else if ( 'future' in req.query ) { 41 hr = couch.get('_design/surveyRuns/_view/by_start_date',{ 42 query: {startkey:now,reduce:false,include_docs:true} 43 }).handle({ 44 '-1': _.identity, 45 200: util.handleRowDocs, 46 default: util.handleUnknownResponse 47 }); 48 } else if ( 'past' in req.query ) { 49 hr = couch.get('_design/surveyRuns/_view/by_end_date',{ 50 query: {endkey:now,reduce:false,include_docs:true} 51 }).handle({ 52 '-1': _.identity, 53 200: util.handleRowDocs, 54 default: util.handleUnknownResponse 55 }); 56 } else { 57 hr = util.getDocumentsOfType('SurveyRun'); 58 } 59 hr.handle({'-1': util.handleException}) 60 .handle(res.send.bind(res)); 61 }); 18 62 app.post('/', 19 63 util.ensureMIME(util.JSON_MIME), -
Dev/trunk/src/server/api/util.js
r527 r531 81 81 82 82 var getDocumentsOfType = exports.getDocumentsOfType = function(type) { 83 var url = '_design/default/_view/by_type?key='+JSON.stringify(type);84 return couch.get(url)83 return couch.get('_design/default/_view/by_type', 84 {query:{reduce:false,include_docs:true,key:type}}) 85 85 .handle({ 86 86 '-1': _.identity, 87 200: handleRow Values,87 200: handleRowDocs, 88 88 404: function() { return {error: "Cannot find collection of type "+type}; }, 89 89 default: handleUnknownResponse
Note: See TracChangeset
for help on using the changeset viewer.