show stories in dropdown

This commit is contained in:
Riley Davis
2017-06-09 14:10:21 -06:00
parent 06da4d7d26
commit de665b3a0d
12 changed files with 233 additions and 4 deletions
+12
View File
@@ -19,6 +19,17 @@ const genAssetsByID = (context, ids) => AssetModel.find({
}
}).then(util.singleJoinBy(ids, 'id'));
/**
* [getAssetsByQuery description]
* @param {Object} context the context of the request
* @param {String} value text string to search agains the documents
* @param {Number} limit limit the number of results
* @return {Promise} resolves the assets
*/
const getAssetsByQuery = (context, value, limit) => {
return AssetsService.search(value, null, limit);
};
/**
* This endpoint find or creates an asset at the given url when it is loaded.
* @param {Object} context the context of the request
@@ -65,6 +76,7 @@ module.exports = (context) => ({
// this operation create a new asset if one isn't found.
getByURL: (url) => findOrCreateAssetByURL(context, url),
search: (value, limit) => getAssetsByQuery(context, value, limit),
getByID: new DataLoader((ids) => genAssetsByID(context, ids)),
getForMetrics: () => getAssetsForMetrics(context),
getAll: new util.SingletonResolver(() => AssetModel.find({}))
+4 -2
View File
@@ -6,12 +6,14 @@ const {
} = require('../../perms/constants');
const RootQuery = {
assets(_, args, {loaders: {Assets}, user}) {
assets(_, {query}, {loaders: {Assets}, user}) {
if (user == null || !user.can(SEARCH_ASSETS)) {
return null;
}
return Assets.getAll.load();
const {value = '', limit} = query;
return Assets.search(value, limit);
},
asset(_, query, {loaders: {Assets}}) {
if (query.id) {
+11 -1
View File
@@ -112,6 +112,16 @@ input UsersQuery {
sort: SORT_ORDER = REVERSE_CHRONOLOGICAL
}
# AssetsQuery allows teh ability to query assets by specific fields
input AssetsQuery {
# a search string to match against titles, authors, urls, etc.
value: String = ""
# Limit the number of results to be returned
limit: Int = 10
}
################################################################################
## Comments
################################################################################
@@ -586,7 +596,7 @@ type RootQuery {
comment(id: ID!): Comment
# All assets. Requires the `ADMIN` role.
assets: [Asset]
assets(query: AssetsQuery!): [Asset]
# Find or create an asset by url, or just find with the ID.
asset(id: ID, url: String): Asset