cityworks 0.0.28 → 0.0.32

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.
Files changed (47) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +19 -19
  3. package/dist/activity_link.d.ts +6 -3
  4. package/dist/error.d.ts +7 -4
  5. package/dist/gis.d.ts +13 -0
  6. package/dist/index.js +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.m.js +1 -1
  9. package/dist/index.m.js.map +1 -1
  10. package/dist/index.modern.js +1 -1
  11. package/dist/index.modern.js.map +1 -1
  12. package/dist/index.umd.js +1 -1
  13. package/dist/index.umd.js.map +1 -1
  14. package/dist/inspection.d.ts +1 -1
  15. package/dist/inspection_admin.d.ts +15 -0
  16. package/dist/request_admin.d.ts +8 -0
  17. package/dist/search.d.ts +7 -7
  18. package/dist/workorder_admin.d.ts +101 -0
  19. package/package.json +3 -2
  20. package/src/activity_link.ts +17 -3
  21. package/src/case.ts +2 -2
  22. package/src/case_admin.ts +4 -4
  23. package/src/case_data.ts +4 -4
  24. package/src/case_financial.ts +8 -8
  25. package/src/case_workflow.ts +2 -2
  26. package/src/cityworks.ts +29 -17
  27. package/src/comments.ts +9 -1
  28. package/src/error.ts +11 -3
  29. package/src/event_layer.ts +219 -28
  30. package/src/general.ts +3 -1
  31. package/src/gis.ts +88 -53
  32. package/src/inspection.ts +1 -1
  33. package/src/inspection_admin.ts +28 -0
  34. package/src/message_queue.ts +10 -0
  35. package/src/request.ts +1 -1
  36. package/src/request_admin.ts +18 -0
  37. package/src/search.ts +16 -14
  38. package/src/workorder.ts +2 -2
  39. package/src/workorder_admin.ts +231 -0
  40. package/test/01.cityworksTest.js +12 -12
  41. package/test/03.generalTest.js +87 -0
  42. package/test/04.requestTest.js +8 -0
  43. package/test/05.caseTest.js +86 -5
  44. package/test/06.caseFinancialTest.js +95 -6
  45. package/test/07.searchTest.js +191 -0
  46. package/test/08.workOrderTest.js +48 -0
  47. package/test/{07.search.js → 09.inspectionTest.js} +4 -11
@@ -266,7 +266,7 @@ export declare class Inspection {
266
266
  * @param {Array<string>} [entityTypes] - The Entity Type(s) to return potential inspections for
267
267
  * @param {boolean} [canCreate] - If true, only return templates the user can create, ignored if false or null, default is true
268
268
  * @param {Object} [options] - An object which can include: [IncludeInactive]: boolean, MaximumDateModified: Date, MinimumDateModified: Date, TemplateIds: Array<number>
269
- * @return {Object} Returns Promise that represents a collection of all possible employees for an Inspection's SubmitTo
269
+ * @return {Object} Returns Promise that represents a collection of all Inspections matching the provided parameters
270
270
  */
271
271
  getTemplates(entityTypes?: Array<string>, canCreate?: boolean, options?: {
272
272
  IncludeInactive?: boolean;
@@ -7,4 +7,19 @@ export declare class InspectionAdmin {
7
7
  * @hidden
8
8
  */
9
9
  constructor(cw: any);
10
+ /**
11
+ * Get inspection templates
12
+ *
13
+ * @category Inspection Templates
14
+ * @param {Array<string>} [entityTypes] - The Entity Type(s) to return potential inspections for
15
+ * @param {boolean} [canCreate] - If true, only return templates the user can create, ignored if false or null, default is true
16
+ * @param {Object} [options] - An object which can include: [IncludeInactive]: boolean, MaximumDateModified: Date, MinimumDateModified: Date, TemplateIds: Array<number>
17
+ * @return {Object} Returns Promise that represents a collection of all Inspections matching the provided parameters
18
+ */
19
+ getTemplates(entityTypes?: Array<string>, canCreate?: boolean, options?: {
20
+ IncludeInactive?: boolean;
21
+ MaximumDateModified?: Date;
22
+ MinimumDateModified?: Date;
23
+ TemplateIds?: Array<number>;
24
+ }): Promise<unknown>;
10
25
  }
@@ -7,4 +7,12 @@ export declare class RequestAdmin {
7
7
  * @hidden
8
8
  */
9
9
  constructor(cw: any);
10
+ /**
11
+ * Get service request templates
12
+ *
13
+ * @category Requests Admin
14
+ * @param {Object} searchData - search data
15
+ * @return {Object} Returns Promise that represents a collection of all Service Request Templates
16
+ */
17
+ getTemplates(searchData: Object): Promise<unknown>;
10
18
  }
package/dist/search.d.ts CHANGED
@@ -90,22 +90,22 @@ export declare class Search {
90
90
  */
91
91
  getDefinition(searchId: number, employeeSid?: number): Promise<unknown>;
92
92
  /**
93
- * Get search definition names
93
+ * Get search definitions
94
94
  *
95
95
  * @category Search Definitions
96
96
  * @param {Array<number>} searchIds - SearchIds to get.
97
- * @return {Object} Returns Promise object that represents a collection of SearchDefinitionNames
97
+ * @param {number} employeeSid - Enforces employee security settings on search definition if provided.
98
+ * @return {Object} Returns Promise object that represents a collection of SearchDefinition objects
98
99
  */
99
- getDefinitionNames(searchIds: Array<number>): Promise<unknown>;
100
+ getDefinitions(searchIds: Array<number>, employeeSid?: number): Promise<unknown>;
100
101
  /**
101
- * Get search definitions
102
+ * Get search definition names
102
103
  *
103
104
  * @category Search Definitions
104
105
  * @param {Array<number>} searchIds - SearchIds to get.
105
- * @param {number} employeeSid - Enforces employee security settings on search definition if provided.
106
- * @return {Object} Returns Promise object that represents a collection of SearchDefinition objects
106
+ * @return {Object} Returns Promise object that represents a collection of SearchDefinitionNames
107
107
  */
108
- getDefinitions(searchIds: Array<number>, employeeSid?: number): Promise<unknown>;
108
+ getDefinitionNames(searchIds: Array<number>): Promise<unknown>;
109
109
  /**
110
110
  * Delete search definitions
111
111
  *
@@ -7,4 +7,105 @@ export declare class WorkOrderAdmin {
7
7
  * @hidden
8
8
  */
9
9
  constructor(cw: any);
10
+ /**
11
+ * Get entity groups
12
+ *
13
+ * @category WorkOrders Admin
14
+ * @return {Object} Returns Promise that represents a collection of all entity groups
15
+ */
16
+ getEntityGroups(): Promise<unknown>;
17
+ /**
18
+ * Get entity types
19
+ *
20
+ * @category WorkOrders Admin
21
+ * @return {Object} Returns Promise that represents a collection of all GIS Work Order entity types
22
+ */
23
+ getEntityTypes(entityGroups: Array<string>): Promise<unknown>;
24
+ /**
25
+ * Get work order templates
26
+ *
27
+ * @category WorkOrders Admin
28
+ * @return {Object} Returns Promise that represents a collection of all Work Order templates
29
+ */
30
+ getTemplates(entityType: string, includeComments?: boolean, includeInstructions?: boolean): Promise<unknown>;
31
+ /**
32
+ * Update Work Order template
33
+ *
34
+ * @category WorkOrders Admin
35
+ * @param {Object} wOTemplate - Obect that describes the Work Order Template
36
+ * @return {Object} Returns Promise that represents a collection of all
37
+ */
38
+ updateTemplate(wOTemplate: Object): Promise<unknown>;
39
+ /**
40
+ * Get template group rights for provided WorkOrder Templates
41
+ *
42
+ * @category WorkOrders Admin
43
+ * @param {Array<number>} wOTemplateIds - Array one or more WorkOrder Template IDs
44
+ * @return {Object} Returns Promise that represents a collection of all
45
+ */
46
+ getTemplateGroupRights(wOTemplateIds: Array<number>): Promise<unknown>;
47
+ /**
48
+ * Get template activity services for provided WorkOrder Templates
49
+ *
50
+ * @category WorkOrders Admin
51
+ * @param {Array<number>} wOTemplateIds - Array one or more WorkOrder Template IDs
52
+ * @return {Object} Returns Promise that represents a collection of all
53
+ */
54
+ getTemplateActivity(wOTemplateIds: Array<number>): Promise<unknown>;
55
+ /**
56
+ * Get fields which will be updated when provided WorkOrder Template instance closes
57
+ *
58
+ * @category WorkOrders Admin
59
+ * @param {Array<number>} wOTemplateIds - Array one or more WorkOrder Template IDs
60
+ * @return {Object} Returns Promise that represents a collection of all
61
+ */
62
+ getUpdateFields(wOTemplateIds: Array<number>): Promise<unknown>;
63
+ /**
64
+ * Get equipment
65
+ *
66
+ * @category WorkOrders Admin
67
+ * @param {Array<number>} wOTemplateIds - WorkOrder Template ID
68
+ * @return {Object} Returns Promise that represents a collection of all
69
+ */
70
+ getTemplateEquipment(wOTemplateId: number): Promise<unknown>;
71
+ /**
72
+ * Get labor
73
+ *
74
+ * @category WorkOrders Admin
75
+ * @param {Array<number>} wOTemplateIds - WorkOrder Template ID
76
+ * @return {Object} Returns Promise that represents a collection of all
77
+ */
78
+ getTemplateLabor(wOTemplateId: number): Promise<unknown>;
79
+ /**
80
+ * Get material
81
+ *
82
+ * @category WorkOrders Admin
83
+ * @param {number} wOTemplateId - WorkOrder Template ID
84
+ * @return {Object} Returns Promise that represents a collection of all
85
+ */
86
+ getTemplateMaterial(wOTemplateId: number): Promise<unknown>;
87
+ /**
88
+ * Get map layer fields configured for provided work order template
89
+ *
90
+ * @category WorkOrders Admin
91
+ * @param {number} wOTemplateId - WorkOrder Template ID
92
+ * @return {Object} Returns Promise that represents a collection of all
93
+ */
94
+ getTemplateMapLayerFields(wOTemplateId: number): Promise<unknown>;
95
+ /**
96
+ * Get tasks configured for provided work order template
97
+ *
98
+ * @category WorkOrders Admin
99
+ * @param {number} wOTemplateId - WorkOrder Template ID
100
+ * @return {Object} Returns Promise that represents a collection of all tasks on work order template
101
+ */
102
+ getTemplateTasks(wOTemplateId: number): Promise<unknown>;
103
+ /**
104
+ * Get inspections connected to provided work order template
105
+ *
106
+ * @category WorkOrders Admin
107
+ * @param {number} wOTemplateId - WorkOrder Template ID
108
+ * @return {Object} Returns Promise that represents a collection of all tasks on work order template
109
+ */
110
+ getRelatedInspectionTemplates(wOTemplateId: number): Promise<unknown>;
10
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cityworks",
3
- "version": "0.0.28",
3
+ "version": "0.0.32",
4
4
  "description": "A Cityworks API wrapper",
5
5
  "main": "dist/index.js",
6
6
  "umd:main": "dist/index.umd.js",
@@ -12,7 +12,8 @@
12
12
  "scripts": {
13
13
  "dev": "microbundle watch",
14
14
  "build": "microbundle",
15
- "test": "mocha --recursive --reporter spec ./test/",
15
+ "test": "mocha -R spec --recursive ./test/ -g ",
16
+ "fulltest": "mocha -R spec --recursive ./test/",
16
17
  "docs": "./node_modules/typedoc/bin/typedoc --tsconfig ./tsconfig.json"
17
18
  },
18
19
  "repository": {
@@ -2,14 +2,18 @@ import { CWError } from './error'
2
2
  import ReversibleMap from 'reversible-map'
3
3
  const _ = require('lodash')
4
4
 
5
- interface ActivityLink {
5
+ /**
6
+ * ActivityLink interface for ActivityLinks
7
+ *
8
+ */
9
+ export interface ActivityLink {
6
10
  linkTypes: ReversibleMap<string, number>
7
11
  activityTypes: ReversibleMap<string, number>
8
12
  cw: any
9
13
  }
10
14
 
11
15
  /**
12
- * ActivityLinks implements the activity link functions
16
+ * ActivityLinks implements the activity link functions via using the ActivityLink interface
13
17
  *
14
18
  */
15
19
  export class ActivityLinks implements ActivityLink {
@@ -89,6 +93,8 @@ export class ActivityLinks implements ActivityLink {
89
93
  let path = 'General/ActivityLink/Add'
90
94
  this.cw.runRequest(path, data).then((response: any) => {
91
95
  resolve(response.Value)
96
+ }).catch(e => {
97
+ reject(e)
92
98
  })
93
99
  })
94
100
  }
@@ -123,6 +129,8 @@ export class ActivityLinks implements ActivityLink {
123
129
  return_data.push(link)
124
130
  })
125
131
  resolve(return_data)
132
+ }).catch(e => {
133
+ reject(e)
126
134
  })
127
135
  })
