UNPKG

2.96 kBJavaScriptView Raw
1const Joi = require('@hapi/joi');
2const { validate, prepare } = require('../../utils/options');
3
4// Validation
5const _id = Joi.number().min(1);
6const _ticket_id = Joi.number().min(1);
7const _data = Joi.object();
8
9// Initialize Endpoint
10module.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 * List Comments
19 *
20 * GET /api/v2/tickets/{ticket_id}/comments.json
21 * https://developer.zendesk.com/rest_api/docs/support/ticket_comments#list-comments
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 * List Email CCs for a Comment
39 *
40 * GET /api/v2/tickets/{ticket_id}/comments.json?include=users
41 * https://developer.zendesk.com/rest_api/docs/support/ticket_comments#list-email-ccs-for-a-comment
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 * Redact String in Comment
59 *
60 * PUT /api/v2/tickets/{ticket_id}/comments/{id}/redact.json
61 * https://developer.zendesk.com/rest_api/docs/support/ticket_comments#redact-string-in-comment
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 * Make Comment Private
82 *
83 * PUT /api/v2/tickets/{ticket_id}/comments/{id}/make_private.json
84 * https://developer.zendesk.com/rest_api/docs/support/ticket_comments#make-comment-private
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};