-
Notifications
You must be signed in to change notification settings - Fork 168
/
listTags.js
58 lines (54 loc) · 1.85 KB
/
listTags.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict';
const boom = require('boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const listSchema = joi.array().items(schema.models.commandTag.base).label('List of command tags');
const namespaceSchema = joi.reach(schema.models.commandTag.base, 'namespace');
const nameSchema = joi.reach(schema.models.commandTag.base, 'name');
module.exports = () => ({
method: 'GET',
path: '/commands/{namespace}/{name}/tags',
config: {
description: 'Get all command tags for a given command namespace and name',
notes: 'Returns all command tags for a given command namespace and name',
tags: ['api', 'commands', 'tags'],
auth: {
strategies: ['token'],
scope: ['user', 'build']
},
plugins: {
'hapi-swagger': {
security: [{ token: [] }]
}
},
handler: (request, reply) => {
const factory = request.server.app.commandTagFactory;
const config = {
params: {
namespace: request.params.namespace,
name: request.params.name
},
sort: request.query.sort
};
if (request.query.page || request.query.count) {
config.paginate = {
page: request.query.page,
count: request.query.count
};
}
return factory.list(config)
.then(tags => reply(tags.map(p => p.toJson())))
.catch(err => reply(boom.boomify(err)));
},
response: {
schema: listSchema
},
validate: {
params: {
namespace: namespaceSchema,
name: nameSchema
},
query: schema.api.pagination
}
}
});