mirror of
https://github.com/wassname/talk.git
synced 2026-08-13 12:40:11 +08:00
Move url route into general asset search
This commit is contained in:
+2
-2
@@ -38,9 +38,9 @@ const AssetSchema = new Schema({
|
||||
/**
|
||||
* Search for assets. Currently only returns all.
|
||||
*/
|
||||
AssetSchema.statics.search = function() {
|
||||
AssetSchema.statics.search = function(query) {
|
||||
|
||||
return Asset.find({});
|
||||
return Asset.find(query);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -2,10 +2,16 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
const Asset = require('../../../models/asset');
|
||||
|
||||
// Get many assets
|
||||
// Search assets.
|
||||
router.get('/', (req, res) => {
|
||||
|
||||
Asset.search(req.params.id)
|
||||
let query = {};
|
||||
|
||||
if (typeof req.query.url !== 'undefined') {
|
||||
query.url = req.query.url;
|
||||
}
|
||||
|
||||
Asset.search(query)
|
||||
.then((asset) => {
|
||||
res.json(asset);
|
||||
});
|
||||
@@ -22,16 +28,6 @@ router.get('/:id', (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
// Get an asset by url
|
||||
router.get('/url/:url', (req, res) => {
|
||||
|
||||
Asset.findByUrl(req.params.url)
|
||||
.then((asset) => {
|
||||
res.json(asset);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// Upsert an asset and return the affected document.
|
||||
router.put('/', (req, res) => {
|
||||
|
||||
|
||||
+8
-5
@@ -11,7 +11,7 @@ should; // nullop to satisfy linting
|
||||
chai.use(chaiHttp);
|
||||
|
||||
var fixture = {
|
||||
'url': 'simple',
|
||||
'url': 'http://hhgg.com/total-perspective-vortex',
|
||||
'type': 'article',
|
||||
'headline': 'The Total Perspective Vortex',
|
||||
'summary': 'You are an insignificant dot on an insignificant dot.',
|
||||
@@ -81,7 +81,7 @@ describe('Asset', () => {
|
||||
|
||||
// Load the asset to make sure it's really there.
|
||||
chai.request(server)
|
||||
.get('/api/v1/asset/url/' + fixture.url)
|
||||
.get('/api/v1/asset?url=' + fixture.url)
|
||||
.end((err, res) => {
|
||||
|
||||
if (err) {
|
||||
@@ -89,12 +89,15 @@ describe('Asset', () => {
|
||||
}
|
||||
|
||||
res.should.have.status(200);
|
||||
res.body.should.be.a('object');
|
||||
res.body.should.have.property('id');
|
||||
res.body.should.be.an('array');
|
||||
|
||||
let asset = res.body[0];
|
||||
|
||||
expect(asset).to.have.property('id');
|
||||
|
||||
// Ensure the asset has the same id as above.
|
||||
// This tests the single url per Id concept.
|
||||
expect(assetId).to.equal(res.body.id);
|
||||
expect(assetId).to.equal(asset.id);
|
||||
|
||||
done();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user