1 | const Joi = require('@hapi/joi');
|
2 | const { validate, prepare } = require('../../utils/options');
|
3 |
|
4 |
|
5 | const _id = Joi.number().min(1);
|
6 | const _ids = Joi.string().min(3);
|
7 |
|
8 |
|
9 | module.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 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | list: () => {
|
23 |
|
24 | return {
|
25 | method: 'GET',
|
26 | url: `${url}/api/v2/suspended_tickets.json`,
|
27 | headers
|
28 | };
|
29 | },
|
30 |
|
31 | |
32 |
|
33 |
|
34 |
|
35 |
|
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/suspended_tickets/${id}.json`,
|
47 | headers
|
48 | };
|
49 | },
|
50 |
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | recover: (options = {}) => {
|
58 | const { error } = Joi.object({
|
59 | id: _id.required()
|
60 | }).validate(options);
|
61 | if (error) throw new Error(error.details[0].message);
|
62 |
|
63 | const { id } = options;
|
64 | return {
|
65 | method: 'PUT',
|
66 | url: `${url}/api/v2/suspended_tickets/${id}/recover.json`,
|
67 | headers
|
68 | };
|
69 | },
|
70 |
|
71 | |
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | recover_many: (options = {}) => {
|
78 | const { error } = Joi.object({
|
79 | ids: _ids.required()
|
80 | }).validate(options);
|
81 | if (error) throw new Error(error.details[0].message);
|
82 |
|
83 | const { ids } = options;
|
84 | return {
|
85 | method: 'PUT',
|
86 | url: `${url}/api/v2/suspended_tickets/recover_many.json?ids=${ids}`,
|
87 | headers
|
88 | };
|
89 | },
|
90 |
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | delete: (options = {}) => {
|
98 | const { error } = Joi.object({
|
99 | id: _id.required()
|
100 | }).validate(options);
|
101 | if (error) throw new Error(error.details[0].message);
|
102 |
|
103 | const { id } = options;
|
104 | return {
|
105 | method: 'DELETE',
|
106 | url: `${url}/api/v2/suspended_tickets/${id}.json`,
|
107 | headers
|
108 | };
|
109 | },
|
110 |
|
111 | |
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 | delete_many: (options = {}) => {
|
118 | const { error } = Joi.object({
|
119 | ids: _ids.required()
|
120 | }).validate(options);
|
121 | if (error) throw new Error(error.details[0].message);
|
122 |
|
123 | const { ids } = options;
|
124 | return {
|
125 | method: 'DELETE',
|
126 | url: `${url}/api/v2/suspended_tickets/destroy_many.json?ids=${ids}`,
|
127 | headers
|
128 | };
|
129 | }
|
130 | };
|
131 | };
|