128
136
  }
@@ -148,7 +156,7 @@ export class ActivityLinks implements ActivityLink {
148
156
  reject(new CWError(1, 'Source type not found.', {'provided': source_type, 'options':this.activityTypes}))
149
157
  }
150
158
  if(!this.activityTypes.has(destination_type)) {
151
- reject(new CWError(1, 'Destination type not found.', {'provided': destination_type, 'options':this.activityTypes}))
159
+ reject(new CWError(2, 'Destination type not found.', {'provided': destination_type, 'options':this.activityTypes}))
152
160
  }
153
161
  let data = {
154
162
  SourceActivityType: this.activityTypes.get(source_type),
@@ -159,6 +167,8 @@ export class ActivityLinks implements ActivityLink {
159
167
  let path = 'General/ActivityLink/CloneByActivitySid'
160
168
  this.cw.runRequest(path, data).then((response: any) => {
161
169
  resolve(response.Value)
170
+ }).catch(e => {
171
+ reject(e)
162
172
  })
163
173
  })
164
174
  }
@@ -177,6 +187,8 @@ export class ActivityLinks implements ActivityLink {
177
187
  let path = 'General/ActivityLink/Delete'
178
188
  this.cw.runRequest(path, data).then((response: any) => {
179
189
  resolve(response.Value)
190
+ }).catch(e => {
191
+ reject(e)
180
192
  })
181
193
  })
