1 | const Joi = require('@hapi/joi');
|
2 | const { validate, prepare } = require('../../utils/options');
|
3 |
|
4 |
|
5 | const _params = Joi.string().min(1);
|
6 | const _id = Joi.number().positive();
|
7 | const _ticket_id = Joi.number().positive();
|
8 | const _data = Joi.object();
|
9 |
|
10 |
|
11 | module.exports = (options = {}) => {
|
12 | const { error } = validate(options);
|
13 | if (error) throw new Error(error.details[0].message);
|
14 |
|
15 | const { url, headers } = prepare(options);
|
16 |
|
17 | return {
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | list_all: (options = {}) => {
|
26 | const { error } = Joi.object({
|
27 | params: _params
|
28 | }).validate(options);
|
29 | if (error) throw new Error(error.details[0].message);
|
30 |
|
31 | const { params } = options;
|
32 | return {
|
33 | method: 'GET',
|
34 | url: `${url}/api/v2/ticket_audits.json${params ? `?${params}` : ''}`,
|
35 | headers
|
36 | };
|
37 | },
|
38 |
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | list: (options = {}) => {
|
46 | const { error } = Joi.object({
|
47 | ticket_id: _ticket_id.required()
|
48 | }).validate(options);
|
49 | if (error) throw new Error(error.details[0].message);
|
50 |
|
51 | const { ticket_id } = options;
|
52 | return {
|
53 | method: 'GET',
|
54 | url: `${url}/api/v2/tickets/${ticket_id}/audits.json`,
|
55 | headers
|
56 | };
|
57 | },
|
58 |
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | show: (options = {}) => {
|
66 | const { error } = Joi.object({
|
67 | ticket_id: _ticket_id.required(),
|
68 | id: _id.required()
|
69 | }).validate(options);
|
70 | if (error) throw new Error(error.details[0].message);
|
71 |
|
72 | const { ticket_id, id } = options;
|
73 | return {
|
74 | method: 'GET',
|
75 | url: `${url}/api/v2/tickets/${ticket_id}/audits/${id}.json`,
|
76 | headers
|
77 | };
|
78 | },
|
79 |
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | change: (options = {}) => {
|
87 | const { error } = Joi.object({
|
88 | ticket_id: _ticket_id.required(),
|
89 | id: _id.required(),
|
90 | data: _data.required()
|
91 | }).validate(options);
|
92 | if (error) throw new Error(error.details[0].message);
|
93 |
|
94 | const { ticket_id, id, data } = options;
|
95 | return {
|
96 | method: 'PUT',
|
97 | url: `${url}/api/v2/tickets/${ticket_id}/audits/${id}/make_private.json`,
|
98 | headers,
|
99 | data
|
100 | };
|
101 | }
|
102 | };
|
103 | };
|