UNPKG

1.46 kBJavaScriptView Raw
1const Joi = require('@hapi/joi');
2const { validate, prepare } = require('../../utils/options');
3
4// Validation
5const _data = Joi.object().min(1);
6
7// Initialize Endpoint
8module.exports = (options = {}) => {
9 const { error } = validate(options);
10 if (error) throw new Error(error.details[0].message);
11
12 const { url, headers } = prepare(options);
13
14 return {
15 /**
16 * Ticket Import
17 *
18 * POST /api/v2/imports/tickets.json
19 * https://developer.zendesk.com/rest_api/docs/support/ticket_import#ticket-import
20 */
21 single: (options = {}) => {
22 const { error } = Joi.object({
23 data: _data.required()
24 }).validate(options);
25 if (error) throw new Error(error.details[0].message);
26
27 const { data } = options;
28 return {
29 method: 'POST',
30 url: `${url}/api/v2/imports/tickets.json`,
31 headers,
32 data
33 };
34 },
35
36 /**
37 * Ticket Bulk Import
38 *
39 * POST /api/v2/imports/tickets/create_many.json
40 * https://developer.zendesk.com/rest_api/docs/support/ticket_import#ticket-bulk-import
41 */
42 bulk: (options = {}) => {
43 const { error } = Joi.object({
44 data: _data.required()
45 }).validate(options);
46 if (error) throw new Error(error.details[0].message);
47
48 const { data } = options;
49 return {
50 method: 'POST',
51 url: `${url}/api/v2/imports/tickets/create_many.json`,
52 headers,
53 data
54 };
55 }
56 };
57};