tellform/app/models/form_submission.server.model.js

94 lines
1.6 KiB
JavaScript
Raw Normal View History

2015-06-29 22:51:29 +00:00
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
_ = require('lodash'),
config = require('../../config/config'),
path = require('path'),
2015-07-27 18:11:43 +00:00
fs = require('fs-extra'),
2015-10-06 20:14:38 +00:00
mUtilities = require('mongoose-utilities'),
async = require('async'),
2016-11-08 22:53:10 +00:00
FieldSchema = require('./form_field.server.model.js');
2015-10-06 20:14:38 +00:00
2016-06-05 03:13:42 +00:00
// Setter function for form_fields
2016-10-23 04:31:18 +00:00
function formFieldsSetter(form_fields) {
for (var i = 0; i < form_fields.length; i++) {
2016-06-05 03:13:42 +00:00
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-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
},
2016-06-05 03:13:42 +00:00
form_fields: [FieldSchema],
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: {
Country: {
2016-04-29 06:16:17 +00:00
type: String
},
City: {
2016-04-29 06:16:17 +00:00
type: String
}
2015-06-29 22:51:29 +00:00
},
device: {
type: {
2016-04-29 06:16:17 +00:00
type: String
},
name: {
2016-04-29 06:16:17 +00:00
type: String
}
},
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
},
percentageComplete: {
2016-04-29 06:16:17 +00:00
type: Number
}
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
module.exports = FormSubmissionSchema;