UNPKG

1.82 kBJavaScriptView Raw
1const Joi = require('@hapi/joi');
2const { validate, prepare } = require('../../utils/options');
3
4// Validation
5const _data = Joi.object();
6const _ticket_id = Joi.number().positive();
7const _user_id = Joi.number().positive();
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 * Record a new skip for the current user
19 *
20 * POST /api/v2/skips.json
21 * https://developer.zendesk.com/rest_api/docs/support/ticket_skips#record-a-new-skip-for-the-current-user
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 * List skips for the current account
40 *
41 * GET /api/v2/skips.json
42 * GET /api/v2/tickets/{ticket_id}/skips.json
43 * GET /api/v2/users/{user_id}/skips.json
44 * https://developer.zendesk.com/rest_api/docs/support/ticket_skips#list-skips-for-the-current-account
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};