Update based on review

This commit is contained in:
David Erwin
2016-11-07 13:07:25 -05:00
parent 2ff6bcf85d
commit c84fc24f78
4 changed files with 14 additions and 20 deletions
+1
View File
@@ -1 +1,2 @@
client
dist
+4 -5
View File
@@ -26,7 +26,6 @@ const AssetSchema = new Schema({
authors: [String],
publication_date: Date
},{
_id: false,
versionKey: false,
timestamps: {
createdAt: 'created_at',
@@ -40,7 +39,7 @@ const AssetSchema = new Schema({
*/
AssetSchema.statics.search = function(query) {
return Asset.find(query);
return Asset.find(query).exec();
};
@@ -50,7 +49,7 @@ AssetSchema.statics.search = function(query) {
*/
AssetSchema.statics.findById = function(id) {
return Asset.findOne({id});
return Asset.findOne({id}).exec();
};
@@ -60,7 +59,7 @@ AssetSchema.statics.findById = function(id) {
*/
AssetSchema.statics.findByUrl = function(url) {
return Asset.findOne({'url': url});
return Asset.findOne({'url': url}).exec();
};
@@ -100,7 +99,7 @@ AssetSchema.statics.upsert = function(data) {
*/
AssetSchema.statics.removeAll = function(query) {
return Asset.remove(query);
return Asset.remove(query).exec();
};
+8 -11
View File
@@ -3,7 +3,7 @@ const router = express.Router();
const Asset = require('../../../models/asset');
// Search assets.
router.get('/', (req, res) => {
router.get('/', (req, res, next) => {
let query = {};
@@ -14,33 +14,30 @@ router.get('/', (req, res) => {
Asset.search(query)
.then((asset) => {
res.json(asset);
});
})
.catch(next);
});
// Get an asset by id
router.get('/:id', (req, res) => {
router.get('/:id', (req, res, next) => {
Asset.findById(req.params.id)
.then((asset) => {
res.json(asset);
});
})
.catch(next);
});
// Upsert an asset and return the affected document.
router.put('/', (req, res) => {
router.put('/', (req, res, next) => {
Asset.upsert(req.body)
.then((asset) => {
res.json(asset);
})
.catch((err) => {
console.error(err);
res.json(err);
});
.catch(next);
});
+1 -4
View File
@@ -179,7 +179,7 @@ paths:
responses:
204:
description: OK
/asset/url/{url}:
/asset?url={url}:
get:
tags:
- Asset
@@ -192,9 +192,6 @@ paths:
responses:
200:
description: OK
404:
description: Not Found
definitions:
Item: