@crmcom/self-service-sdk 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/account.js +144 -0
- package/authentication.js +475 -0
- package/communications.js +94 -0
- package/community.js +327 -0
- package/config.js +302 -0
- package/connectx.js +92 -0
- package/contacts.js +1109 -0
- package/dataUtil.js +2186 -0
- package/eventListener.js +41 -0
- package/httpBackOfficeUtil.js +396 -0
- package/httpJCCUtil.js +61 -0
- package/httpUtil.js +863 -0
- package/index.d.ts +527 -0
- package/index.js +24 -0
- package/jcccards.js +112 -0
- package/logger.js +40 -0
- package/mobilepass.js +64 -0
- package/orders.js +732 -0
- package/organisations.js +141 -0
- package/package.json +63 -0
- package/payment.js +338 -0
- package/paymentgateway.js +26 -0
- package/payouts.js +33 -0
- package/resultUtil.js +86 -0
- package/rewards.js +409 -0
- package/servicerequest.js +235 -0
- package/subscriptions.js +406 -0
- package/wallet.js +478 -0
package/rewards.js
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import { httpUtil } from "./httpUtil";
|
|
2
|
+
import { ErrorCodes, createResult, createCommonResult } from "./resultUtil";
|
|
3
|
+
import { logger } from './logger';
|
|
4
|
+
export const rewards = {
|
|
5
|
+
getRewards,
|
|
6
|
+
getOffers,
|
|
7
|
+
getPerformanceOffer,
|
|
8
|
+
getListPromotions,
|
|
9
|
+
getPromotion,
|
|
10
|
+
searchRewardSchemes,
|
|
11
|
+
verifyClosedLoopScheme,
|
|
12
|
+
sendRefferals,
|
|
13
|
+
redeemPass,
|
|
14
|
+
reclaimPurchase,
|
|
15
|
+
signUpRewardScheme,
|
|
16
|
+
signOutRewardScheme,
|
|
17
|
+
getOfferDetail,
|
|
18
|
+
getDonationDetail,
|
|
19
|
+
getPassPlans
|
|
20
|
+
}
|
|
21
|
+
async function getRewards() {
|
|
22
|
+
try {
|
|
23
|
+
let id = httpUtil.getSession().sub;
|
|
24
|
+
|
|
25
|
+
let response = await httpUtil.get({
|
|
26
|
+
resourcePath: '/v2/contacts/' + id + '/rewards',
|
|
27
|
+
});
|
|
28
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
29
|
+
return createCommonResult(response);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
logger.error('Exception getRewards:', e);
|
|
32
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function getOffers({
|
|
37
|
+
countries,
|
|
38
|
+
include_total = true,
|
|
39
|
+
industry,
|
|
40
|
+
industry_sector,
|
|
41
|
+
organisations,
|
|
42
|
+
owner,
|
|
43
|
+
performance_enabled,
|
|
44
|
+
tags,
|
|
45
|
+
towns_cities,
|
|
46
|
+
reward_offer_tags,
|
|
47
|
+
page,
|
|
48
|
+
size,
|
|
49
|
+
sort,
|
|
50
|
+
order,
|
|
51
|
+
lat,
|
|
52
|
+
lon,
|
|
53
|
+
is_featured,
|
|
54
|
+
search_value,
|
|
55
|
+
types
|
|
56
|
+
} = {},) {
|
|
57
|
+
try {
|
|
58
|
+
|
|
59
|
+
//console.log('API: ', contact)
|
|
60
|
+
let response = await httpUtil.get({
|
|
61
|
+
resourcePath: '/v2/reward_offers',
|
|
62
|
+
queryParams: {
|
|
63
|
+
countries,
|
|
64
|
+
include_total,
|
|
65
|
+
industries: industry,
|
|
66
|
+
industry_sectors: industry_sector,
|
|
67
|
+
organisations,
|
|
68
|
+
owner,
|
|
69
|
+
performance_enabled,
|
|
70
|
+
tags,
|
|
71
|
+
towns_cities,
|
|
72
|
+
reward_offer_tags,
|
|
73
|
+
page,
|
|
74
|
+
size,
|
|
75
|
+
sort,
|
|
76
|
+
order,
|
|
77
|
+
lat,
|
|
78
|
+
lon,
|
|
79
|
+
is_featured,
|
|
80
|
+
search_value,
|
|
81
|
+
types
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
85
|
+
return createCommonResult(response);
|
|
86
|
+
} catch (e) {
|
|
87
|
+
logger.error('Exception getOffers:', e);
|
|
88
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
async function getPerformanceOffer(offerId) {
|
|
94
|
+
try {
|
|
95
|
+
|
|
96
|
+
//console.log('API: ', contact)
|
|
97
|
+
let response = await httpUtil.get({
|
|
98
|
+
resourcePath: '/v2/reward_offers/' + offerId + "/performance",
|
|
99
|
+
queryParams: {}
|
|
100
|
+
});
|
|
101
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
102
|
+
return createCommonResult(response);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
logger.error('Exception getOffers:', e);
|
|
105
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function getListPromotions({
|
|
110
|
+
organisations,
|
|
111
|
+
promotion_tags,
|
|
112
|
+
search_value,
|
|
113
|
+
page,
|
|
114
|
+
size = 100,
|
|
115
|
+
sort,
|
|
116
|
+
order,
|
|
117
|
+
} = {},) {
|
|
118
|
+
try {
|
|
119
|
+
|
|
120
|
+
//console.log('API: ', contact)
|
|
121
|
+
let response = await httpUtil.get({
|
|
122
|
+
resourcePath: '/v2/promotions',
|
|
123
|
+
queryParams: {
|
|
124
|
+
organisations,
|
|
125
|
+
promotion_tags,
|
|
126
|
+
search_value,
|
|
127
|
+
page,
|
|
128
|
+
size,
|
|
129
|
+
sort,
|
|
130
|
+
order,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
134
|
+
return createCommonResult(response);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
logger.error('Exception getListPromotions:', e);
|
|
137
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function getPromotion(id) {
|
|
142
|
+
try {
|
|
143
|
+
let response = await httpUtil.get({
|
|
144
|
+
resourcePath: '/v2/promotions/' + id
|
|
145
|
+
});
|
|
146
|
+
return createCommonResult(response);
|
|
147
|
+
} catch (e) {
|
|
148
|
+
logger.error('Exception getPromotion:', e);
|
|
149
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function searchRewardSchemes({
|
|
154
|
+
include_total,
|
|
155
|
+
is_signed,
|
|
156
|
+
name,
|
|
157
|
+
page,
|
|
158
|
+
size = 20,
|
|
159
|
+
sort,
|
|
160
|
+
order
|
|
161
|
+
} = {}) {
|
|
162
|
+
try {
|
|
163
|
+
let response = await httpUtil.get({
|
|
164
|
+
resourcePath: '/v2/reward_schemes',
|
|
165
|
+
queryParams: {
|
|
166
|
+
include_total,
|
|
167
|
+
is_signed,
|
|
168
|
+
name,
|
|
169
|
+
page,
|
|
170
|
+
size,
|
|
171
|
+
sort,
|
|
172
|
+
order
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
176
|
+
return createCommonResult(response);
|
|
177
|
+
} catch (e) {
|
|
178
|
+
logger.error('Exception searchRewardSchemes:', e);
|
|
179
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async function verifyClosedLoopScheme({
|
|
184
|
+
sign_up_code
|
|
185
|
+
} = {}) {
|
|
186
|
+
try {
|
|
187
|
+
let response = await httpUtil.get({
|
|
188
|
+
resourcePath: '/v2/contacts/reward_schemes/verification/' + sign_up_code
|
|
189
|
+
});
|
|
190
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
191
|
+
return createCommonResult(response);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
logger.error('Exception verifyClosedLoopScheme:', e);
|
|
194
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function sendRefferals({
|
|
199
|
+
recipients,
|
|
200
|
+
action = 'SEND',
|
|
201
|
+
} = {}) {
|
|
202
|
+
try {
|
|
203
|
+
let response = await httpUtil.post({
|
|
204
|
+
resourcePath: '/v2/referrals/actions',
|
|
205
|
+
// resourcePath: '/v1/send_referrals',
|
|
206
|
+
body: {
|
|
207
|
+
action,
|
|
208
|
+
recipients,
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
212
|
+
return createCommonResult(response);
|
|
213
|
+
} catch (e) {
|
|
214
|
+
logger.error('Exception sendRefferals:', e);
|
|
215
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async function redeemPass({
|
|
220
|
+
code,
|
|
221
|
+
pin,
|
|
222
|
+
wallet_id,
|
|
223
|
+
} = {}) {
|
|
224
|
+
try {
|
|
225
|
+
let id = await httpUtil.getSession().sub;
|
|
226
|
+
let response = await httpUtil.post({
|
|
227
|
+
// resourcePath: '/v2/passes/redeem',
|
|
228
|
+
resourcePath: '/v2/passes/redeem',
|
|
229
|
+
body: {
|
|
230
|
+
code,
|
|
231
|
+
pin,
|
|
232
|
+
contact_id: id,
|
|
233
|
+
wallet_id: wallet_id,
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
237
|
+
if (response.code == "OK")
|
|
238
|
+
return createResult(ErrorCodes.OK, response.data);
|
|
239
|
+
else {
|
|
240
|
+
if(response.error && response.error.error == "CRM.EXCEPTIONS.NOTFOUNDEXCEPTION"){
|
|
241
|
+
return createResult(
|
|
242
|
+
ErrorCodes.REDEEM_PASS_INVALID,
|
|
243
|
+
response.error
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
else if(response.error && response.error.error == "COM.CRM.EXCEPTIONS.THISPASSHASALREADYBEENREDEEMEDEXCEPTION"){
|
|
247
|
+
return createResult(
|
|
248
|
+
ErrorCodes.REDEEM_PASS_USED,
|
|
249
|
+
response.error
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
else if(response.error && response.error.error == "COM.CRM.EXCEPTIONS.ONLYACTIVEPASSESCANBEREDEEMEDEXCEPTION"){
|
|
253
|
+
return createResult(
|
|
254
|
+
ErrorCodes.REDEEM_PASS_NOT_ACTIVE,
|
|
255
|
+
response.error
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
else
|
|
259
|
+
return createResult(ErrorCodes.UNCLASSIFIED_ERROR, response.error);
|
|
260
|
+
}
|
|
261
|
+
} catch (e) {
|
|
262
|
+
logger.error('Exception redeemPass:', e);
|
|
263
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async function reclaimPurchase({
|
|
268
|
+
purchase_id,
|
|
269
|
+
merchant_tap,
|
|
270
|
+
venue_tap,
|
|
271
|
+
net_amount,
|
|
272
|
+
tax_amount,
|
|
273
|
+
discount_amount,
|
|
274
|
+
total_amount,
|
|
275
|
+
transaction_code,
|
|
276
|
+
} = {}) {
|
|
277
|
+
try {
|
|
278
|
+
let id = await httpUtil.getSession().sub;
|
|
279
|
+
let response = await httpUtil.post({
|
|
280
|
+
// resourcePath: '/v2/passes/redeem',
|
|
281
|
+
resourcePath: '/v2/purchases/reclaim',
|
|
282
|
+
body: {
|
|
283
|
+
id: purchase_id,
|
|
284
|
+
organisation: {
|
|
285
|
+
merchant_tap: {
|
|
286
|
+
code: merchant_tap,
|
|
287
|
+
},
|
|
288
|
+
venue_tap: {
|
|
289
|
+
code: venue_tap
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
transaction_amounts: {
|
|
293
|
+
net: net_amount,
|
|
294
|
+
tax: tax_amount,
|
|
295
|
+
discount: discount_amount,
|
|
296
|
+
total: total_amount,
|
|
297
|
+
},
|
|
298
|
+
transaction_code: transaction_code
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
302
|
+
return createCommonResult(response);
|
|
303
|
+
} catch (e) {
|
|
304
|
+
logger.error('Exception reclaimPurchase:', e);
|
|
305
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
async function signOutRewardScheme({
|
|
310
|
+
reward_scheme_id
|
|
311
|
+
}) {
|
|
312
|
+
try {
|
|
313
|
+
let id = await httpUtil.getSession().sub;
|
|
314
|
+
let response = await httpUtil.post({
|
|
315
|
+
resourcePath: '/v2/contacts/' + id + '/reward_schemes',
|
|
316
|
+
body: {
|
|
317
|
+
reward_scheme_id,
|
|
318
|
+
action: 'SIGN_OUT'
|
|
319
|
+
},
|
|
320
|
+
withAccessToken: true
|
|
321
|
+
});
|
|
322
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
323
|
+
return createCommonResult(response);
|
|
324
|
+
} catch (e) {
|
|
325
|
+
logger.error('Exception signOutRewardScheme:', e);
|
|
326
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
async function signUpRewardScheme({
|
|
331
|
+
reward_scheme_id,
|
|
332
|
+
email_address,
|
|
333
|
+
sign_up_code
|
|
334
|
+
}) {
|
|
335
|
+
try {
|
|
336
|
+
let id = await httpUtil.getSession().sub;
|
|
337
|
+
let body = {
|
|
338
|
+
reward_scheme_id,
|
|
339
|
+
}
|
|
340
|
+
if (sign_up_code) {
|
|
341
|
+
body.sign_up_code = sign_up_code
|
|
342
|
+
}
|
|
343
|
+
if (email_address) {
|
|
344
|
+
body.email_address = email_address
|
|
345
|
+
}
|
|
346
|
+
let response = await httpUtil.post({
|
|
347
|
+
resourcePath: '/v2/contacts/' + id + '/reward_schemes',
|
|
348
|
+
body: { ...body, action: 'SIGN_UP' },
|
|
349
|
+
withAccessToken: true
|
|
350
|
+
});
|
|
351
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
352
|
+
return createCommonResult(response);
|
|
353
|
+
} catch (e) {
|
|
354
|
+
logger.error('Exception signUpRewardScheme:', e);
|
|
355
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
async function getOfferDetail(offerId) {
|
|
360
|
+
try {
|
|
361
|
+
|
|
362
|
+
//console.log('API: ', contact)
|
|
363
|
+
let response = await httpUtil.get({
|
|
364
|
+
resourcePath: '/v2/reward_offers/' + offerId,
|
|
365
|
+
queryParams: {}
|
|
366
|
+
});
|
|
367
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
368
|
+
return createCommonResult(response);
|
|
369
|
+
} catch (e) {
|
|
370
|
+
logger.error('Exception getOfferDetail:', e);
|
|
371
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
async function getDonationDetail(donationId) {
|
|
376
|
+
try {
|
|
377
|
+
|
|
378
|
+
//console.log('API: ', contact)
|
|
379
|
+
let response = await httpUtil.get({
|
|
380
|
+
resourcePath: '/v2/donation_offers/' + donationId,
|
|
381
|
+
queryParams: {}
|
|
382
|
+
});
|
|
383
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
384
|
+
return createCommonResult(response);
|
|
385
|
+
} catch (e) {
|
|
386
|
+
logger.error('Exception getDonationDetail:', e);
|
|
387
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
async function getPassPlans({
|
|
391
|
+
page = 1,
|
|
392
|
+
size = 20,
|
|
393
|
+
} = {}) {
|
|
394
|
+
try {
|
|
395
|
+
let queryParams = {
|
|
396
|
+
page,
|
|
397
|
+
size,
|
|
398
|
+
};
|
|
399
|
+
let response = await httpUtil.get({
|
|
400
|
+
resourcePath: '/v2/pass_plans',
|
|
401
|
+
queryParams: queryParams,
|
|
402
|
+
withAccessToken: true
|
|
403
|
+
});
|
|
404
|
+
return createCommonResult(response);
|
|
405
|
+
} catch (e) {
|
|
406
|
+
logger.error('Exception getLocations:', e);
|
|
407
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { httpUtil } from './httpUtil'
|
|
2
|
+
import { ErrorCodes, createResult, createCommonResult } from './resultUtil'
|
|
3
|
+
import { logger } from './logger';
|
|
4
|
+
|
|
5
|
+
export const servicerequest = {
|
|
6
|
+
getListServiceRequests,
|
|
7
|
+
createServiceRequest,
|
|
8
|
+
addServiceRequestAttachment,
|
|
9
|
+
deleteServiceRequestAttachment,
|
|
10
|
+
getListServiceRequestAttachment,
|
|
11
|
+
uploadFiles,
|
|
12
|
+
getListServiceRequestQueues,
|
|
13
|
+
getListServiceRequestNotes,
|
|
14
|
+
createServiceRequestNote,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function getListServiceRequests({
|
|
18
|
+
include_total,
|
|
19
|
+
page = 1,
|
|
20
|
+
size = 10,
|
|
21
|
+
sort,
|
|
22
|
+
order,
|
|
23
|
+
search_value,
|
|
24
|
+
states,
|
|
25
|
+
queue_id
|
|
26
|
+
} = {}) {
|
|
27
|
+
try {
|
|
28
|
+
let id = httpUtil.getSession().sub;
|
|
29
|
+
let response = await httpUtil.get({
|
|
30
|
+
resourcePath: '/v2/contacts/' + id + '/service_requests',
|
|
31
|
+
queryParams: {
|
|
32
|
+
include_total,
|
|
33
|
+
page,
|
|
34
|
+
size,
|
|
35
|
+
sort,
|
|
36
|
+
order,
|
|
37
|
+
search_value,
|
|
38
|
+
states,
|
|
39
|
+
queue_id
|
|
40
|
+
},
|
|
41
|
+
withAccessToken: true
|
|
42
|
+
});
|
|
43
|
+
return createCommonResult(response);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
logger.error('Exception getListServiceRequests:', e);
|
|
46
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function createServiceRequest({
|
|
51
|
+
description,
|
|
52
|
+
queue_id,
|
|
53
|
+
categories,
|
|
54
|
+
address_id,
|
|
55
|
+
other_address
|
|
56
|
+
}) {
|
|
57
|
+
try {
|
|
58
|
+
let address = null;
|
|
59
|
+
if (address_id) {
|
|
60
|
+
address.id = address_id;
|
|
61
|
+
} else if(other_address){
|
|
62
|
+
address.other = other_address;
|
|
63
|
+
}
|
|
64
|
+
let id = httpUtil.getSession().sub;
|
|
65
|
+
let response = await httpUtil.post({
|
|
66
|
+
resourcePath: '/v2/contacts/' + id + '/service_requests',
|
|
67
|
+
body: {
|
|
68
|
+
description,
|
|
69
|
+
queue_id,
|
|
70
|
+
categories,
|
|
71
|
+
address: address
|
|
72
|
+
},
|
|
73
|
+
withAccessToken: true
|
|
74
|
+
});
|
|
75
|
+
return createCommonResult(response);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
logger.error('Exception createServiceRequest:', e);
|
|
78
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function addServiceRequestAttachment({
|
|
83
|
+
file_id,
|
|
84
|
+
description,
|
|
85
|
+
service_request_id
|
|
86
|
+
}) {
|
|
87
|
+
try {
|
|
88
|
+
let response = await httpUtil.post({
|
|
89
|
+
resourcePath: '/v2/service_requests/' + service_request_id + '/attachments',
|
|
90
|
+
body: {
|
|
91
|
+
file_id,
|
|
92
|
+
description,
|
|
93
|
+
},
|
|
94
|
+
withAccessToken: true
|
|
95
|
+
});
|
|
96
|
+
return createCommonResult(response);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
logger.error('Exception addServiceRequestAttachment:', e);
|
|
99
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function deleteServiceRequestAttachment({
|
|
104
|
+
file_id,
|
|
105
|
+
service_request_id
|
|
106
|
+
}) {
|
|
107
|
+
try {
|
|
108
|
+
let response = await httpUtil.sendDelete({
|
|
109
|
+
resourcePath: '/v2/service_requests/' + service_request_id + '/attachments/' + file_id,
|
|
110
|
+
withAccessToken: true
|
|
111
|
+
});
|
|
112
|
+
return createCommonResult(response);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
logger.error('Exception deleteServiceRequestAttachment:', e);
|
|
115
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function getListServiceRequestAttachment({
|
|
120
|
+
include_total,
|
|
121
|
+
page = 1,
|
|
122
|
+
size = 10,
|
|
123
|
+
sort,
|
|
124
|
+
order,
|
|
125
|
+
} = {}, id) {
|
|
126
|
+
try {
|
|
127
|
+
let response = await httpUtil.get({
|
|
128
|
+
resourcePath: '/v2/service_requests/' + id + '/attachments',
|
|
129
|
+
queryParams: {
|
|
130
|
+
include_total,
|
|
131
|
+
page,
|
|
132
|
+
size,
|
|
133
|
+
sort,
|
|
134
|
+
order,
|
|
135
|
+
},
|
|
136
|
+
withAccessToken: true
|
|
137
|
+
});
|
|
138
|
+
return createCommonResult(response);
|
|
139
|
+
} catch (e) {
|
|
140
|
+
logger.error('Exception getListServiceRequestAttachment:', e);
|
|
141
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async function uploadFiles({
|
|
146
|
+
file,
|
|
147
|
+
disalbedContentType = false,
|
|
148
|
+
} = {}) {
|
|
149
|
+
try {
|
|
150
|
+
let response = await httpUtil.uploadFile({
|
|
151
|
+
resourcePath: "/v2/upload/files",
|
|
152
|
+
fileData: file,
|
|
153
|
+
body: {},
|
|
154
|
+
withAccessToken: true,
|
|
155
|
+
disalbedContentType: disalbedContentType,
|
|
156
|
+
});
|
|
157
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
158
|
+
if (response.code == "OK")
|
|
159
|
+
return createResult(ErrorCodes.OK, response.data);
|
|
160
|
+
else {
|
|
161
|
+
createResult(ErrorCodes.UNKNOWN, response.error);
|
|
162
|
+
}
|
|
163
|
+
} catch (e) {
|
|
164
|
+
logger.error("Exception uploadFiles:", e);
|
|
165
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function getListServiceRequestQueues({
|
|
170
|
+
state = null,
|
|
171
|
+
name,
|
|
172
|
+
search_value,
|
|
173
|
+
} = {},) {
|
|
174
|
+
try {
|
|
175
|
+
let id = httpUtil.getSession().sub;
|
|
176
|
+
let response = await httpUtil.get({
|
|
177
|
+
resourcePath: '/v2/queues',
|
|
178
|
+
queryParams: {
|
|
179
|
+
state,
|
|
180
|
+
name,
|
|
181
|
+
search_value,
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
//check return code here instead of put as there would be different intepretation for different API
|
|
185
|
+
return createCommonResult(response);
|
|
186
|
+
} catch (e) {
|
|
187
|
+
logger.error('Exception getListServiceRequestQueues:', e);
|
|
188
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function getListServiceRequestNotes({
|
|
193
|
+
include_total,
|
|
194
|
+
page = 1,
|
|
195
|
+
size = 10,
|
|
196
|
+
sort,
|
|
197
|
+
order,
|
|
198
|
+
} = {}, id) {
|
|
199
|
+
try {
|
|
200
|
+
let response = await httpUtil.get({
|
|
201
|
+
resourcePath: '/v2/service_requests/' + id + '/notes',
|
|
202
|
+
queryParams: {
|
|
203
|
+
include_total,
|
|
204
|
+
page,
|
|
205
|
+
size,
|
|
206
|
+
sort,
|
|
207
|
+
order,
|
|
208
|
+
},
|
|
209
|
+
withAccessToken: true
|
|
210
|
+
});
|
|
211
|
+
return createCommonResult(response);
|
|
212
|
+
} catch (e) {
|
|
213
|
+
logger.error('Exception getListServiceRequestNotes:', e);
|
|
214
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async function createServiceRequestNote({
|
|
219
|
+
note,
|
|
220
|
+
service_request_id
|
|
221
|
+
}) {
|
|
222
|
+
try {
|
|
223
|
+
let response = await httpUtil.post({
|
|
224
|
+
resourcePath: '/v2/service_requests/' + service_request_id + '/notes',
|
|
225
|
+
body: {
|
|
226
|
+
note,
|
|
227
|
+
},
|
|
228
|
+
withAccessToken: true
|
|
229
|
+
});
|
|
230
|
+
return createCommonResult(response);
|
|
231
|
+
} catch (e) {
|
|
232
|
+
logger.error('Exception createServiceRequestNote:', e);
|
|
233
|
+
return createResult(ErrorCodes.UNKNOWN, e);
|
|
234
|
+
}
|
|
235
|
+
}
|