Last active
August 29, 2015 14:27
-
-
Save reecefenwick/5ee2d2c24045a33218f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Files = require('../services/FileService'); | |
module.exports.deleteFile = function (req, res, next) { | |
var query = {createdBy: req.user._id, key: req.params.key}; | |
var file = req.params._id; | |
Files.remove(query, file, function (err) { | |
if (err) return next(err); | |
res.status(204).json({}); | |
}) | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Uploads = require('../models/UploadService'); | |
module.exports.remove = function (query, file, callback) { | |
var update = { | |
$pull: { | |
files: { | |
_id: file | |
} | |
} | |
}; | |
// Calls the upload service to remove the file reference from db | |
Uploads.update(query, update, callback); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* routes.js | |
* | |
* @description :: Configure request router to appropriate Controllers | |
* @docs :: | |
*/ | |
'use strict'; | |
var express = require('express'); | |
var router = express.Router(); | |
var validate = require('express-jsonschema').validate; | |
var FileController = require('../src/main/api/controllers/FileController'); | |
// Load Middleware libraries | |
var auth = require('../src/main/shared/middleware/authentication'); | |
/** | |
* Map HTTP Endpoints to controllers | |
*/ | |
/** | |
* Configure File Resources | |
*/ | |
router | |
.route('/api/file') | |
.post(FileController.upload); | |
router | |
.route('/api/file/:_id') | |
.get(FileController.download) | |
.delete(auth.isAuthenticated, FileController.deleteFile); | |
module.exports = router; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment