1 | const Joi = require('@hapi/joi');
|
2 | const { validate, prepare } = require('../../utils/options');
|
3 |
|
4 |
|
5 | const _params = Joi.string().min(1);
|
6 | const _id = Joi.number().positive();
|
7 | const _ticket_id = Joi.number().positive();
|
8 | const _data = Joi.object();
|
9 |
|
10 |
|
11 | module.exports = (options = {}) => {
|
12 | const { error } = validate(options);
|
13 | if (error) throw new Error(error.details[0].message);
|
14 |
|
15 | const { url, headers } = prepare(options);
|
16 |
|
17 | return {
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | list: (options = {}) => {
|
25 | const { error } = Joi.object({
|
26 | params: _params
|
27 | }).validate(options);
|
28 | if (error) throw new Error(error.details[0].message);
|
29 |
|
30 | const { params } = options;
|
31 | const paramStr = params ? `?${params}` : '';
|
32 | return {
|
33 | method: 'GET',
|
34 | url: `${url}/api/v2/satisfaction_ratings.json${paramStr}`,
|
35 | headers
|
36 | };
|
37 | },
|
38 |
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | show: (options = {}) => {
|
46 | const { error } = Joi.object({
|
47 | id: _id.required()
|
48 | }).validate(options);
|
49 | if (error) throw new Error(error.details[0].message);
|
50 |
|
51 | const { id } = options;
|
52 | return {
|
53 | method: 'GET',
|
54 | url: `${url}/api/v2/satisfaction_ratings/${id}.json`,
|
55 | headers
|
56 | };
|
57 | },
|
58 |
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | create: (options = {}) => {
|
66 | const { error } = Joi.object({
|
67 | ticket_id: _ticket_id.required(),
|
68 | data: _data.required()
|
69 | }).validate(options);
|
70 | if (error) throw new Error(error.details[0].message);
|
71 |
|
72 | const { ticket_id, data } = options;
|
73 | return {
|
74 | method: 'POST',
|
75 | url: `${url}/api/v2/tickets/${ticket_id}/satisfaction_rating.json`,
|
76 | headers,
|
77 | data
|
78 | };
|
79 | }
|
80 | };
|
81 | };
|