Create A New Form
@param req
@param res
@param next
505308
function create(req, res, next) {
  var options = req.connectionOptions;
  req.user = req.user || {};
  var params = {
    userEmail: req.user.email || req.body.updatedBy
  };

  options = _.extend(options, params);

  logger.debug("Middleware: create form: ", {options: options});

  forms.updateForm(options, req.body, formsResultHandlers(constants.resultTypes.forms, req, next));
}
508361
function notFoundRequestHandler( req, res, next ) {
  var err = new Error( 'Not Found' )

  err.statusCode = 404
  next( err )
}
228762
function (req, res) {
    User.create({ firstName: req.body.firstName, lastName: req.body.lastName}).exec(function (err, user) {
      if(err) return res.json({ err: err }, 500);
      else res.json(user);
    });
  }
1039979
function (req, res) {
        var {name} = new {modelName}({{createFields}
        });

        {name}.save(function (err, {name}) {
            if (err) {
                return res.status(500).json({
                    message: 'Error when creating {name}',
                    error: err
                });
            }
            return res.status(201).json({name});
        });
    }
1161294
function deploy(req, res, next) {
  var dataSource = req.body;

  dataSource._id = req.params.id;

  forms.dataSources.deploy(req.connectionOptions, dataSource, dataSourcesHandler(constants.resultTypes.dataSources, req, next));
}
920773
function update(req, res, next) {
  var params = {
    appId: req.params.id || req.body._id,
    forms: req.body.forms || []
  };
  forms.updateAppForms(req.connectionOptions, params, formsResultHandlers(constants.resultTypes.formProjects, req, next));
}
476062
function listProjectSubmissions(req, res, next) {
  var formId = req.body.formId;
  var subIds = req.body.subid;

  var params = {
    wantRestrictions: false,
    appId: req.params.projectid
  };

  //Assigning Form Search If Set
  if (_.isString(formId)) {
    params.formId = formId;
  }

  //Assigning Submission Search Params If Set
  if (_.isArray(subIds)) {
    params.subid = subIds;
  } else if (_.isString(subIds)) {
    params.subid = [subIds];
  }

  logger.debug("Middleware listProjectSubmissions ", {params: params});

  forms.getSubmissions(req.connectionOptions, params, submissionsHandler(constants.resultTypes.submissions, req, next));
}
1112453
function deploy(req, res, next) {
  var options = req.connectionOptions;
  var form = req.body;
  req.user = req.user || {};

  if (req.appformsResultPayload && _.isObject(req.appformsResultPayload.data)) {
    form = req.appformsResultPayload.data;
  }

  //Expect A Data Source Data Set To Be Available If Deploying A Form.
  var params = {
    userEmail: req.user.email || req.body.updatedBy,
    expectDataSourceCache: true
  };

  options = _.extend(options, params);

  logger.debug("Middleware: Deploy form: ", {options: options});

  forms.updateOrCreateForm(options, form, formsResultHandlers(constants.resultTypes.forms, req, next));
}
309467
function update(req, res, next) {
  var options = req.connectionOptions;
  req.appformsResultPayload = req.appformsResultPayload || {};

  var params = {
    userEmail: req.user.email
  };

  options = _.extend(options, params);

  var form = req.body;

  if (_.isObject(req.appformsResultPayload.data) && !req.body._id) {
    form = req.appformsResultPayload.data;
  }

  logger.debug("Middleware: Update form: ", {options: options, form: form});

  forms.updateForm(options, form, formsResultHandlers(constants.resultTypes.forms, req, next));
}
448649
function createUser(form) {
      // refuse to work with invalid data
      if (vm.user._id || (form && !form.$valid)) {
        return;
      }

      Auth.createUser(vm.user)
        .then(createUserSuccess)
        .catch(createUserCatch);

      function createUserSuccess(newUser) {
        Toast.show({
          type: 'success',
          text: 'User ' + newUser.name + ' has been created',
          link: {state: 'admin.user.list.detail', params: {id: newUser._id}}
        });
        vm.close();
      }

      function createUserCatch(err) {
        if (form && err) {
          form.setResponseErrors(err);
        }

        Toast.show({
          type: 'warn',
          text: 'Error while creating a new user'
        });
      }
    }
