1 | const Joi = require('@hapi/joi');
|
2 | const { validate, prepare } = require('../../utils/options');
|
3 |
|
4 |
|
5 | const _data = Joi.object();
|
6 | const _ticket_id = Joi.number().positive();
|
7 | const _user_id = Joi.number().positive();
|
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 | record: (options = {}) => {
|
24 | const { error } = Joi.object({
|
25 | data: _data.required()
|
26 | }).validate(options);
|
27 | if (error) throw new Error(error.details[0].message);
|
28 |
|
29 | const { data } = options;
|
30 | return {
|
31 | method: 'POST',
|
32 | url: `${url}/api/v2/skips.json`,
|
33 | headers,
|
34 | data
|
35 | };
|
36 | },
|
37 |
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | list: (options = {}) => {
|
47 | const { error } = Joi.object({
|
48 | ticket_id: _ticket_id,
|
49 | user_id: _user_id
|
50 | }).validate(options);
|
51 | if (error) throw new Error(error.details[0].message);
|
52 |
|
53 | const { ticket_id = 0, user_id = 0 } = options;
|
54 | const section = ticket_id
|
55 | ? `tickets/${ticket_id}/`
|
56 | : user_id
|
57 | ? `users/${user_id}/`
|
58 | : '';
|
59 |
|
60 | return {
|
61 | method: 'GET',
|
62 | url: `${url}/api/v2/${section}skips.json`,
|
63 | headers
|
64 | };
|
65 | }
|
66 | };
|
67 | };
|