1 | const Joi = require('@hapi/joi');
|
2 | const { validate, prepare } = require('../../utils/options');
|
3 |
|
4 |
|
5 | const _id = Joi.number().min(1);
|
6 | const _data = Joi.object();
|
7 |
|
8 |
|
9 | module.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 |
|
18 |
|
19 |
|
20 |
|
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 |
|
38 |
|
39 |
|
40 |
|
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 | };
|