@sonoransoftware/sonoran.js 1.0.3 → 1.0.6

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 (41) hide show
  1. package/dist/constants.d.ts +56 -0
  2. package/dist/libs/rest/src/lib/REST.js +18 -1
  3. package/dist/libs/rest/src/lib/utils/constants.d.ts +23 -3
  4. package/dist/libs/rest/src/lib/utils/constants.js +12 -0
  5. package/dist/managers/CMSManager.d.ts +19 -0
  6. package/dist/managers/CMSManager.js +61 -6
  7. package/dist/managers/CMSServerManager.js +6 -0
  8. package/package.json +2 -2
  9. package/src/builders/cad/DispatchCall.ts +158 -158
  10. package/src/builders/index.ts +2 -2
  11. package/src/constants.ts +58 -0
  12. package/src/errors/LibraryErrors.ts +42 -42
  13. package/src/errors/Messages.ts +6 -6
  14. package/src/errors/index.ts +1 -1
  15. package/src/index.ts +3 -3
  16. package/src/instance/Instance.ts +117 -117
  17. package/src/instance/instance.types.ts +16 -16
  18. package/src/libs/rest/src/index.ts +5 -5
  19. package/src/libs/rest/src/lib/REST.ts +19 -2
  20. package/src/libs/rest/src/lib/RequestManager.ts +255 -255
  21. package/src/libs/rest/src/lib/errors/APIError.ts +14 -14
  22. package/src/libs/rest/src/lib/errors/HTTPError.ts +21 -21
  23. package/src/libs/rest/src/lib/errors/RateLimitError.ts +20 -20
  24. package/src/libs/rest/src/lib/errors/index.ts +3 -3
  25. package/src/libs/rest/src/lib/handlers/IHandler.ts +12 -12
  26. package/src/libs/rest/src/lib/handlers/SequentialHandler.ts +157 -157
  27. package/src/libs/rest/src/lib/utils/constants.ts +35 -2
  28. package/src/libs/rest/src/lib/utils/utils.ts +17 -17
  29. package/src/managers/BaseManager.ts +15 -15
  30. package/src/managers/CADActiveUnitsManager.ts +49 -49
  31. package/src/managers/CADManager.ts +58 -58
  32. package/src/managers/CADServerManager.ts +26 -26
  33. package/src/managers/CMSManager.ts +60 -11
  34. package/src/managers/CMSServerManager.ts +6 -0
  35. package/src/managers/CacheManager.ts +37 -37
  36. package/src/managers/DataManager.ts +63 -63
  37. package/src/structures/Base.ts +27 -27
  38. package/src/structures/CADActiveUnit.ts +84 -84
  39. package/src/structures/CADServer.ts +36 -36
  40. package/src/structures/CMSServer.ts +25 -25
  41. package/src/utils/utils.ts +74 -74
@@ -115,6 +115,55 @@ export interface CMSCheckComApiIdPromiseResult {
115
115
  reason?: string;
116
116
  username?: string;
117
117
  }
118
+ export interface CMSGetDepartmentsPromiseResult {
119
+ success: boolean;
120
+ reason?: string;
121
+ data?: CMSDepartment[];
122
+ }
123
+ export interface CMSSetAccountRanksPromiseResult {
124
+ success: boolean;
125
+ reason?: string;
126
+ data?: {
127
+ accId: string;
128
+ sysStatus: boolean;
129
+ comStatus: boolean;
130
+ joinDate: string;
131
+ lastLogin: string;
132
+ owner: boolean;
133
+ banned: boolean;
134
+ activeApiIds: string[];
135
+ primaryIdentifier: string;
136
+ secondaryIdentifiers: {
137
+ identifiers: {
138
+ id: string;
139
+ label: string;
140
+ }[];
141
+ };
142
+ primaryRank: string;
143
+ secondaryRanks: string[];
144
+ primaryDepartment: string;
145
+ secondaryDepartments: string[];
146
+ };
147
+ }
148
+ export interface CMSSetAccountRanksChangesObject {
149
+ set?: {
150
+ primary?: string | null;
151
+ secondary?: string[];
152
+ };
153
+ add: string[];
154
+ remove: string[];
155
+ }
156
+ export interface CMSDepartment {
157
+ uuid: string;
158
+ label: string;
159
+ labelTwo: string;
160
+ ranks: {
161
+ id: string;
162
+ label: string;
163
+ primaryOnly: boolean;
164
+ secondaryOnly: boolean;
165
+ }[];
166
+ }
118
167
  export interface CADGetAccountPromiseResult {
119
168
  success: boolean;
120
169
  reason?: string;
@@ -172,3 +221,10 @@ export interface CADGetAccountPromiseResult {
172
221
  apiIds: string[];
173
222
  };
174
223
  }
