1 | const Joi = require('@hapi/joi');
|
2 | const { validate, prepare } = require('../../utils/options');
|
3 |
|
4 |
|
5 | const _id = Joi.number().min(1);
|
6 | const _ticket_id = Joi.number().min(1);
|
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: (options = {}) => {
|
24 | const { error } = Joi.object({
|
25 | ticket_id: _ticket_id.required()
|
26 | }).validate(options);
|
27 | if (error) throw new Error(error.details[0].message);
|
28 |
|
29 | const { ticket_id } = options;
|
30 | return {
|
31 | method: 'GET',
|
32 | url: `${url}/api/v2/tickets/${ticket_id}/comments.json`,
|
33 | headers
|
34 | };
|
35 | },
|
36 |
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | emailCCs: (options = {}) => {
|
44 | const { error } = Joi.object({
|
45 | ticket_id: _ticket_id.required()
|
46 | }).validate(options);
|
47 | if (error) throw new Error(error.details[0].message);
|
48 |
|
49 | const { ticket_id } = options;
|
50 | return {
|
51 | method: 'GET',
|
52 | url: `${url}/api/v2/tickets/${ticket_id}/comments.json?include=users`,
|
53 | headers
|
54 | };
|
55 | },
|
56 |
|
57 | |
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 | redact: (options = {}) => {
|
64 | const { error } = Joi.object({
|
65 | ticket_id: _ticket_id.required(),
|
66 | id: _id.required(),
|
67 | data: _data.required()
|
68 | }).validate(options);
|
69 | if (error) throw new Error(error.details[0].message);
|
70 |
|
71 | const { ticket_id, id, data } = options;
|
72 | return {
|
73 | method: 'PUT',
|
74 | url: `${url}/api/v2/tickets/${ticket_id}/comments/${id}/redact.json`,
|
75 | headers,
|
76 | data
|
77 | };
|
78 | },
|
79 |
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | makePrivate: (options = {}) => {
|
87 | const { error } = Joi.object({
|
88 | ticket_id: _ticket_id.required(),
|
89 | id: _id.required()
|
90 | }).validate(options);
|
91 | if (error) throw new Error(error.details[0].message);
|
92 |
|
93 | const { ticket_id, id } = options;
|
94 | return {
|
95 | method: 'PUT',
|
96 | url: `${url}/api/v2/tickets/${ticket_id}/comments/${id}/make_private.json`,
|
97 | headers,
|
98 | data: {}
|
99 | };
|
100 | }
|
101 | };
|
102 | };
|