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'),
|
|
|
|
config = require('../../config/config');
|
|
|
|
|
|
|
|
// Setting the pdf upload route and folder
|
|
|
|
var upload = multer({ dest: config.tmpUploadPath,
|
|
|
|
rename: function (fieldname, filename) {
|
|
|
|
return Date.now();
|
|
|
|
},
|
|
|
|
onFileUploadStart: function (file) {
|
|
|
|
//Check to make sure we can only upload images and pdfs
|
|
|
|
console.log(file.originalname + ' is starting ...');
|
|
|
|
},
|
|
|
|
onFileUploadComplete: function (file, req, res) {
|
|
|
|
console.log(file.originalname + ' uploaded to ' + file.path);
|
|
|
|
// console.log('\n\nheadersSent in onFileUploadComplete: ', res.headersSent);
|
|
|
|
// res.status(200).send(file);
|
|
|
|
}
|
|
|
|
});
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
module.exports = function(app) {
|
|
|
|
// Form Routes
|
|
|
|
app.route('/upload/pdf')
|
2015-11-01 00:32:37 +00:00
|
|
|
.post(users.requiresLogin, upload.single('file'), forms.uploadPDF);
|
2015-06-29 22:51:29 +00:00
|
|
|
|
|
|
|
app.route('/forms')
|
2015-07-01 23:14:39 +00:00
|
|
|
.get(users.requiresLogin, forms.list)
|
2015-06-29 22:51:29 +00:00
|
|
|
.post(users.requiresLogin, forms.create);
|
|
|
|
|
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)
|
2015-06-29 22:51:29 +00:00
|
|
|
.put(users.requiresLogin, forms.hasAuthorization, forms.update)
|
2015-06-30 17:36:51 +00:00
|
|
|
.delete(users.requiresLogin, 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')
|
2015-07-27 18:11:43 +00:00
|
|
|
.get(users.requiresLogin, forms.hasAuthorization, forms.listSubmissions)
|
|
|
|
.delete(users.requiresLogin, 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);
|
|
|
|
};
|