2015-06-29 22:51:29 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module dependencies.
|
|
|
|
*/
|
|
|
|
var users = require('../../app/controllers/users.server.controller'),
|
2015-11-01 00:32:37 +00:00
|
|
|
forms = require('../../app/controllers/forms.server.controller'),
|
|
|
|
multer = require('multer'),
|
2016-08-26 00:54:16 +00:00
|
|
|
config = require('../../config/config'),
|
|
|
|
auth = require('../../config/passport_helpers');
|
2015-11-01 00:32:37 +00:00
|
|
|
|
|
|
|
// Setting the pdf upload route and folder
|
2016-04-29 02:48:02 +00:00
|
|
|
var storage = multer.diskStorage({
|
|
|
|
destination: function (req, file, cb) {
|
|
|
|
cb(null, config.tmpUploadPath);
|
|
|
|
},
|
|
|
|
filename: function (req, file, cb) {
|
|
|
|
var len = file.originalname.split('.').length;
|
|
|
|
var ext = file.originalname.split('.')[len-1];
|
|
|
|
cb(null, Date.now()+ '-' + file.fieldname + '.'+ext);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-05-10 17:13:20 +00:00
|
|
|
var upload = multer({
|
|
|
|
storage: storage
|
|
|
|
});
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
module.exports = function(app) {
|
|
|
|
// Form Routes
|
2016-05-13 18:13:09 +00:00
|
|
|
app.route('/forms')
|
2016-08-26 00:54:16 +00:00
|
|
|
.get(auth.isAuthenticatedOrApiKey, forms.list)
|
|
|
|
.post(auth.isAuthenticatedOrApiKey, forms.create);
|
2016-05-13 18:13:09 +00:00
|
|
|
|
2015-07-02 23:34:00 +00:00
|
|
|
app.route('/forms/:formId([a-zA-Z0-9]+)')
|
2015-06-29 22:51:29 +00:00
|
|
|
.get(forms.read)
|
2015-07-07 01:56:38 +00:00
|
|
|
.post(forms.createSubmission)
|
2016-08-26 00:54:16 +00:00
|
|
|
.put(auth.isAuthenticatedOrApiKey, forms.hasAuthorization, forms.update)
|
|
|
|
.delete(auth.isAuthenticatedOrApiKey, forms.hasAuthorization, forms.delete);
|
2015-06-29 22:51:29 +00:00
|
|
|
|
2015-07-02 23:34:00 +00:00
|
|
|
app.route('/forms/:formId([a-zA-Z0-9]+)/submissions')
|
2016-08-26 00:54:16 +00:00
|
|
|
.get(auth.isAuthenticatedOrApiKey, forms.hasAuthorization, forms.listSubmissions)
|
|
|
|
.delete(auth.isAuthenticatedOrApiKey, forms.hasAuthorization, forms.deleteSubmissions);
|
2015-07-02 23:34:00 +00:00
|
|
|
|
2015-06-29 22:51:29 +00:00
|
|
|
// Finish by binding the form middleware
|
|
|
|
app.param('formId', forms.formByID);
|
|
|
|
};
|