3 var restful = require('../../../services/restful');
4 var restSerializer = require('../../../serializers/rest-serializer');
5 var repoService = require('../../../services/repo-service');
6 var createTextFilter = require('text-filter');
7 var StatusError = require('statuserror');
9 function indexQuery(req) {
10 var limit = parseInt(req.query.limit, 10) || 0;
12 return repoService.getReposForUser(req.user).then(function(repos) {
13 var query = (req.query.q || '').replace(/\*|\+|\$/g, '');
14 var filteredRepos = repos.filter(createTextFilter({ query: query, fields: ['full_name'] }));
16 var strategyOptions = { currentUserId: req.user.id };
17 // if (req.query.include_users) strategyOptions.mapUsers = true;
19 var strategy = new restSerializer.SearchResultsStrategy({
20 resultItemStrategy: new restSerializer.GithubRepoStrategy(strategyOptions)
24 filteredRepos = filteredRepos.slice(0, limit + 1);
27 return restSerializer.serializeObject({ results: filteredRepos }, strategy);
33 index: function(req) {
34 if (!req.user) throw new StatusError(401);
37 return indexQuery(req);
40 if (req.query.type === 'admin') {
41 return restful.serializeAdminReposForUser(req.user);
44 return restful.serializeReposForUser(req.user);