224
+ export interface clockInOutRequest {
225
+ id: number;
226
+ notes: any[];
227
+ endTime: string;
228
+ completed: boolean;
229
+ startTime: string;
230
+ }
@@ -78,7 +78,16 @@ class REST extends events_1.EventEmitter {
78
78
  return {
79
79
  apiId: args[0],
80
80
  username: args[1],
81
- accId: args[2]
81
+ accId: args[2],
82
+ discord: args[3]
83
+ };
84
+ }
85
+ case 'GET_ACCOUNT_RANKS': {
86
+ return {
87
+ apiId: args[0],
88
+ username: args[1],
89
+ accId: args[2],
90
+ discord: args[3]
82
91
  };
83
92
  }
84
93
  case 'CLOCK_IN_OUT': {
@@ -93,6 +102,14 @@ class REST extends events_1.EventEmitter {
93
102
  apiId: args[0]
94
103
  };
95
104
  }
105
+ case 'SET_ACCOUNT_RANKS': {
106
+ return {
107
+ accountId: args[0],
108
+ set: args[1],
109
+ add: args[2],
110
+ remove: args[3],
111
+ };
112
+ }
96
113
  default: {
97
114
  return args;
98
115
  }
@@ -32,7 +32,7 @@ export declare const EmergencyCADAPITypes: APITypeData[];
32
32
  export declare const GeneralCMSAPITypes: APITypeData[];
33
33
  export declare const ServersCMSAPITypes: APITypeData[];
34
34
  export declare const AllAPITypes: AllAPITypeData[];
