1 | const Joi = require('@hapi/joi');
|
2 | const { validate, prepare } = require('../../utils/options');
|
3 |
|
4 |
|
5 | const _data = Joi.object().min(1);
|
6 |
|
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 | single: (options = {}) => {
|
22 | const { error } = Joi.object({
|
23 | data: _data.required()
|
24 | }).validate(options);
|
25 | if (error) throw new Error(error.details[0].message);
|
26 |
|
27 | const { data } = options;
|
28 | return {
|
29 | method: 'POST',
|
30 | url: `${url}/api/v2/imports/tickets.json`,
|
31 | headers,
|
32 | data
|
33 | };
|
34 | },
|
35 |
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | bulk: (options = {}) => {
|
43 | const { error } = Joi.object({
|
44 | data: _data.required()
|
45 | }).validate(options);
|
46 | if (error) throw new Error(error.details[0].message);
|
47 |
|
48 | const { data } = options;
|
49 | return {
|
50 | method: 'POST',
|
51 | url: `${url}/api/v2/imports/tickets/create_many.json`,
|
52 | headers,
|
53 | data
|
54 | };
|
55 | }
|
56 | };
|
57 | };
|