2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
var mongoose = require('mongoose'),
|
|
|
|
Schema = mongoose.Schema,
|
2015-10-06 20:14:38 +00:00
|
|
|
mUtilities = require('mongoose-utilities'),
|
2016-11-08 22:53:10 +00:00
|
|
|
FieldSchema = require('./form_field.server.model.js');
|
2015-10-06 20:14:38 +00:00
|
|
|
|
2016-04-29 06:16:17 +00:00
|
|
|
/**
|
2015-06-29 22:51:29 +00:00
|
|
|
* Form Submission Schema
|
|
|
|
*/
|
|
|
|
var FormSubmissionSchema = new Schema({
|
2015-10-06 20:14:38 +00:00
|
|
|
title: {
|
2015-07-27 18:11:43 +00:00
|
|
|
type: String
|
2015-06-29 22:51:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
admin: {
|
|
|
|
type: Schema.Types.ObjectId,
|
|
|
|
ref: 'User',
|
2015-07-27 18:11:43 +00:00
|
|
|
required: true
|
2015-06-29 22:51:29 +00:00
|
|
|
},
|
2015-10-06 20:24:02 +00:00
|
|
|
|
2016-06-05 03:13:42 +00:00
|
|
|
form_fields: [FieldSchema],
|
2015-10-06 20:24:02 +00:00
|
|
|
|
2016-04-29 06:16:17 +00:00
|
|
|
form: {
|
|
|
|
type: Schema.Types.ObjectId,
|
|
|
|
ref: 'Form',
|
2015-06-29 22:51:29 +00:00
|
|
|
required: true
|
|
|
|
},
|
|
|
|
|
|
|
|
ipAddr: {
|
2016-04-29 06:16:17 +00:00
|
|
|
type: String
|
2015-06-29 22:51:29 +00:00
|
|
|
},
|
|
|
|
geoLocation: {
|
2015-11-23 20:12:10 +00:00
|
|
|
Country: {
|
2016-04-29 06:16:17 +00:00
|
|
|
type: String
|
2015-11-23 20:12:10 +00:00
|
|
|
},
|
|
|
|
City: {
|
2016-04-29 06:16:17 +00:00
|
|
|
type: String
|
2015-11-23 20:12:10 +00:00
|
|
|
}
|
2015-06-29 22:51:29 +00:00
|
|
|
},
|
2015-11-13 01:40:23 +00:00
|
|
|
device: {
|
|
|
|
type: {
|
2016-04-29 06:16:17 +00:00
|
|
|
type: String
|
2015-11-13 01:40:23 +00:00
|
|
|
},
|
|
|
|
name: {
|
2016-04-29 06:16:17 +00:00
|
|
|
type: String
|
2015-11-13 01:40:23 +00:00
|
|
|
}
|
|
|
|
},
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2016-04-29 06:16:17 +00:00
|
|
|
timeElapsed: {
|
2016-06-05 03:13:42 +00:00
|
|
|
type: Number
|
2016-04-29 06:16:17 +00:00
|
|
|
},
|
2015-07-30 00:22:53 +00:00
|
|
|
percentageComplete: {
|
2016-04-29 06:16:17 +00:00
|
|
|
type: Number
|
2015-07-30 00:22:53 +00:00
|
|
|
}
|
2015-06-29 22:51:29 +00:00
|
|
|
});
|
|
|
|
|
2016-11-09 18:02:12 +00:00
|
|
|
FormSubmissionSchema.path('form_fields', {
|
|
|
|
set: function(form_fields){
|
|
|
|
for (var i = 0; i < form_fields.length; i++) {
|
|
|
|
form_fields[i].isSubmission = true;
|
|
|
|
form_fields[i].submissionId = form_fields[i]._id;
|
|
|
|
form_fields[i]._id = new mongoose.mongo.ObjectID();
|
|
|
|
}
|
|
|
|
return form_fields;
|
|
|
|
}
|
|
|
|
});
|
2016-06-05 03:13:42 +00:00
|
|
|
|
2015-10-06 20:14:38 +00:00
|
|
|
FormSubmissionSchema.plugin(mUtilities.timestamp, {
|
|
|
|
createdPath: 'created',
|
|
|
|
modifiedPath: 'lastModified',
|
|
|
|
useVirtual: false
|
|
|
|
});
|
2015-09-10 22:06:28 +00:00
|
|
|
|
2015-07-21 23:25:45 +00:00
|
|
|
module.exports = FormSubmissionSchema;
|