UNPKG

1.35 kBJavaScriptView Raw
1const Joi = require('@hapi/joi');
2const { validate, prepare } = require('../../utils/options');
3
4// Validation
5const _id = Joi.number().positive();
6
7// Initialize Endpoint
8module.exports = (options = {}) => {
9 const { error } = validate(options);
10 if (error) throw new Error(error.details[0].message);
11
12 const { url, headers } = prepare(options);
13
14 return {
15 /**
16 * List Reasons for Satisfaction Rating
17 *
18 * GET /api/v2/satisfaction_reasons.json
19 * https://developer.zendesk.com/rest_api/docs/support/satisfaction_reasons#list-reasons-for-satisfaction-rating
20 */
21 list: () => {
22 // Ignore any options
23 return {
24 method: 'GET',
25 url: `${url}/api/v2/satisfaction_reasons.json`,
26 headers
27 };
28 },
29
30 /**
31 * Show Reason for Satisfaction Rating
32 *
33 * GET /api/v2/satisfaction_reasons/{id}.json
34 * https://developer.zendesk.com/rest_api/docs/support/satisfaction_reasons#show-reason-for-satisfaction-rating
35 */
36 show: (options = {}) => {
37 const { error } = Joi.object({
38 id: _id.required()
39 }).validate(options);
40 if (error) throw new Error(error.details[0].message);
41
42 const { id } = options;
43 return {
44 method: 'GET',
45 url: `${url}/api/v2/satisfaction_reasons/${id}.json`,
46 headers
47 };
48 }
49 };
50};