1 | const Joi = require('@hapi/joi');
|
2 | const { validate, prepare } = require('../../utils/options');
|
3 |
|
4 |
|
5 | const _id = Joi.number().min(1);
|
6 | const _ids = Joi.string().min(3);
|
7 | const _data = Joi.object();
|
8 |
|
9 |
|
10 | module.exports = (options = {}) => {
|
11 | const { error } = validate(options);
|
12 | if (error) throw new Error(error.details[0].message);
|
13 |
|
14 | const { url, headers } = prepare(options);
|
15 |
|
16 | return {
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | list: () => {
|
24 |
|
25 | return {
|
26 | method: 'GET',
|
27 | url: `${url}/api/v2/ticket_forms.json`,
|
28 | headers
|
29 | };
|
30 | },
|
31 |
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | create: (options = {}) => {
|
39 | const { error } = Joi.object({
|
40 | data: _data.required()
|
41 | }).validate(options);
|
42 | if (error) throw new Error(error.details[0].message);
|
43 |
|
44 | const { data } = options;
|
45 | return {
|
46 | method: 'POST',
|
47 | url: `${url}/api/v2/ticket_forms.json`,
|
48 | headers,
|
49 | data
|
50 | };
|
51 | },
|
52 |
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | show: (options = {}) => {
|
60 | const { error } = Joi.object({
|
61 | id: _id.required()
|
62 | }).validate(options);
|
63 | if (error) throw new Error(error.details[0].message);
|
64 |
|
65 | const { id } = options;
|
66 | return {
|
67 | method: 'GET',
|
68 | url: `${url}/api/v2/ticket_forms/${id}.json`,
|
69 | headers
|
70 | };
|
71 | },
|
72 |
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | show_many: (options = {}) => {
|
80 | const { error } = Joi.object({
|
81 | ids: _ids.required()
|
82 | }).validate(options);
|
83 | if (error) throw new Error(error.details[0].message);
|
84 |
|
85 | const { ids } = options;
|
86 | return {
|
87 | method: 'GET',
|
88 | url: `${url}/api/v2/ticket_forms/show_many.json?ids=${ids}`,
|
89 | headers
|
90 | };
|
91 | },
|
92 |
|
93 | |
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | update: (options = {}) => {
|
100 | const { error } = Joi.object({
|
101 | id: _id.required(),
|
102 | data: _data.required()
|
103 | }).validate(options);
|
104 | if (error) throw new Error(error.details[0].message);
|
105 |
|
106 | const { id, data } = options;
|
107 | return {
|
108 | method: 'PUT',
|
109 | url: `${url}/api/v2/ticket_forms/${id}.json`,
|
110 | headers,
|
111 | data
|
112 | };
|
113 | },
|
114 |
|
115 | |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | delete: (options = {}) => {
|
122 | const { error } = Joi.object({
|
123 | id: _id.required()
|
124 | }).validate(options);
|
125 | if (error) throw new Error(error.details[0].message);
|
126 |
|
127 | const { id } = options;
|
128 | return {
|
129 | method: 'DELETE',
|
130 | url: `${url}/api/v2/ticket_forms/${id}.json`,
|
131 | headers
|
132 | };
|
133 | },
|
134 |
|
135 | |
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 | reorder: (options = {}) => {
|
142 | const { error } = Joi.object({
|
143 | data: _data.required()
|
144 | }).validate(options);
|
145 | if (error) throw new Error(error.details[0].message);
|
146 |
|
147 | const { data } = options;
|
148 | return {
|
149 | method: 'PUT',
|
150 | url: `${url}/api/v2/ticket_forms/reorder.json`,
|
151 | headers,
|
152 | data
|
153 | };
|
154 | },
|
155 |
|
156 | |
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 | clone: (options = {}) => {
|
163 | const { error } = Joi.object({
|
164 | id: _id.required()
|
165 | }).validate(options);
|
166 | if (error) throw new Error(error.details[0].message);
|
167 |
|
168 | const { id } = options;
|
169 | return {
|
170 | method: 'POST',
|
171 | url: `${url}/api/v2/ticket_forms/${id}/clone.json`,
|
172 | headers
|
173 | };
|
174 | }
|
175 | };
|
176 | };
|