1 | const Joi = require('@hapi/joi');
|
2 | const { validate, prepare } = require('../../utils/options');
|
3 |
|
4 |
|
5 | const _id = Joi.number().positive();
|
6 | const _holiday_id = Joi.number().positive();
|
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/business_hours/schedules.json`,
|
28 | headers
|
29 | };
|
30 | },
|
31 |
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | show: (options = {}) => {
|
39 | const { error } = Joi.object({
|
40 | id: _id.required()
|
41 | }).validate(options);
|
42 | if (error) throw new Error(error.details[0].message);
|
43 |
|
44 | const { id } = options;
|
45 | return {
|
46 | method: 'GET',
|
47 | url: `${url}/api/v2/business_hours/schedules/${id}.json`,
|
48 | headers
|
49 | };
|
50 | },
|
51 |
|
52 | |
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | create: (options = {}) => {
|
59 | const { error } = Joi.object({
|
60 | data: _data.required()
|
61 | }).validate(options);
|
62 | if (error) throw new Error(error.details[0].message);
|
63 |
|
64 | const { data } = options;
|
65 | return {
|
66 | method: 'POST',
|
67 | url: `${url}/api/v2/business_hours/schedules.json`,
|
68 | headers,
|
69 | data
|
70 | };
|
71 | },
|
72 |
|
73 | |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 | update: (options = {}) => {
|
80 | const { error } = Joi.object({
|
81 | id: _id.required(),
|
82 | data: _data.required()
|
83 | }).validate(options);
|
84 | if (error) throw new Error(error.details[0].message);
|
85 |
|
86 | const { id, data } = options;
|
87 | return {
|
88 | method: 'PUT',
|
89 | url: `${url}/api/v2/business_hours/schedules/${id}.json`,
|
90 | headers,
|
91 | data
|
92 | };
|
93 | },
|
94 |
|
95 | |
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | delete: (options = {}) => {
|
102 | const { error } = Joi.object({
|
103 | id: _id.required()
|
104 | }).validate(options);
|
105 | if (error) throw new Error(error.details[0].message);
|
106 |
|
107 | const { id } = options;
|
108 | return {
|
109 | method: 'DELETE',
|
110 | url: `${url}/api/v2/business_hours/schedules/${id}.json`,
|
111 | headers
|
112 | };
|
113 | },
|
114 |
|
115 | |
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | update_intervals: (options = {}) => {
|
122 | const { error } = Joi.object({
|
123 | id: _id.required(),
|
124 | data: _data.required()
|
125 | }).validate(options);
|
126 | if (error) throw new Error(error.details[0].message);
|
127 |
|
128 | const { id, data } = options;
|
129 | return {
|
130 | method: 'PUT',
|
131 | url: `${url}/api/v2/business_hours/schedules/${id}/workweek.json`,
|
132 | headers,
|
133 | data
|
134 | };
|
135 | },
|
136 |
|
137 | |
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | list_holidays: (options = {}) => {
|
144 | const { error } = Joi.object({
|
145 | id: _id.required()
|
146 | }).validate(options);
|
147 | if (error) throw new Error(error.details[0].message);
|
148 |
|
149 | const { id } = options;
|
150 | return {
|
151 | method: 'GET',
|
152 | url: `${url}/api/v2/business_hours/schedules/${id}/holidays.json`,
|
153 | headers
|
154 | };
|
155 | },
|
156 |
|
157 | |
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | show_holiday: (options = {}) => {
|
164 | const { error } = Joi.object({
|
165 | id: _id.required(),
|
166 | holiday_id: _holiday_id.required()
|
167 | }).validate(options);
|
168 | if (error) throw new Error(error.details[0].message);
|
169 |
|
170 | const { id, holiday_id } = options;
|
171 | return {
|
172 | method: 'GET',
|
173 | url: `${url}/api/v2/business_hours/schedules/${id}/holidays/${holiday_id}.json`,
|
174 | headers
|
175 | };
|
176 | },
|
177 |
|
178 | |
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 | create_holiday: (options = {}) => {
|
185 | const { error } = Joi.object({
|
186 | id: _id.required(),
|
187 | data: _data.required()
|
188 | }).validate(options);
|
189 | if (error) throw new Error(error.details[0].message);
|
190 |
|
191 | const { id, data } = options;
|
192 | return {
|
193 | method: 'POST',
|
194 | url: `${url}/api/v2/business_hours/schedules/${id}/holidays.json`,
|
195 | headers,
|
196 | data
|
197 | };
|
198 | },
|
199 |
|
200 | |
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | update_holiday: (options = {}) => {
|
207 | const { error } = Joi.object({
|
208 | id: _id.required(),
|
209 | holiday_id: _holiday_id.required(),
|
210 | data: _data.required()
|
211 | }).validate(options);
|
212 | if (error) throw new Error(error.details[0].message);
|
213 |
|
214 | const { id, holiday_id, data } = options;
|
215 | return {
|
216 | method: 'PUT',
|
217 | url: `${url}/api/v2/business_hours/schedules/${id}/holidays/${holiday_id}.json`,
|
218 | headers,
|
219 | data
|
220 | };
|
221 | },
|
222 |
|
223 | |
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 | delete_holiday: (options = {}) => {
|
230 | const { error } = Joi.object({
|
231 | id: _id.required(),
|
232 | holiday_id: _holiday_id.required()
|
233 | }).validate(options);
|
234 | if (error) throw new Error(error.details[0].message);
|
235 |
|
236 | const { id, holiday_id } = options;
|
237 | return {
|
238 | method: 'DELETE',
|
239 | url: `${url}/api/v2/business_hours/schedules/${id}/holidays/${holiday_id}.json`,
|
240 | headers
|
241 | };
|
242 | }
|
243 | };
|
244 | };
|