182
194
  }
@@ -221,6 +233,8 @@ export class ActivityLinks implements ActivityLink {
221
233
  let path = 'General/ActivityLink/Remove'
222
234
  this.cw.runRequest(path, data).then((response: any) => {
223
235
  resolve(response.Value)
236
+ }).catch(e => {
237
+ reject(e)
224
238
  })
225
239
  })
226
240
  }
package/src/case.ts CHANGED
@@ -212,7 +212,7 @@ export class Case {
212
212
  }).catch(e => {
213
213
  reject(e)
214
214
  })
215
- });
215
+ })
216
216
  }
217
217
 
218
218
  /**
@@ -225,7 +225,7 @@ export class Case {
225
225
  delete(caObjectId: number) {
226
226
  return new Promise((resolve, reject) => {
227
227
  var data = {
228
- CaObjectId: caObjectId,
228
+ CaObjectId: caObjectId
229
229
  }
230
230
  this.cw.runRequest('Pll/CaseObject/DeleteCase', data).then(r => {
231
231
  resolve(r.Value)
package/src/case_admin.ts CHANGED
@@ -142,7 +142,7 @@ export class CaseAdmin {
142
142
  */
143
143
  searchCaseTypeIDs(filters: Object) {
144
144
  return new Promise((resolve, reject) => {
145
- if(_.intersectionBy(filters, ['CaseType', 'CaseTypeDesc', 'CaseTypeId']).length==0) {
145
+ if(_.intersectionBy(_.keysIn(filters), ['CaseType', 'CaseTypeDesc', 'CaseTypeId']).length==0) {
146
146
  reject(new CWError(2, 'At least one of the attributes (CaFeeId, CaObjectId, FeeCode, FeeDesc) must be defined.'))
147
147
  }
148
148
  var data = filters
@@ -163,7 +163,7 @@ export class CaseAdmin {
163
163
  */
164
164
  searchCaseTypeObjects(filters: Object) {
165
165
  return new Promise((resolve, reject) => {
166
- if(_.intersectionBy(filters, ['CaseType', 'CaseTypeDesc', 'CaseTypeId']).length==0) {
166
+ if(_.intersectionBy(_.keysIn(filters), ['CaseType', 'CaseTypeDesc', 'CaseTypeId']).length==0) {
167
167
  reject(new CWError(3, 'At least one of the attributes (CaseType, CaseTypeDesc, CaseTypeId) must be defined.'))
168
168
  }
169
169
  var data = filters
@@ -263,7 +263,7 @@ export class CaseAdmin {
263
263
  */
264
264
  searchFees(filters: {AccountCode?: string, FeeCode?: string, FeeDesc?: string, FeeSetupId?: number, FeeTypeId?: number}) {
265
265
  return new Promise((resolve, reject) => {
266
- if(_.intersectionBy(filters, ['AccountCode', 'FeeCode', 'FeeDesc', 'FeeSetupId', 'FeeTypeId']).length==0) {
266
+ if(_.intersectionBy(_.keysIn(filters), ['AccountCode', 'FeeCode', 'FeeDesc', 'FeeSetupId', 'FeeTypeId']).length==0) {
267
267
  reject(new CWError(4, 'At least one of the attributes (AccountCode, FeeCode, FeeDesc, FeeSetupId, FeeTypeId) must be defined.'))
268
268
  }
269
269
  var data = filters
@@ -338,7 +338,7 @@ export class CaseAdmin {
338
338
  */
339
339
  searchDeposits(filters: {AccountCode?: string, DepositCode?: string, DepositDesc?: string, DepositId?: number, DepositTypeId?: number}) {
340
340
  return new Promise((resolve, reject) => {
341
- if(_.intersectionBy(filters, ['AccountCode', 'DepositCode', 'DepositDesc', 'DepositId', 'DepositTypeId']).length==0) {
341
+ if(_.intersectionBy(_.keysIn(filters), ['AccountCode', 'DepositCode', 'DepositDesc', 'DepositId', 'DepositTypeId']).length==0) {
342
342
  reject(new CWError(4, 'At least one of the attributes (AccountCode, DepositCode, DepositDesc, DepositId, DepositTypeId) must be defined.'))
343
343
  }
344
344
  var data = filters
package/src/case_data.ts CHANGED
@@ -143,7 +143,7 @@ export class CaseData {
143
143
  */
144
144
  searchForGroups(filters?: Object) {
145
145
  return new Promise((resolve, reject) => {
146
- if(_.intersectionBy(filters, ['CaDataGroupId', 'CaseDataGroupId', 'GroupCode', 'GroupDesc', 'GroupSum', 'SumFlag']).length==0) {
146
+ if(_.intersectionBy(_.keysIn(filters), ['CaDataGroupId', 'CaseDataGroupId', 'GroupCode', 'GroupDesc', 'GroupSum', 'SumFlag']).length==0) {
147
147
  reject(new CWError(2, 'At least one of the attributes (CaDataGroupId, CaseDataGroupId, GroupCode, GroupDesc, GroupSum, SumFlag) must be defined.'))
148
148
  }
149
149
  var data = filters
@@ -359,7 +359,7 @@ export class CaseData {
359
359
  */
360
360
  searchForListValueIds(filters?: Object) {
361
361
  return new Promise((resolve, reject) => {
362
- if(_.intersectionBy(filters, ['CaDataDetailId', 'CaDataListId', 'ListValue']).length==0) {
362
+ if(_.intersectionBy(_.keysIn(filters), ['CaDataDetailId', 'CaDataListId', 'ListValue']).length==0) {
363
363
  reject(new CWError(3, 'At least one of the attributes (CaDataDetailId, CaDataListId, ListValue) must be defined.'))
364
364
  }
365
365
  var data = filters
@@ -380,8 +380,8 @@ export class CaseData {
380
380
  */
381
381
  searchForListValueObjects(filters?: Object) {
382
382
  return new Promise((resolve, reject) => {
383
- if(_.intersectionBy(filters, ['CaDataDetailId', 'CaDataListId', 'ListValue']).length==0) {
384
- reject(new CWError(3, 'At least one of the attributes (CaDataDetailId, CaDataListId, ListValue) must be defined.'))
383
+ if(_.intersectionBy(_.keysIn(filters), ['CaDataDetailId', 'CaDataListId', 'ListValue']).length==0) {
384
+ reject(new CWError(4, 'At least one of the attributes (CaDataDetailId, CaDataListId, ListValue) must be defined.'))
385
385
  }
386
386
  var data = filters
387
387
  this.cw.runRequest('Pll/CaseDataGroup/SearchObject', data).then(r => {
@@ -521,7 +521,7 @@ export class CaseFinancial {
521
521
  */
522
522
  searchFees(filters: Object) {
523
523
  return new Promise((resolve, reject) => {
524
- if(_.intersectionBy(filters, ['CaFeeId', 'CaObjectId', 'FeeCode', 'FeeDesc']).length==0) {
524
+ if(_.intersectionBy(_.keysIn(filters), ['CaFeeId', 'CaObjectId', 'FeeCode', 'FeeDesc']).length==0) {
525
525
  reject(new CWError(4, 'At least one of the attributes (CaFeeId, CaObjectId, FeeCode, FeeDesc) must be defined.'))
526
526
  }
527
527
  var data = filters
@@ -542,7 +542,7 @@ export class CaseFinancial {
542
542
  */
543
543
  searchPayments(filters: Object) {
544
544
  return new Promise((resolve, reject) => {
545
- if(_.intersectionBy(filters, ['CaPaymentId', 'CommentText', 'FeeAmount', 'FeeCode', 'FeeDesc', 'PaymentAccount', 'PaymentAmount', 'TenderType']).length==0) {
545
+ if(_.intersectionBy(_.keysIn(filters), ['CaPaymentId', 'CommentText', 'FeeAmount', 'FeeCode', 'FeeDesc', 'PaymentAccount', 'PaymentAmount', 'TenderType']).length==0) {
546
546
  reject(new CWError(5, 'At least one of the attributes (CaPaymentId, CommentText, FeeAmount, FeeCode, FeeDesc, PaymentAccount, PaymentAmount, TenderType) must be defined.'))
547
547
  }
548
548
  var data = filters
@@ -563,7 +563,7 @@ export class CaseFinancial {
563
563
  */
564
564
  searchRefunds(filters: Object) {
565
565
  return new Promise((resolve, reject) => {
566
- if(_.intersectionBy(filters, ['CaPaymentId', 'CaPaymentRefundId', 'Comments', 'RefundAmount']).length==0) {
566
+ if(_.intersectionBy(_.keysIn(filters), ['CaPaymentId', 'CaPaymentRefundId', 'Comments', 'RefundAmount']).length==0) {
567
567
  reject(new CWError(6, 'At least one of the attributes (CaPaymentId, CaPaymentRefundId, Comments, RefundAmount) must be defined.'))
568
568
  }
569
569
  var data = filters
@@ -584,7 +584,7 @@ export class CaseFinancial {
584
584
  */
585
585
  searchDeposits(filters: Object) {
586
586
  return new Promise((resolve, reject) => {
587
- if(_.intersectionBy(filters, ['CaDepositId', 'CaObjectId', 'DepositCode', 'DepositDesc']).length==0) {
587
+ if(_.intersectionBy(_.keysIn(filters), ['CaDepositId', 'CaObjectId', 'DepositCode', 'DepositDesc']).length==0) {
588
588
  reject(new CWError(1, 'At least one of the arguments (CaDepositId, CaObjectId, DepositCode, DepositDesc) must be defined.'))
589
589
  }
590
590
  var data = filters
@@ -622,7 +622,7 @@ export class CaseFinancial {
622
622
  */
623
623
  searchFeeTemplates(filters: Object) {
624
624
  return new Promise((resolve, reject) => {
625
- if(_.intersectionBy(filters, ['FeeSetupId', 'FeeTypeId', 'FeeCode', 'FeeDesc', 'AccountCode']).length==0) {
625
+ if(_.intersectionBy(_.keysIn(filters), ['FeeSetupId', 'FeeTypeId', 'FeeCode', 'FeeDesc', 'AccountCode']).length==0) {
626
626
  reject(new CWError(7, 'At least one of the arguments (FeeSetupId, FeeTypeId, FeeCode, FeeDesc, AccountCode) must be defined.'))
627
627
  }
628
628
  var data = filters
@@ -643,7 +643,7 @@ export class CaseFinancial {
643
643
  */
644
644
  searchCaseInstruments(filters: Object) {
645
645
  return new Promise((resolve, reject) => {
646
- if(_.intersectionBy(filters, ['AddressLine1', 'Amount', 'CaInstrumentId', 'CityName', 'CommentText', 'Company', 'ContactEmail', 'ContactName', 'ContactPhone', 'CountryCode', 'InstTypeId', 'SerialNumber', 'StateCode', 'ZipCode']).length==0) {
646
+ if(_.intersectionBy(_.keysIn(filters), ['AddressLine1', 'Amount', 'CaInstrumentId', 'CityName', 'CommentText', 'Company', 'ContactEmail', 'ContactName', 'ContactPhone', 'CountryCode', 'InstTypeId', 'SerialNumber', 'StateCode', 'ZipCode']).length==0) {
647
647
  reject(new CWError(9, 'At least one of the arguments (AddressLine1, Amount, CaInstrumentId, CityName, CommentText, Company, ContactEmail, ContactName, ContactPhone, CountryCode, InstTypeId, SerialNumber, StateCode, ZipCode) must be defined.'))
648
648
  }
649
649
  var data = filters
@@ -740,7 +740,7 @@ export class CaseFinancial {
740
740
  searchCaseInstrumentReleases(filters: Object) {
741
741
  return new Promise((resolve, reject) => {
742
742
  var data = filters
743
- if(_.intersectionBy(filters, ['AmountReleased', 'CaInstReleasesId', 'CaInstrumentId', 'CommentText', 'PercentReleased', 'ReleasedBy']).length==0) {
743
+ if(_.intersectionBy(_.keysIn(filters), ['AmountReleased', 'CaInstReleasesId', 'CaInstrumentId', 'CommentText', 'PercentReleased', 'ReleasedBy']).length==0) {
744
744
  reject(new CWError(3, 'At least one of the attributes (AmountReleased, CaInstReleasesId, CaInstrumentId, CommentText, PercentReleased, ReleasedBy) must be defined.'))
745
745
  }
746
746
  this.cw.runRequest('Pll/CaseInstReleases/Search', data).then(r => {
@@ -776,7 +776,7 @@ export class CaseFinancial {
776
776
  */
777
777
  searchAvailableFees(filters: {AccountCode?: string, FeeCode?: string, FeeDesc?: string, FeeSetupId?: number, FeeTypeId?: number}) {
778
778
  return new Promise((resolve, reject) => {
779
- if(_.intersectionBy(filters, ['AccountCode', 'FeeCode', 'FeeDesc', 'FeeSetupId', 'FeeTypeId']).length==0) {
779
+ if(_.intersectionBy(_.keysIn(filters), ['AccountCode', 'FeeCode', 'FeeDesc', 'FeeSetupId', 'FeeTypeId']).length==0) {
780
780
  reject(new CWError(8, 'At least one of the attributes (AccountCode, FeeCode, FeeDesc, FeeSetupId, FeeTypeId) must be defined.'))
781
781
  }
782
782
  var data = filters
@@ -275,7 +275,7 @@ export class CaseWorkflow {
275
275
  var data = {
276
276
  CaTaskId: caTaskId
277
277
  }
278
- if(_.intersectionBy(options, ['TaskCompleteDate', 'TaskCompletedBy']).length==0) {
278
+ if(_.intersectionBy(_.keysIn(options), ['TaskCompleteDate', 'TaskCompletedBy']).length==0) {
279
279
  reject(new CWError(2, 'At least one of the attributes (TaskCompletedBy, TaskCompleteDate) must be defined.'))
280
280
  }
281
281
  if(typeof(options)!='undefined') {
@@ -358,7 +358,7 @@ export class CaseWorkflow {
358
358
  */
359
359
  searchForTasks(filters?: Object) {
360
360
  return new Promise((resolve, reject) => {
361
- if(_.intersectionBy(filters, ['ResponsibleUserId', 'TaskAvailable', 'TaskComplete', 'TaskType']).length==0) {
361
+ if(_.intersectionBy(_.keysIn(filters), ['ResponsibleUserId', 'TaskAvailable', 'TaskComplete', 'TaskType']).length==0) {
362
362
  reject(new CWError(1, 'At least one of the attributes (ResponsibleUserId, TaskAvailable, TaskComplete, TaskType) must be defined.'))
363
363
  }
364
364
  var data = filters
package/src/cityworks.ts CHANGED
@@ -225,7 +225,6 @@ module.exports = class Cityworks implements Citywork {
225
225
  },
226
226
  timeout: 10000000
227
227
  }
228
-
229
228
  let request = https.request(options, (response) => {
230
229
  let str=''
231
230
  response.on('error',function(e){
@@ -249,21 +248,34 @@ module.exports = class Cityworks implements Citywork {
249
248
  // failed
250
249
  reject(new CWError(10, 'No response received from Cityworks API.'))
251
250
  } else if(typeof(obj)!='undefined' && typeof(obj.Value)!='undefined') { // && typeof(response.Value.Token)!='undefined') {
252
- // console.log(str, options, pd, obj)
253
- resolve(obj)
251
+ switch(obj.Status) {
252
+ case 1:
253
+ reject(new CWError(1, 'Error', obj))
254
+ break;
255
+ case 2:
256
+ reject(new CWError(2, 'Unauthorized', obj))
257
+ break;
258
+ case 3:
259
+ reject(new CWError(3, 'InvalidCredentials', obj))
260
+ break;
261
+ case 0:
262
+ default:
263
+ resolve(obj);
264
+ break;
265
+ }
254
266
  } else {
255
- reject(new CWError(3, "Unknown error.", {options: options, postedData: pd, api_returned_string: obj}))
267
+ reject(new CWError(4, "Unknown error.", {options: options, postedData: pd, api_returned_string: obj}))
256
268
  }
257
269
  } else {
258
- reject(new CWError(1, "Error parsing JSON. Cityworks returned HTML.", {response: str}))
270
+ reject(new CWError(5, "Error parsing JSON. Cityworks returned HTML.", {response: str}))
259
271
  }
260
272
  } catch (e) {
261
273
  if (e instanceof SyntaxError) {
262
274
  console.log('try/catch error on JSON')
263
- reject(new CWError(1, "Error parsing JSON.", {error: e}))
275
+ reject(new CWError(6, "Error parsing JSON.", {error: e}))
264
276
  } else {
265
- console.log('try/catch error on JSON')
266
- reject(new CWError(1, "Error parsing JSON."))
277
+ console.log('try/catch error on JSON - but not an instance of SyntaxError')
278
+ reject(new CWError(7, "Error parsing JSON."))
267
279
  }
268
280
  }
269
281
  })
@@ -287,20 +299,20 @@ module.exports = class Cityworks implements Citywork {
287
299
  path = 'General/Authentication/CityworksOnlineAuthenticate'
288
300
  }
289
301
  this.runRequest(path, data).then((response: any) => {
290
- if(response.Status>0) {
291
- // failed
292
- reject(new CWError(10, response.Message))
293
- } else if(typeof(response.Value)!='undefined' && typeof(response.Value.Token)!='undefined') {
302
+ // if(response.Status>0) {
303
+ // // failed
304
+ // reject(new CWError(100, response.Message))
305
+ // } else if(typeof(response.Value)!='undefined' && typeof(response.Value.Token)!='undefined') {
294
306
  this.login = login
295
307
  this.password = password
296
308
  this.Token = response.Value.Token
297
309
  resolve(true)
298
- } else {
299
- // failed
300
- reject(new CWError(11, 'Unknown Error'))
301
- }
310
+ // } else {
311
+ // // failed
312
+ // reject(new CWError(11, 'Unknown Error'))
313
+ // }
302
314
  }).catch(error => {
303
- reject(error)
315
+ reject(error);
304
316
  })
305
317
  })
306
318
  }
package/src/comments.ts CHANGED
@@ -59,6 +59,8 @@ export class Comments {
59
59
  }
60
60
  this.cw.runRequest('Ams/Comment/Add', data).then((response: any) => {
61
61
  resolve(response.Value)
62
+ }).catch(e => {
63
+ reject(e)
62
64
  })
63
65
  })
64
66
  }
@@ -79,6 +81,8 @@ export class Comments {
79
81
  }
80
82
  this.cw.runRequest('Ams/Comment/Update', data).then((response: any) => {
81
83
  resolve(response.Value)
84
+ }).catch(e => {
85
+ reject(e)
82
86
  })
83
87
  })
84
88
  }
@@ -126,6 +130,8 @@ export class Comments {
126
130
  _.set(data, 'ActivityType', this.activityTypes.get(this.currentActivityType))
127
131
  this.cw.runRequest('Ams/Comment/PredefinedComments', data).then((response: any) => {
128
132
  resolve(response.Value)
133
+ }).catch(e => {
134
+ reject(e)
129
135
  })
130
136
  })
131
137
  }
@@ -152,7 +158,9 @@ export class Comments {
152
158
  // console.log(data, 'data')
153
159
  // this.cw.runRequest('Ams/Comment/ByActivityTypes', data).then((response: any) => {
154
160
  // resolve(response.Value)
155
- // })
161
+ // }).catch(e => {
162
+ // reject(e)
163
+ // })
156
164
  // })
157
165
  // }
158
166
 
package/src/error.ts CHANGED
@@ -1,4 +1,12 @@
1
- interface CWErrorInt {
1
+ const _ = require('lodash')
2
+
3
+ /**
4
+ * CWErrorInt interface definition for implementation by CWError
5
+ *
6
+ * `{name: string, code: number, message: string, info?: string}`
7
+ *
8
+ */
9
+ export interface CWErrorInt {
2
10
  name: string
3
11
  code: number
4
12
  message: string
@@ -8,8 +16,6 @@ interface CWErrorInt {
8
16
  /**
9
17
  * CWError implements a custom error class for this codebase with additional information
10
18
  *
11
- * `{name: string, code:number, info: object}`
12
- *
13
19
  */
14
20
  export class CWError implements CWErrorInt {
15
21
  /**
@@ -42,6 +48,8 @@ export class CWError implements CWErrorInt {
42
48
  this.code = code
43
49
  this.message = message
44
50
  if(typeof(info) !== 'undefined') {
51
+ if(_.has(info, 'Message'))
52
+ this.message = _.get(info, 'Message')
45
53
  this.info = JSON.stringify(info)
46
54
  }
47
55
  }