28778
function updateTheme(req, res, next) {

  //No theme sent, no need update the project theme
  if (!req.body.theme) {
    return next();
  }

  var params = {
    appId: req.params.id || req.body._id,
    theme: req.body.theme
  };
  forms.setAppTheme(_.extend(req.connectionOptions, params), formsResultHandlers(constants.resultTypes.formProjects, req, next));
}
853433
function next() {
		
		var data = new Object();
		// Submit content of all forms -- except those with class 'ignore-form' -- before going to next page.
		$('#container form:not(.ignore-form)').each(function(index) {
			//console.log("Form no. "+index + " with the ID #" + $(this).attr('id') );
			//console.log($( this ).serializeArray() );
			data[$(this).attr('id')] = $( this ).serializeArray(); // Add each form's data to the data object.
		});
		
		if(isEmpty(data)) 
			cloak.message('next');
		else
			cloak.message('next', data);
	}
1185283
function list(req, res, next) {
  logger.debug("Middleware Submissions List ", {connectionOptions: req.connectionOptions});
  forms.getSubmissions(req.connectionOptions, {}, _getSubmissionsResultHandler(req, next));
}
780653
function(req, res){

            var insertJson = {};

            //Request DB structure
            lastQry = connection.query('SHOW COLUMNS FROM ??', req.params.table , function (err, columns) {
                if (err) return sendError(res,err.code);

                var value;

                //Forced sync iterator
                var iterator = function (i) {
                    if (i >= columns.length) {
                        insertIntoDB();
                        return;
                    }

                    var dbField = columns[i];
                    var field = dbField.Field;

                    //Check required fields
                    if (dbField.Null === 'NO' && 
                        dbField.Default === '' && 
                        dbField.Extra !== 'auto_increment' && 
                        dbField.Extra.search('on update')===-1) {

                        //Check if field not set
                        if (undefOrEmpty(req.body[field])) {
                            return sendError(res,"Field " + field + " is NOT NULL but not specified in this request");
                        } else {
                            //Check if the set values are roughly okay
                            value = checkIfSentvaluesAreSufficient(req,dbField);
                            console.log(value);
                            if(value !== false) {
                                //Value seems okay, go to the next field
                                insertJson[field] = value;
                                iterator(i + 1);
                            } else {
                                return sendError(res,'Value for field ' + field + ' is not sufficient. Expecting ' + dbField.Type + ' but got ' + typeof req.body[field] );
                            }
                        }
                    }  else {
                        //Check for not required fields
                        //Skip auto_incremented fields
                        if(dbField.Extra === 'auto_increment') {
                            iterator(i + 1);
                        } else {
                            //Check if the field was provided by the client
                            var defined = false;
                            if(dbField.Default == "FILE") {
                                if(req.files.hasOwnProperty(dbField.Field)) {
                                    defined = true;
                                }
                            } else {
                                if(typeof req.body[field] !== "undefined") {
                                    defined = true;
                                }
                            }

                            //If it was provided, check if the values are okay
                            if(defined) {
                                value = checkIfSentvaluesAreSufficient(req,dbField);
                                if(value !== false) {
                                    insertJson[field] = value;
                                    iterator(i + 1);
                                } else {
                                    if(dbField.Default == "FILE") {
                                        return sendError(res, 'Value for field ' + field + ' is not sufficient. Either the file is to large or an other error occured');
                                    } else {
                                        return sendError(res, 'Value for field ' + field + ' is not sufficient. Expecting ' + dbField.Type + ' but got ' + typeof req.body[field]);
                                    }
                                }
                            } else {
                                //If not, don't mind
                                iterator(i + 1);
                            }

                        }
                    }

                };

                iterator(0); //start the async "for" loop

                /**
                 * When the loop is finished write everything in the database
                 */
                function insertIntoDB() {
                    lastQry = connection.query('INSERT INTO ?? SET ?', [req.params.table , insertJson] , function (err, rows) {
                        if (err) {
                            console.error(err);
                            res.statusCode = 500;
                            res.send({
                                result: 'error',
                                err: err.code
                            });
                        } else {
                            sendSuccessAnswer(req.params.table , res, rows.insertId);
                        }

                    });
                }
            });
        }
338581
function post (req, res, next) {
    var prop = pluralize.singular(req.params.resource)
    req.body[prop + 'Id'] = utils.toNative(req.params.id)
    req.url = '/' + req.params.nested
    next()
  }
277907
function undeploy(req, res, next) {
  var removeParams = {
    _id: req.params.id
  };

  logger.debug("Middleware: undeploy form: ", {params: removeParams});

  forms.deleteForm(_.extend(req.connectionOptions, removeParams), formsResultHandlers(constants.resultTypes.forms, req, next));
}
242048
function createContext(req, res, context, done) {
  debug('default createContext - does nothing', context);
  process.nextTick(done.bind(null, null, context));
}