UNPKG

1.81 kBJavaScriptView Raw
1const Joi = require('@hapi/joi');
2const { validate, prepare } = require('../../utils/options');
3
4// Validation
5const _id = Joi.number().positive();
6const _ids = Joi.string().min(3);
7
8// Initialize Endpoint
9module.exports = (options = {}) => {
10 const { error } = validate(options);
11 if (error) throw new Error(error.details[0].message);
12
13 const { url, headers } = prepare(options);
14
15 return {
16 /**
17 * List Job Statuses
18 *
19 * GET /api/v2/job_statuses.json
20 * https://developer.zendesk.com/rest_api/docs/support/job_statuses#list-job-statuses
21 */
22 list: () => {
23 // Ignore any options
24 return {
25 method: 'GET',
26 url: `${url}/api/v2/job_statuses.json`,
27 headers
28 };
29 },
30
31 /**
32 * Show Job Status
33 *
34 * GET /api/v2/job_statuses/{id}.json
35 * https://developer.zendesk.com/rest_api/docs/support/tickets#show-ticket
36 */
37 show: (options = {}) => {
38 const { error } = Joi.object({
39 id: _id.required()
40 }).validate(options);
41 if (error) throw new Error(error.details[0].message);
42
43 const { id } = options;
44 return {
45 method: 'GET',
46 url: `${url}/api/v2/job_statuses/${id}.json`,
47 headers
48 };
49 },
50
51 /**
52 * Show Many Job Statuses
53 *
54 * GET /api/v2/job_statuses/show_many.json?ids={ids}
55 * https://developer.zendesk.com/rest_api/docs/support/job_statuses#show-many-job-statuses
56 */
57 show_many: (options = {}) => {
58 const { error } = Joi.object({
59 ids: _ids.required()
60 }).validate(options);
61 if (error) throw new Error(error.details[0].message);
62
63 const { ids } = options;
64 return {
65 method: 'GET',
66 url: `${url}/api/v2/job_statuses/show_many.json?ids=${ids}`,
67 headers
68 };
69 }
70 };
71};