-
Notifications
You must be signed in to change notification settings - Fork 169
/
Copy pathget.js
47 lines (43 loc) · 1.23 KB
/
get.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
'use strict';
const boom = require('@hapi/boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const getSchema = schema.models.banner.get;
const idSchema = schema.models.banner.base.extract('id');
module.exports = () => ({
method: 'GET',
path: '/banners/{id}',
options: {
description: 'Get a single banner',
notes: 'Return a banner record',
tags: ['api', 'banners'],
plugins: {
'hapi-rate-limit': {
enabled: false
}
},
handler: async (request, h) => {
const { bannerFactory } = request.server.app;
const { id } = request.params;
return bannerFactory
.get(id)
.then(banner => {
if (!banner) {
throw boom.notFound(`Banner ${id} does not exist`);
}
return h.response(banner.toJson());
})
.catch(err => {
throw err;
});
},
response: {
schema: getSchema
},
validate: {
params: joi.object({
id: idSchema
})
}
}
});