35
- export declare type AllAPITypesType = 'GET_SERVERS' | 'SET_SERVERS' | 'GET_VERSION' | 'SET_PENAL_CODES' | 'SET_API_ID' | 'GET_TEMPLATES' | 'NEW_RECORD' | 'EDIT_RECORD' | 'REMOVE_RECORD' | 'LOOKUP_INT' | 'LOOKUP' | 'GET_ACCOUNT' | 'CHECK_APIID' | 'APPLY_PERMISSION_KEY' | 'SET_ACCOUNT_PERMISSIONS' | 'BAN_USER' | 'VERIFY_SECRET' | 'AUTH_STREETSIGNS' | 'SET_POSTALS' | 'SEND_PHOTO' | 'GET_CHARACTERS' | 'NEW_CHARACTER' | 'EDIT_CHARACTER' | 'REMOVE_CHARACTER' | 'GET_IDENTIFIERS' | 'MODIFY_IDENTIFIER' | 'SET_IDENTIFIER' | 'UNIT_PANIC' | 'UNIT_STATUS' | 'GET_BLIPS' | 'ADD_BLIP' | 'MODIFY_BLIP' | 'REMOVE_BLIP' | '911_CALL' | 'REMOVE_911' | 'GET_CALLS' | 'GET_ACTIVE_UNITS' | 'KICK_UNIT' | 'NEW_DISPATCH' | 'ATTACH_UNIT' | 'DETACH_UNIT' | 'SET_CALL_POSTAL' | 'SET_CALL_PRIMARY' | 'ADD_CALL_NOTE' | 'CLOSE_CALL' | 'UNIT_LOCATION' | 'SET_STREETSIGN_CONFIG' | 'UPDATE_STREETSIGN' | 'GET_COM_ACCOUNT' | 'GET_SUB_VERSION' | 'CHECK_COM_APIID' | 'VERIFY_WHITELIST' | 'CLOCK_IN_OUT' | 'FULL_WHITELIST' | 'GET_ACCOUNT_RANKS';
35
+ export declare type AllAPITypesType = 'GET_SERVERS' | 'SET_SERVERS' | 'GET_VERSION' | 'SET_PENAL_CODES' | 'SET_API_ID' | 'GET_TEMPLATES' | 'NEW_RECORD' | 'EDIT_RECORD' | 'REMOVE_RECORD' | 'LOOKUP_INT' | 'LOOKUP' | 'GET_ACCOUNT' | 'CHECK_APIID' | 'APPLY_PERMISSION_KEY' | 'SET_ACCOUNT_PERMISSIONS' | 'BAN_USER' | 'VERIFY_SECRET' | 'AUTH_STREETSIGNS' | 'SET_POSTALS' | 'SEND_PHOTO' | 'GET_CHARACTERS' | 'NEW_CHARACTER' | 'EDIT_CHARACTER' | 'REMOVE_CHARACTER' | 'GET_IDENTIFIERS' | 'MODIFY_IDENTIFIER' | 'SET_IDENTIFIER' | 'UNIT_PANIC' | 'UNIT_STATUS' | 'GET_BLIPS' | 'ADD_BLIP' | 'MODIFY_BLIP' | 'REMOVE_BLIP' | '911_CALL' | 'REMOVE_911' | 'GET_CALLS' | 'GET_ACTIVE_UNITS' | 'KICK_UNIT' | 'NEW_DISPATCH' | 'ATTACH_UNIT' | 'DETACH_UNIT' | 'SET_CALL_POSTAL' | 'SET_CALL_PRIMARY' | 'ADD_CALL_NOTE' | 'CLOSE_CALL' | 'UNIT_LOCATION' | 'SET_STREETSIGN_CONFIG' | 'UPDATE_STREETSIGN' | 'GET_COM_ACCOUNT' | 'GET_DEPARTMENTS' | 'GET_SUB_VERSION' | 'CHECK_COM_APIID' | 'VERIFY_WHITELIST' | 'CLOCK_IN_OUT' | 'FULL_WHITELIST' | 'GET_ACCOUNT_RANKS' | 'SET_ACCOUNT_RANKS';
36
36
  export interface CMSServerAPIStruct {
37
37
  id: number;
38
38
  name: string;
@@ -386,7 +386,8 @@ export interface RESTTypedAPIDataStructs {
386
386
  GET_COM_ACCOUNT: [
387
387
  apiId?: string,
388
388
  username?: string,
389
- accId?: string
389
+ accId?: string,
390
+ discord?: string
390
391
  ];
391
392
  GET_SUB_VERSION: [];
392
393
  CHECK_COM_APIID: [apiId: string];
@@ -395,10 +396,21 @@ export interface RESTTypedAPIDataStructs {
395
396
  accId?: string,
396
397
  forceClockIn?: boolean
397
398
  ];
399
+ GET_DEPARTMENTS: [];
398
400
  GET_ACCOUNT_RANKS: [
399
401
  apiId?: string,
400
402
  username?: string,
401
- accId?: string
403
+ accId?: string,
404
+ discord?: string
405
+ ];
406
+ SET_ACCOUNT_RANKS: [
407
+ accountId: string,
408
+ set?: {
409
+ primary?: string | null;
410
+ secondary?: string[];
411
+ },
412
+ add?: string[],
413
+ remove?: string[]
402
414
  ];
403
415
  GET_GAME_SERVERS: [];
404
416
  VERIFY_WHITELIST: [
@@ -498,4 +510,12 @@ export declare type PossibleRequestData = undefined | {
498
510
  } | {
499
511
  apiId: string;
500
512
  forceClockIn: boolean;
513
+ } | {
514
+ accountId: string;
515
+ set?: {
516
+ primary: string[];
517
+ secondary: string[];
518
+ };
519
+ add?: string[];
520
+ remove?: string[];
501
521
  };
@@ -322,6 +322,18 @@ exports.GeneralCMSAPITypes = [
322
322
  method: 'POST',
323
323
  minVersion: 2,
324
324
  },
325
+ {
326
+ type: 'SET_ACCOUNT_RANKS',
327
+ path: 'general/set_account_ranks',
328
+ method: 'POST',
329
+ minVersion: 2,
330
+ },
331
+ {
332
+ type: 'GET_DEPARTMENTS',
333
+ path: 'general/get_departments',
334
+ method: 'POST',
335
+ minVersion: 2,
336
+ },
325
337
  {
326
338
  type: 'GET_SUB_VERSION',
327
339
  path: 'general/get_sub_version',
@@ -45,6 +45,7 @@ export declare class CMSManager extends BaseManager {
45
45
  accId?: string;
46
46
  apiId?: string;
47
47
  username?: string;
48
+ discord?: string;
48
49
  }): Promise<globalTypes.CMSGetComAccountPromiseResult>;
49
50
  /**
50
51
  * Gets a community account by `accId`, `apiId`, or `username`.
@@ -58,6 +59,7 @@ export declare class CMSManager extends BaseManager {
58
59
  accId?: string;
59
60
  apiId?: string;
60
61
  username?: string;
62
+ discord?: string;
61
63
  }): Promise<globalTypes.CMSGetAccountRanksPromiseResult>;
62
64
  /**
63
65
  * Clocks in or out an account by `accId` or `apiId`.
@@ -78,4 +80,21 @@ export declare class CMSManager extends BaseManager {
78
80
  * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
79
81
  */
80
82
  checkComApiId(apiId: string): Promise<globalTypes.CMSCheckComApiIdPromiseResult>;
83
+ /**
84
+ * Gets all department information within the community CMS.
85
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
86
+ */
87
+ getDepartments(): Promise<globalTypes.CMSGetDepartmentsPromiseResult>;
88
+ /**
89
+ * Sets a community account's ranks for the CMS community.
90
+ * @param {string} accountId The object that contains critical data to clock in or out an account.
91
+ * @param {Object} changes The object that contains change data for setting account ranks.
92
+ * @param {Object} [changes.set] (Optional) The object that contains primary and secondary data for setting account ranks.
93
+ * @param {string} [changes.set.primary] (Optional) The primary rank ID wanting to set to the account.
94
+ * @param {string} [changes.set.secondary] (Optional) The secondary rank ID(s) wanting to set to the account.
95
+ * @param {Array} [changes.add] (Optional) The secondary rank IDs wanting to add to the account.
96
+ * @param {Array} [changes.remove] (Optional) The secondary rank IDs wanting to remove to the account.
97
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
98
+ */
99
+ setAccountRanks(accountId: string, changes: globalTypes.CMSSetAccountRanksChangesObject): Promise<globalTypes.CMSSetAccountRanksPromiseResult>;
81
100
  }
@@ -43,12 +43,16 @@ class CMSManager extends BaseManager_1.BaseManager {
43
43
  var _a;
44
44
  try {
45
45
  const versionResp = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_SUB_VERSION'));
46
+ const version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i, '$1'));
46
47
  const mutableThis = this;
47
- mutableThis.version = Number.parseInt(versionResp.replace(/(^\d+)(.+$)/i, '$1'));
48
- if (this.version >= globalTypes.CMSSubscriptionVersionEnum.STANDARD) {
48
+ if (version >= globalTypes.CMSSubscriptionVersionEnum.STANDARD) {
49
49
  this.servers = new CMSServerManager_1.CMSServerManager(instance, this);
50
50
  }
51
51
  mutableThis.ready = true;
52
+ mutableThis.version = version;
53
+ console.log(mutableThis.version);
54
+ console.log(this.version);
55
+ console.log(version);
52
56
  instance.isCMSSuccessful = true;
53
57
  instance.emit('CMS_SETUP_SUCCESSFUL');
54
58
  }
@@ -122,7 +126,7 @@ class CMSManager extends BaseManager_1.BaseManager {
122
126
  return new Promise(async (resolve, reject) => {
123
127
  var _a;
124
128
  try {
125
- const getAccountRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_COM_ACCOUNT', params.apiId, params.username, params.accId));
129
+ const getAccountRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_COM_ACCOUNT', params.apiId, params.username, params.accId, params.discord));
126
130
  resolve({ success: true, data: getAccountRequest });
127
131
  }
128
132
  catch (err) {
@@ -147,7 +151,7 @@ class CMSManager extends BaseManager_1.BaseManager {
147
151
  return new Promise(async (resolve, reject) => {
148
152
  var _a;
149
153
  try {
150
- const getAccountRanksRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_ACCOUNT_RANKS', params.apiId, params.username, params.accId));
154
+ const getAccountRanksRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_ACCOUNT_RANKS', params.apiId, params.username, params.accId, params.discord));
151
155
  resolve({ success: true, data: getAccountRanksRequest });
152
156
  }
153
157
  catch (err) {
@@ -173,8 +177,10 @@ class CMSManager extends BaseManager_1.BaseManager {
173
177
  var _a;
174
178
  try {
175
179
  const clockInOutRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('CLOCK_IN_OUT', data.apiId, data.accId, !!data.forceClockIn));
176
- const clockInOutRequestString = clockInOutRequest;
177
- resolve({ success: true, clockedIn: clockInOutRequestString.includes('CLOCKED IN') });
180
+ const clockInOutResponse = clockInOutRequest;
181
+ if (!clockInOutResponse)
182
+ resolve({ success: false, reason: clockInOutRequest });
183
+ resolve({ success: true, clockedIn: clockInOutResponse.completed });
178
184
  }
179
185
  catch (err) {
180
186
  if (err instanceof src_1.APIError) {
@@ -208,5 +214,54 @@ class CMSManager extends BaseManager_1.BaseManager {
208
214
  }
209
215
  });
210
216
  }
217
+ /**
218
+ * Gets all department information within the community CMS.
219
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
220
+ */
221
+ async getDepartments() {
222
+ return new Promise(async (resolve, reject) => {
223
+ var _a;
224
+ try {
225
+ const getDepartmentsRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('GET_DEPARTMENTS'));
226
+ resolve({ success: true, data: getDepartmentsRequest });
227
+ }
228
+ catch (err) {
229
+ if (err instanceof src_1.APIError) {
230
+ resolve({ success: false, reason: err.response });
231
+ }
232
+ else {
233
+ reject(err);
234
+ }
235
+ }
236
+ });
237
+ }
238
+ /**
239
+ * Sets a community account's ranks for the CMS community.
240
+ * @param {string} accountId The object that contains critical data to clock in or out an account.
241
+ * @param {Object} changes The object that contains change data for setting account ranks.
242
+ * @param {Object} [changes.set] (Optional) The object that contains primary and secondary data for setting account ranks.
243
+ * @param {string} [changes.set.primary] (Optional) The primary rank ID wanting to set to the account.
244
+ * @param {string} [changes.set.secondary] (Optional) The secondary rank ID(s) wanting to set to the account.
245
+ * @param {Array} [changes.add] (Optional) The secondary rank IDs wanting to add to the account.
246
+ * @param {Array} [changes.remove] (Optional) The secondary rank IDs wanting to remove to the account.
247
+ * @returns {Promise} Promise object represents if the request was successful with reason for failure if needed.
248
+ */
249
+ async setAccountRanks(accountId, changes) {
250
+ return new Promise(async (resolve, reject) => {
251
+ var _a;
252
+ try {
253
+ const setAccountRanksRequest = await ((_a = this.rest) === null || _a === void 0 ? void 0 : _a.request('SET_ACCOUNT_RANKS', accountId, changes.set, changes.add, changes.remove));
254
+ resolve({ success: true, data: setAccountRanksRequest });
255
+ }
256
+ catch (err) {
257
+ if (err instanceof src_1.APIError) {
258
+ resolve({ success: false, reason: err.response });
259
+ }
260
+ else {
261
+ reject(err);
262
+ }
263
+ }
264
+ });
265
+ }
211
266
  }
212
267
  exports.CMSManager = CMSManager;
@@ -8,6 +8,11 @@ class CMSServerManager extends CacheManager_1.CacheManager {
8
8
  super(instance, CMSServer_1.CMSServer, []);
9
9
  (async () => {
10
10
  var _a;
11
+ while (!manager.ready) {
12
+ await new Promise((resolve) => {
13
+ setTimeout(resolve, 100);
14
+ });
15
+ }
11
16
  try {
12
17
  const serversRes = await ((_a = manager.rest) === null || _a === void 0 ? void 0 : _a.request('GET_GAME_SERVERS'));
13
18
  const servers = serversRes.servers;
@@ -18,6 +23,7 @@ class CMSServerManager extends CacheManager_1.CacheManager {
18
23
  };
19
24
  this._add(serverStruct, true, server.id);
20
25
  });
26
+ console.log(`Found ${servers.length} servers`);
21
27
  }
22
28
  catch (err) {
23
29
  throw new Error(String(err));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonoransoftware/sonoran.js",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "Sonoran.js is a library that allows you to interact with the Sonoran CAD and Sonoran CMS API. Based off of and utilizes several Discord.js library techniques for ease of use.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "license": "ISC",
19
19
  "devDependencies": {
20
20
  "@types/node": "^17.0.21",
21
- "@types/node-fetch": "^2.6.1",
21
+ "@types/node-fetch": "^2.6.2",
22
22
  "eslint": "^8.10.0",
23
23
  "eslint-config-prettier": "^8.5.0",
24
24
  "eslint-plugin-import": "^2.25.4",
@@ -1,159 +1,159 @@
1
- import { CADNewDispatchBuilderOptions } from '../../constants';
2
- import { CADDispatchOriginEnums, CADDispatchStatusEnums } from '../../libs/rest/src';
3
-
4
- /**
5
- * Represents a constructed dispatch call for API requests
6
- */
7
- export class DispatchCallBuilder {
8
- public readonly data: CADNewDispatchBuilderOptions;
9
-
10
- /**
11
- * Dispatch Call Builder used for API calls with Sonoran CAD to create a new dispatch call.
12
- * @param data Data Options (CADNewDispatchBuilderOptions) used to build the new dispatch call
13
- */
14
- public constructor(data: CADNewDispatchBuilderOptions = {}) {
15
- this.data = { ...data };
16
- }
17
-
18
- /**
19
- * Sets the origin for this dispatch call
20
- * @param origin Origin enum used for this dispatch call for information purposes
21
- */
22
- public setOrigin(origin: CADDispatchOriginEnums): this {
23
- this.data.origin = origin;
24
- return this;
25
- }
26
-
27
- /**
28
- * Sets the status for this dispatch call
29
- * @param status Status enum used for the dispatch call for information purposes
30
- */
31
- public setStatus(status: CADDispatchStatusEnums): this {
32
- this.data.status = status;
33
- return this;
34
- }
35
-
36
- /**
37
- * Sets the priority level for this dispatch call
38
- * @param priority Priority level used for the dispatch call for information purposes
39
- */
40
- public setPriority(priority: 1 | 2 | 3): this {
41
- this.data.priority = priority;
42
- return this;
43
- }
44
-
45
- /**
46
- * Sets the block for this dispatch call
47
- * @param block Block used for the dispatch call for information purposes
48
- */
49
- public setBlock(block: string): this {
50
- this.data.block = block;
51
- return this;
52
- }
53
-
54
- /**
55
- * Sets the address for this dispatch call
56
- * @param address Address used for the dispatch call for information purposes
57
- */
58
- public setAddress(address: string): this {
59
- this.data.address = address;
60
- return this;
61
- }
62
-
63
- /**
64
- * Sets the postal for this dispatch call
65
- * @param postal Postal used for the dispatch call for information purposes
66
- */
67
- public setPostal(postal: string): this {
68
- this.data.postal = postal;
69
- return this;
70
- }
71
-
72
- /**
73
- * Sets the title for this dispatch call
74
- * @param title Title used for the dispatch call for information purposes
75
- */
76
- public setTitle(title: string): this {
77
- this.data.title = title;
78
- return this;
79
- }
80
-
81
- /**
82
- * Sets the code for this dispatch call
83
- * @param code Code used for the dispatch call for information purposes
84
- */
85
- public setCode(code: string): this {
86
- this.data.code = code;
87
- return this;
88
- }
89
-
90
- /**
91
- * Sets the primary tracking preference for this dispatch call
92
- * @param primaryUnit Primary unit identifier
93
- */
94
- public setPrimary(primaryUnit: number): this {
95
- this.data.primary = primaryUnit;
96
- return this;
97
- }
98
-
99
- /**
100
- * Sets the track primary preference for this dispatch call
101
- * @param preference Preference for tracking primary
102
- */
103
- public setTrackPrimaryPreference(preference: boolean): this {
104
- this.data.trackPrimary = preference;
105
- return this;
106
- }
107
-
108
- /**
109
- * Sets the description for this dispatch call
110
- * @param description Description for a dispatch call
111
- */
112
- public setDescription(description: string): this {
113
- this.data.description = description;
114
- return this;
115
- }
116
-
117
- /**
118
- * Sets metadata for this dispatch call that can be used later on
119
- * @param metaData Dictionary of metadata to store with a dispatch call, can be used later on
120
- */
121
- public setMetadata(metaData: Record<string, string>): this {
122
- this.data.metaData = metaData;
123
- return this;
124
- }
125
-
126
- /**
127
- * Sets specified units for this dispatch call
128
- * @param units Units to be removed from a call
129
- */
130
- public setUnits(units: string[]): this {
131
- this.data.units = units;
132
- return this;
133
- }
134
-
135
- /**
136
- * Adds specified units from this dispatch call
137
- * @param units Units to be removed from a call
138
- */
139
- public addUnits(...units: string[]): this {
140
- this.data.units?.push(...units);
141
- return this;
142
- }
143
-
144
- /**
145
- * Removes specified units from this dispatch call
146
- * @param units Units to be removed from a call
147
- */
148
- public removeUnits(...units: string[]): this {
149
- this.data.units?.filter((unit) => !units.includes(unit));
150
- return this;
151
- }
152
-
153
- /**
154
- * Transforms the dispatch call to a plain object
155
- */
156
- public toJSON(): CADNewDispatchBuilderOptions{
157
- return { ...this.data };
158
- }
1
+ import { CADNewDispatchBuilderOptions } from '../../constants';
2
+ import { CADDispatchOriginEnums, CADDispatchStatusEnums } from '../../libs/rest/src';
3
+
4
+ /**
5
+ * Represents a constructed dispatch call for API requests
6
+ */
7
+ export class DispatchCallBuilder {
8
+ public readonly data: CADNewDispatchBuilderOptions;
9
+
10
+ /**
11
+ * Dispatch Call Builder used for API calls with Sonoran CAD to create a new dispatch call.
12
+ * @param data Data Options (CADNewDispatchBuilderOptions) used to build the new dispatch call
13
+ */
14
+ public constructor(data: CADNewDispatchBuilderOptions = {}) {
15
+ this.data = { ...data };
16
+ }
17
+
18
+ /**
19
+ * Sets the origin for this dispatch call
20
+ * @param origin Origin enum used for this dispatch call for information purposes
21
+ */
22
+ public setOrigin(origin: CADDispatchOriginEnums): this {
23
+ this.data.origin = origin;
24
+ return this;
25
+ }
26
+
27
+ /**
28
+ * Sets the status for this dispatch call
29
+ * @param status Status enum used for the dispatch call for information purposes
30
+ */
31
+ public setStatus(status: CADDispatchStatusEnums): this {
32
+ this.data.status = status;
33
+ return this;
34
+ }
35
+
36
+ /**
37
+ * Sets the priority level for this dispatch call
38
+ * @param priority Priority level used for the dispatch call for information purposes
39
+ */
40
+ public setPriority(priority: 1 | 2 | 3): this {
41
+ this.data.priority = priority;
42
+ return this;
43
+ }
44
+
45
+ /**
46
+ * Sets the block for this dispatch call
47
+ * @param block Block used for the dispatch call for information purposes
48
+ */
49
+ public setBlock(block: string): this {
50
+ this.data.block = block;
51
+ return this;
52
+ }
53
+
54
+ /**
55
+ * Sets the address for this dispatch call
56
+ * @param address Address used for the dispatch call for information purposes
57
+ */
58
+ public setAddress(address: string): this {
59
+ this.data.address = address;
60
+ return this;
61
+ }
62
+
63
+ /**
64
+ * Sets the postal for this dispatch call
65
+ * @param postal Postal used for the dispatch call for information purposes
66
+ */
67
+ public setPostal(postal: string): this {
68
+ this.data.postal = postal;
69
+ return this;
70
+ }
71
+
72
+ /**
73
+ * Sets the title for this dispatch call
74
+ * @param title Title used for the dispatch call for information purposes
75
+ */
76
+ public setTitle(title: string): this {
77
+ this.data.title = title;
78
+ return this;
79
+ }
80
+
81
+ /**
82
+ * Sets the code for this dispatch call
83
+ * @param code Code used for the dispatch call for information purposes
84
+ */
85
+ public setCode(code: string): this {
86
+ this.data.code = code;
87
+ return this;
88
+ }
89
+
90
+ /**
91
+ * Sets the primary tracking preference for this dispatch call
92
+ * @param primaryUnit Primary unit identifier
93
+ */
94
+ public setPrimary(primaryUnit: number): this {
95
+ this.data.primary = primaryUnit;
96
+ return this;
97
+ }
98
+
99
+ /**
100
+ * Sets the track primary preference for this dispatch call
101
+ * @param preference Preference for tracking primary
102
+ */
103
+ public setTrackPrimaryPreference(preference: boolean): this {
104
+ this.data.trackPrimary = preference;
105
+ return this;
106
+ }
107
+
108
+ /**
109
+ * Sets the description for this dispatch call
110
+ * @param description Description for a dispatch call
111
+ */
112
+ public setDescription(description: string): this {
113
+ this.data.description = description;
114
+ return this;
115
+ }
116
+
117
+ /**
118
+ * Sets metadata for this dispatch call that can be used later on
119
+ * @param metaData Dictionary of metadata to store with a dispatch call, can be used later on
120
+ */
121
+ public setMetadata(metaData: Record<string, string>): this {
122
+ this.data.metaData = metaData;
123
+ return this;
124
+ }
125
+
126
+ /**
127
+ * Sets specified units for this dispatch call
128
+ * @param units Units to be removed from a call
129
+ */
130
+ public setUnits(units: string[]): this {
131
+ this.data.units = units;
132
+ return this;
133
+ }
134
+
135
+ /**
136
+ * Adds specified units from this dispatch call
137
+ * @param units Units to be removed from a call
138
+ */
139
+ public addUnits(...units: string[]): this {
140
+ this.data.units?.push(...units);
141
+ return this;
142
+ }
143
+
144
+ /**
145
+ * Removes specified units from this dispatch call
146
+ * @param units Units to be removed from a call
147
+ */
148
+ public removeUnits(...units: string[]): this {
149
+ this.data.units?.filter((unit) => !units.includes(unit));
150
+ return this;
151
+ }
152
+
153
+ /**
154
+ * Transforms the dispatch call to a plain object
155
+ */
156
+ public toJSON(): CADNewDispatchBuilderOptions{
157
+ return { ...this.data };
158
+ }
159
159
  }