Shortid in form

This commit is contained in:
varunzxzx 2017-10-07 11:19:51 +05:30
parent a7d4d4ecd3
commit 7342b4665d
3 changed files with 11 additions and 7 deletions

View file

@ -54,6 +54,7 @@ exports.createSubmission = function(req, res) {
timeElapsed = req.body.timeElapsed;
}
var submission = new FormSubmission({
form: req.body._id,
title: req.body.title,
form_fields: req.body.form_fields,
timeElapsed: timeElapsed,

View file

@ -11,6 +11,8 @@ var mongoose = require('mongoose'),
Random = require('random-js'),
mt = Random.engines.mt19937();
var shortid = require('shortid');
mt.autoSeed();
@ -84,6 +86,10 @@ var formSchemaOptions = {
* Form Schema
*/
var FormSchema = new Schema({
_id: {
type: String,
default: shortid.generate
},
title: {
type: String,
trim: true,
@ -262,12 +268,12 @@ FormSchema.virtual('analytics.fields').get(function () {
var totalViews = dropoffViews+continueViews;
var continueRate = 0;
var dropoffRate = 0;
if(totalViews > 0){
continueRate = (continueViews/totalViews*100).toFixed(0);
dropoffRate = (dropoffViews/totalViews*100).toFixed(0);
}
fieldDropoffs[i] = {
dropoffViews: dropoffViews,
responses: continueViews,
@ -442,4 +448,3 @@ FormSchema.pre('save', function (next) {
FormSchema.index({created: 1});
mongoose.model('Form', FormSchema);

View file

@ -8,8 +8,6 @@ var mongoose = require('mongoose'),
mUtilities = require('mongoose-utilities'),
FieldSchema = require('./form_field.server.model.js');
var shortid = require('shortid');
/**
* Form Submission Schema
*/
@ -21,9 +19,9 @@ var FormSubmissionSchema = new Schema({
form_fields: [FieldSchema],
form: {
type: Schema.Types.ObjectId,
ref: 'Form',
type: String,
default: shortid.generate
required: true
},
ipAddr: {