waltz-ng/client/survey/survey-utils.js
/**
 * Indexes the given survey responses by question id.
 * Also ensures that booleans and dates are properly
 * represented as strings.
 *
 * @param responses
 * @returns {qid -> surveyResponse}
 */
Indexes the given survey responses by question id.
Also ensures that booleans and dates are properly
represented as strings.

@param responses
@returns {qid -> surveyResponse}
Indexes the given survey responses by question id . Also ensures that booleans and dates are properly represented as strings . @param responses @returns { qid - > surveyResponse }
function indexResponses(responses = []) {
    return _
        .chain(responses)
        .map(d => d.questionResponse)
        .map(qr => {
            if (!_.isNil(qr.booleanResponse) && !_.isString(qr.booleanResponse)) {
                qr.booleanResponse = qr.booleanResponse
                    ? "true"
                    : "false";
            }
            if (_.isNil(qr.booleanResponse) && !_.isString(qr.booleanResponse)){
                qr.booleanResponse = "null"
            }
            if (!_.isNil(qr.dateResponse)) {
                qr.dateResponse = moment(qr.dateResponse, formats.parseDateOnly).toDate()
            }
            return qr;
        })
        .keyBy("questionId")
        .value();
}
function indexResponses ( responses = [ ] ) { return _ . chain ( responses ) . map ( d => d . questionResponse ) . map ( qr => { if ( ! _ . isNil ( qr . booleanResponse ) && ! _ . isString ( qr . booleanResponse ) ) { qr . booleanResponse = qr . booleanResponse ? "true" : "false" ; } if ( _ . isNil ( qr . booleanResponse ) && ! _ . isString ( qr . booleanResponse ) ) { qr . booleanResponse = "null" } if ( ! _ . isNil ( qr . dateResponse ) ) { qr . dateResponse = moment ( qr . dateResponse , formats . parseDateOnly ) . toDate ( ) } return qr ; } ) . keyBy ( "questionId" ) . value ( ) ; }
Indexes the given survey responses by question id.
Indexes the given survey responses by question id .