diff --git a/.eslintignore b/.eslintignore index b051c6c57..6cb6a3bc3 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ client +dist diff --git a/models/asset.js b/models/asset.js index afae0c677..5864d6409 100644 --- a/models/asset.js +++ b/models/asset.js @@ -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(); }; diff --git a/routes/api/asset/index.js b/routes/api/asset/index.js index 0b3959204..235958aaa 100644 --- a/routes/api/asset/index.js +++ b/routes/api/asset/index.js @@ -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); }); diff --git a/swagger.yaml b/swagger.yaml index ca7ef29d0..acc696ec6 100644 --- a/swagger.yaml +++ b/swagger.yaml @@ -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: