-
Notifications
You must be signed in to change notification settings - Fork 3
/
briefcase.ts
512 lines (487 loc) · 15.2 KB
/
briefcase.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
import { CWError } from './error'
const _ = require('lodash')
const querystring = require('querystring')
const fs = require('fs')
import * as https from 'https'
import { CaseData } from './case_data'
import { CaseFinancial } from './case_financial'
import { CaseWorkflow} from './case_workflow'
import { CaseAdmin } from './case_admin'
import { Comments } from './comments'
import { CaseAssets } from './case_assets'
export interface Briefcase {
TempTableName: string
AnonymousFlag: string
RegisteredFlag: string
CreatedByLoginId: string
TableName: string
ModifiedByLoginId: number
AcceptedByLoginId: number
EnteredByLoginid: number
WorkOrderId: string
WorkOrderDesc: string
WorkOrderStatus: string
ServiceRequestId: number
ServiceRequestDesc: string
ServiceRequestStatus: string
CloneCaseRelation: any|null
PendingFlag: any|null
CaseGroup: any|null
ParentCaObjectId: number|null
AmountDue: number|null
GetViewColumns: Array<string>
CaObjectId: number
OrgId: number
CaseTypeId: number
CaseType: string
CaseTypeDesc: string
BusCaseDesc: string|null
SubTypeId: number|null
SubType: string|null
SubTypeDesc: string|null
CreatedBy: number
DateAccepted: Date|null
DateCreated: Date
DateEntered: Date
DateExpiration: Date|null
DateIssued: Date|null
DateModified: Date|null
EnteredBy: number
ExpiredFlag: string|null
IssuedBy: number|null
IssuedFlag: string|null
ModifiedBy: number|null
SubTypeDefaultText: string|null
CaseNumber: string
CaseStatusId: number
CaseStatus: string
ProjectSid: number|null
ProjectId: string|null
ProjectCode: string|null
ProjectDesc: string|null
PriorityLevel: string|null
StatusCode: string
CaseName: string
AcceptedBy: number
BLicenseFlag: string|null
BusinessName: string|null
BusCaseId: number|null
BusinessOrgType: string|null
BusinessCategory: string|null
StateTaxId: string|null
FedTaxId: string|null
Location: string|null
PACaseFlag: string|null
ActiveFlag: string|null
CX: number|null
CY: number|null
CZ: number|null
AssignedTo: number|null
AssignedToLoginId: string|null
AssignedToFirstName: string|null
AssignedToLastName: string|null
Facility_Id: string|number|null
Level_Id: string|number|null
}
export class Briefcase {
/**
* @hidden
*/
cw: any
/**
* @hidden
*/
current_case: number = 0
/**
* Data Detail methods
*/
data?: any
/**
* Asset (Address) methods
*/
asset?: any
/**
* Asset (Address) methods
*/
attachments?: any
/**
* Workflow & task methods
*/
workflow?: any
/**
* Payment, Receipt, & Fee methods
*/
financial?: any
/**
* Commenting methods
*/
comment?: any
/**
* PLL Administration methods
*/
admin?: any
/**
* @hidden
*/
constructor(cw) {
this.cw = cw
}
/**
* Create new case
*
* @category Cases
* @param {number} caseTypeId - The case Type ID
* @param {number} subTypeId - The case subType ID
* @param {Object} [options] - See /{subdirectory}/apidocs/#/data-type-info;dataType=CaObjectItemBase
* @return {Object} Returns Promise that represents an object describing the newly-created case
*/
create(caseTypeId: number, subTypeId: number, options?: Object): Promise<Briefcase> {
return new Promise((resolve, reject) => {
var data_init = {
CaseTypeId: caseTypeId,
SubTypeId: subTypeId
}
var data = _.merge(data_init, options)
this.cw.runRequest('Pll/Case/Create', data).then(r => {
this.current_case = r.Value.CaObjectId
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Create a child case
*
* @category Cases
* @param {number} busCaseId - The case Type ID
* @param {number} parentCaObjectId - The case subType ID
* @param {Object} [options] - See /{subdirectory}/apidocs/#/data-type-info;dataType=CaObjectItemBase
* @return {Object} Returns Promise that represents an object describing the newly-created case
*/
createChild(busCaseId: number, parentCaObjectId: number, options?: Object): Promise<Briefcase> {
return new Promise((resolve, reject) => {
var data_init = {
BusCaseId: busCaseId,
ParentCaObjectId: parentCaObjectId
}
var data = _.merge(data_init, options)
this.cw.runRequest('Pll/Case/CreateChild', data).then(r => {
this.current_case = r.Value.CaObjectId
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Create a case from a Service Request
*
* @category Cases
* @param {number} caseTypeId - The case Type ID
* @param {number} subTypeId - The case subType ID
* @param {number} requestId - The service request ID
* @param {Object} [options] - See /{subdirectory}/apidocs/#/data-type-info;dataType=CaObjectItemBase
* @return {Object} Returns Promise that represents an object describing the newly-created case
*/
createFromRequest(caseTypeId: number, subTypeId: number, requestId: number, options?: Object) {
return new Promise((resolve, reject) => {
var data_init = {
CaseTypeId: caseTypeId,
SubTypeId: subTypeId,
ServiceRequestId: requestId
}
var data = _.merge(data_init, options)
this.cw.runRequest('Pll/CaseObject/CreateCaseFromServiceRequest', data).then(r => {
this.current_case = r.Value.CaObjectId
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Update a case
*
* @category Cases
* @param {number} caObjectId - The case Object ID to update
* @param {Object} [options] - See /{subdirectory}/apidocs/#/data-type-info;dataType=CaObjectItemBase
* @return {Object} Returns Promise that represents an object describing the updated case
*/
update(caObjectId: number, options?: Object): Promise<Briefcase> {
return new Promise((resolve, reject) => {
var data_init = {
CaObjectId: caObjectId
}
var data = _.merge(data_init, options)
this.cw.runRequest('Pll/CaseObject/Update', data).then(r => {
this.current_case = r.Value.CaObjectId
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Get cases by IDs
*
* @category Cases
* @param {Array<number>} caObjectIds - The case Object ID to get
* @return {Object} Returns Promise that represents a collection of objects describing the cases
*/
getByIds(caObjectIds: Array<number>): Promise<Array<Briefcase>> {
return new Promise((resolve, reject) => {
var data = {
CaObjectIds: caObjectIds
}
this.cw.runRequest('Pll/CaseObject/ByIds', data).then(r => {
if(r.Value.length == 1) {
this.current_case = r.Value[0]
}
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Search for Cases. Include at least one of the search fields. A logical 'and' operation is applied for multiple search fields.
*
* @category Cases
* @param {Object} filters - The parameter(s) to search by
* @return {Object} Returns Promise that represents an Array of case Object IDs
*/
search(filters: Object): Promise<Array<number>> {
return new Promise((resolve, reject) => {
var data = filters
this.cw.runRequest('Pll/CaseObject/Search', data).then(r => {
if(r.Value.length == 1) {
this.current_case = r.Value[0].CaObjectId
}
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Move a Case point
*
* @category Cases
* @param {string} caObjectId
* @param {number} x
* @param {number} y
* @param {Object} projection - Should include at least WKT _or_ WKID attribute. Can also include VcsWKID attribute.
* @param {number} [z] - Optional Z coordinate
* @return {Object} Returns Promise that represents an object describing the updated GISPoint
*/
move(caObjectId: number, x: number, y: number, projection: {WKID?: string, WKT?: string, VcsWKID?: string}, z?: number) {
return new Promise((resolve, reject) => {
if(!_.has(projection, 'WKID') && !_.has(projection, 'WKT')) {
// Throw error
reject(new CWError(1, 'You must provide either the WKID or WKT for the x/y coordinates.', {'projection': projection}))
}
var data_init = {
CaObjectId: caObjectId,
X: x,
Y: y
};
if(typeof(z)!='undefined') {
_.set(data_init, 'Z', z)
}
var data = _.merge(data_init, projection);
this.cw.runRequest('Pll/CaseObject/Move', data).then(r => {
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Delete case
*
* @category Cases
* @param {number} caObjectId - The case Object ID
* @return {Object} Returns Promise that represents an object describing the deleted case
*/
delete(caObjectId: number) {
return new Promise((resolve, reject) => {
var data = {
CaObjectId: caObjectId
}
this.cw.runRequest('Pll/CaseObject/DeleteCase', data).then(r => {
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Get Map Layer Fields
*
* @category Cases
* @param {number} caObjectId - The case object ID to get the map layer fields for.
* @return {Object} Returns Promise that represents a collection of Objects describing the case object map layer fields
*/
getMLFs(caObjectId: number) {
return new Promise((resolve, reject) => {
var data = {
CaObjectId: caObjectId
}
var path = 'Ams/TemplateMapLayer/CaseInstanceMapLayersByCaObjectId';
this.cw.runRequest(path, data).then(r => {
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Update Map Layer Fields
*
* @category Cases
* @param {number} caObjectId - The case object ID to get the map layer fields for.
* @param {number} x
* @param {number} y
* @param {number} domainId - The domain ID for the case in question
* @param {number} [z] - Optional Z coordinate
* @return {Object} Returns Promise that represents a collection of Objects describing the case object map layer fields
*/
updateMLFs(caObjectId: number, x?: number, y?: number, domainId?: number, z?: number) {
return new Promise((resolve, reject) => {
var data = {
CaObjectId: caObjectId
}
var path = 'Ams/TemplateMapLayer/UpdateCaseInstanceMapLayers';
if(_.isNumber(x)) {
_.set(data, 'X', x)
}
if(_.isNumber(y)) {
_.set(data, 'Y', y)
}
if(_.isNumber(z)) {
_.set(data, 'Z', z)
}
if(_.isNumber(domainId)) {
_.set(data, 'DomainId', domainId)
}
this.cw.runRequest(path, data).then(r => {
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Delete Map Layer Fields
*
* @category Cases
* @param {number} caObjectId - The case object ID to delete the map layer fields for.
* @return {Object} Returns Promise that represents a collection of Objects describing the case object map layer fields deleted
*/
deleteMLFs(caObjectId: number) {
return new Promise((resolve, reject) => {
var data = {
CaObjectId: caObjectId
}
var path = 'Ams/TemplateMapLayer/DeleteCaseInstanceMapLayersByCaObjectId';
this.cw.runRequest(path, data).then(r => {
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Reports available for Case
*
* @category Cases
* @param {number} caObjectId - The case object ID to get the report (print template) list for
* @return {Object} Returns Promise that represents a collection of Objects describing the reports (print templates) available for this case
*/
getPrintTemplates(caObjectId: number) {
return new Promise((resolve, reject) => {
var data = {
CaObjectId: caObjectId
}
var path = 'Pll/BusinessCaseReports/ByCaObjectId';
this.cw.runRequest(path, data).then(r => {
resolve(r.Value)
}).catch(e => {
reject(e)
})
})
}
/**
* Print Case
*
* @category Cases
* @param {number} caObjectId - The case object ID to delete the map layer fields for.
* @param {string} fileName - the filename of the report from the getPrintTemplates method, but w/out the extension
* @return {Object} Returns Promise that represents a collection of Objects describing the case object map layer fields deleted
*/
print(caObjectId: number, fileName: string, callback: any) {
return new Promise((resolve, reject) => {
var data = {
CaObjectId: caObjectId,
FileName: fileName
}
var path = 'Pll/BusinessCaseReports/Download'
var options = this.cw.getRequestOptions(path, 'GET')
console.log(options)
var file_extension = `pdf`
console.log(__dirname + fileName + '.' + file_extension)
const file = fs.createWriteStream(__dirname.replace('/dist', '/downloads') + '/' + fileName + '.' + file_extension)
var request_url = 'https://'+options.hostname + options.path + '?data=' + JSON.stringify(data) + '&Token=' + this.cw.getToken()
// TODO: test the Filename to make sure it's in the File list from getPrintTemplates (or let the API just error?)
https.get(request_url, {timeout: 10000000}, (res) => {
res.on('data', (d) => {
file.write(d);
});
res.on('end', () => {
file.close(callback('Success'))
})
}).on('error', (e) => {
file.close(callback('Failure'));
console.error(e);
});
})
}
// importCase(caseTypeId: number, subTypeId: number, caseName: string, location: string, x: number, y:number, appData: object, comment: string, expiration: string, assetIds: object) {
// return new Promise(resolve => {
// const _this = this;
// let case_data = {CaseName:caseName, Location:location, DateExpiration: expiration, X:x,Y:y}
// this.create(caseTypeId, subTypeId, case_data).then((response: any) => {
// if(response) {
// if(typeof(response.CaObjectId)!='undefined') {
// var CaObjectId = response.CaObjectId
// if(typeof(comment) != 'undefined') {
// _this.comments.add(CaObjectId, comment)
// }
// if(assetIds) {
// _this.assets!.attach(CaObjectId, true, assetIds)
// }
// if(appData) {
// _this.data!.getGroupsByCaseId(response.CaObjectId).then(response_one => {
// // loop through all groups
// let data_details_items = []
// _this.data!.caseDataGroupIterator(appData, response_one, data_details_items).then(di => {
// _this.data!.caseDataDetailIterator(appData, di).then(resp => {
// resolve(response)
// })
// })
// })
// } else {
// resolve(response)
// }
// } else {
// console.log('Error creating case: '+ JSON.stringify(case_data))
// process.exit(0)
// }
// } else {
// resolve(false)
// }
// })
// })
// }
}