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 | module.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 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | list: () => {
|
22 |
|
23 | return {
|
24 | method: 'GET',
|
25 | url: `${url}/api/v2/custom_roles.json`,
|
26 | headers
|
27 | };
|
28 | },
|
29 |
|
30 | |
31 |
|
32 |
|
33 |
|
34 |
|
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/custom_roles/${id}.json`,
|
46 | headers
|
47 | };
|
48 | },
|
49 |
|
50 | |
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | create: (options = {}) => {
|
57 | const { error } = Joi.object({
|
58 | data: _data.required()
|
59 | }).validate(options);
|
60 | if (error) throw new Error(error.details[0].message);
|
61 |
|
62 | const { data } = options;
|
63 | return {
|
64 | method: 'POST',
|
65 | url: `${url}/api/v2/custom_roles.json`,
|
66 | headers,
|
67 | data
|
68 | };
|
69 | },
|
70 |
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | update: (options = {}) => {
|
78 | const { error } = Joi.object({
|
79 | id: _id.required(),
|
80 | data: _data.required()
|
81 | }).validate(options);
|
82 | if (error) throw new Error(error.details[0].message);
|
83 |
|
84 | const { id, data } = options;
|
85 | return {
|
86 | method: 'PUT',
|
87 | url: `${url}/api/v2/custom_roles/${id}.json`,
|
88 | headers,
|
89 | data
|
90 | };
|
91 | },
|
92 |
|
93 | |
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | delete: (options = {}) => {
|
100 | const { error } = Joi.object({
|
101 | id: _id.required()
|
102 | }).validate(options);
|
103 | if (error) throw new Error(error.details[0].message);
|
104 |
|
105 | const { id } = options;
|
106 | return {
|
107 | method: 'DELETE',
|
108 | url: `${url}/api/v2/custom_roles/${id}.json`,
|
109 | headers
|
110 | };
|
111 | }
|
112 | };
|
113 | };
|