Last change
on this file since 523 was
508,
checked in by hendrikvanantwerpen, 11 years ago
|
- Server handles the new flat response format correctly.
- Client widgets and survey rendering creates a flat structure.
- Fixed logic error in checking if questions in survey are published.
- Restrict accepted properties in answers and reject empty strings as properties.
|
File size:
858 bytes
|
Line | |
---|
1 | var env = require('../env') |
---|
2 | , upgradeCouch = require('../config/upgrade-couchdb') |
---|
3 | , cryptoken = require('../util/crypto-token') |
---|
4 | , Q = require('q') |
---|
5 | , _ = require('underscore') |
---|
6 | ; |
---|
7 | |
---|
8 | function flatten(obj,prefix,newObj) { |
---|
9 | prefix = prefix || ""; |
---|
10 | newObj = newObj || {}; |
---|
11 | _.each(obj,function(val,key){ |
---|
12 | key = key.replace(/^[0-9]+\//,''); |
---|
13 | if ( _.isObject(val) && !_.isArray(val) ) { |
---|
14 | flatten(val,prefix+key,newObj); |
---|
15 | } else { |
---|
16 | newObj[prefix+key] = val; |
---|
17 | } |
---|
18 | }); |
---|
19 | return newObj; |
---|
20 | } |
---|
21 | |
---|
22 | upgradeCouch(env.couchServerURL,env.dbName,function(doc){ |
---|
23 | if ( doc.type === "Response" ) { |
---|
24 | doc.answers = flatten(doc.answers); |
---|
25 | return doc; |
---|
26 | } else { |
---|
27 | return Q.reject(); |
---|
28 | } |
---|
29 | }).then(function(res){ |
---|
30 | console.log("done",res); |
---|
31 | }, function(err){ |
---|
32 | console.error("fail",err); |
---|
33 | }); |
---|
Note: See
TracBrowser
for help on using the repository browser.