Ignore:
Timestamp:
03/27/14 14:44:36 (11 years ago)
Author:
hendrikvanantwerpen
Message:
  • Return to using truly ISO formatted dates, including milliseconds.
  • Also set constraint on surveyrun dates when value is initially set.
  • Separate runs & results from surveys and questions.
  • Moved date & email format to schema itself.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/server/api/surveyRuns.js

    r527 r531  
    1515    app.get('/',
    1616        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        });
    1862    app.post('/',
    1963        util.ensureMIME(util.JSON_MIME),
Note: See TracChangeset for help on using the changeset viewer.