UNPKG

1.43 kBJavaScriptView Raw
1const Joi = require('@hapi/joi');
2const { validate, prepare } = require('../../utils/options');
3
4// Validation
5const _id = Joi.number().min(1);
6const _data = Joi.object();
7
8// Initialize Endpoint
9module.exports = (options = {}) => {
10 const { error } = validate(options);
11 if (error) throw new Error(error.details[0].message);
12
13 const { url, headers } = prepare(options);
14
15 return {
16 /**
17 * Show User
18 *
19 * GET /api/v2/end_users/{id}.json
20 * https://developer.zendesk.com/rest_api/docs/support/end_user#show-user
21 */
22 show: (options = {}) => {
23 const { error } = Joi.object({
24 id: _id.required()
25 }).validate(options);
26 if (error) throw new Error(error.details[0].message);
27
28 const { id } = options;
29 return {
30 method: 'GET',
31 url: `${url}/api/v2/end_users/${id}.json`,
32 headers
33 };
34 },
35
36 /**
37 * Update User
38 *
39 * PUT /api/v2/end_users/{id}.json
40 * https://developer.zendesk.com/rest_api/docs/support/end_user#update-user
41 */
42 update: (options = {}) => {
43 const { error } = Joi.object({
44 id: _id.required(),
45 data: _data.required()
46 }).validate(options);
47 if (error) throw new Error(error.details[0].message);
48
49 const { id, data } = options;
50 return {
51 method: 'PUT',
52 url: `${url}/api/v2/end_users/${id}.json`,
53 headers,
54 data
55 };
56 }
57 };
58};