@tamu-dor/famis-db 2.0.2 → 2.0.4

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 (68) hide show
  1. package/.github/workflows/actions.yml +16 -0
  2. package/docs/index.html +1453 -335
  3. package/docs.md +363 -190
  4. package/index.d.ts +619 -0
  5. package/index.js +56 -2
  6. package/package.json +3 -3
  7. package/readme.md +2 -2
  8. package/schemas/migrations/202102041628.sql +26 -0
  9. package/schemas/migrations/202102261131.sql +68 -0
  10. package/schemas/migrations/202104011516.sql +12 -0
  11. package/schemas/migrations/202104210829.sql +69 -0
  12. package/schemas/migrations/202104210926.sql +77 -0
  13. package/schemas/migrations/202105201344.sql +17 -0
  14. package/schemas/migrations/202105201355.sql +26 -0
  15. package/schemas/migrations/202105251323.sql +17 -0
  16. package/schemas/migrations/202106081436.sql +20 -0
  17. package/schemas/migrations/202106221333.sql +20 -0
  18. package/schemas/migrations/202107291406.sql +35 -0
  19. package/schemas/migrations/202108181427.sql +26 -0
  20. package/schemas/migrations/202110041133.sql +75 -0
  21. package/schemas/migrations/202110251113.sql +20 -0
  22. package/schemas/migrations/202111021104.sql +13 -0
  23. package/schemas/migrations/202111021110.sql +16 -0
  24. package/schemas/migrations/202111100901.sql +16 -0
  25. package/schemas/migrations/202111101041.sql +79 -0
  26. package/schemas/migrations/20211115.sql +71 -0
  27. package/schemas/migrations/202112171038.sql +89 -0
  28. package/schemas/migrations/202201211055.sql +97 -0
  29. package/schemas/migrations/202201211124.sql +24 -0
  30. package/schemas/migrations/202201261015.sql +17 -0
  31. package/schemas/migrations/202201311403.sql +91 -0
  32. package/schemas/migrations/202202081201.sql +41 -0
  33. package/schemas/migrations/202202081205.sql +45 -0
  34. package/schemas/migrations/202202141101.sql +21 -0
  35. package/schemas/migrations/202202141117.sql +76 -0
  36. package/schemas/migrations/202202151329.sql +21 -0
  37. package/schemas/migrations/202202171025.sql +4 -0
  38. package/schemas/migrations/20220225.sql +23 -0
  39. package/schemas/migrations/202203150618.sql +13 -0
  40. package/schemas/migrations/202204041316.sql +12 -0
  41. package/schemas/migrations/202204141018.sql +78 -0
  42. package/schemas/migrations/202204141301.sql +36 -0
  43. package/schemas/migrations/202205061236.sql +15 -0
  44. package/schemas/migrations/202206021248.sql +20 -0
  45. package/schemas/migrations/20220615.sql +39 -0
  46. package/schemas/migrations/202206291132.sql +15 -0
  47. package/schemas/migrations/202207290901.sql +31 -0
  48. package/schemas/migrations/202207290907.sql +26 -0
  49. package/schemas/migrations/202208241422.sql +21 -0
  50. package/schemas/migrations/202209141529.sql +21 -0
  51. package/schemas/migrations/202209300911.sql +35 -0
  52. package/schemas/migrations/202210111429.sql +35 -0
  53. package/schemas/migrations/202210111456.sql +57 -0
  54. package/schemas/migrations/202210171517.sql +23 -0
  55. package/schemas/migrations/202211091403.sql +26 -0
  56. package/schemas/migrations/202211091410.sql +26 -0
  57. package/schemas/migrations/202211091417.sql +31 -0
  58. package/schemas/migrations/202211161451.sql +81 -0
  59. package/schemas/migrations/202212141236.sql +37 -0
  60. package/schemas/migrations/202302201117.sql +73 -0
  61. package/schemas/migrations/202303081110.sql +78 -0
  62. package/schemas/migrations/202304191238.sql +12 -0
  63. package/schemas/migrations/202304271214.sql +7 -0
  64. package/schemas/schema.sql +57 -22
  65. package/change.txt +0 -123
  66. package/changes.md +0 -405
  67. package/famisDb.pdf +0 -0
  68. package/readme.wiki +0 -332
package/index.d.ts ADDED
@@ -0,0 +1,619 @@
1
+ export = FAMISDb;
2
+ declare class FAMISDb {
3
+ constructor(config: any, people: any);
4
+ init(config: any, people: any): void;
5
+ db: any;
6
+ people: any;
7
+ /**
8
+ *
9
+ * Extract customer account and po number
10
+ * @param {object} famis
11
+ * @param {object} replace_data
12
+ * @returns {object} account number object
13
+ * @memberof FAMISDb
14
+ */
15
+ getAccountNumber(famis: object, replace_data: object): object;
16
+ /**
17
+ *
18
+ * Process an invoice to have all necessary relationships
19
+ * @param {object} invoice - the invoice object sent by iLab
20
+ * @param {boolean} [historical=false] - if true use historical accounts too
21
+ * @returns {Promise<object>} invoice object
22
+ * @memberof FAMISDb
23
+ */
24
+ processInvoice(invoice: object, historical?: boolean): Promise<object>;
25
+ /**
26
+ *
27
+ * Get invoice by uid
28
+ * @param {string} uid
29
+ * @returns {Promise<object>} invoice object
30
+ * @memberof FAMISDb
31
+ */
32
+ getInvoiceByUid(uid: string): Promise<object>;
33
+ /**
34
+ *
35
+ * Get invoice by originating system assigned number
36
+ * @param {string} number
37
+ * @returns {Promise<object>} invoice object
38
+ * @memberof FAMISDb
39
+ */
40
+ getInvoiceByNumber(number: string): Promise<object>;
41
+ /**
42
+ *
43
+ * Get invoice by fingerprint
44
+ * @param {string} fingerPrint
45
+ * @returns {Promise<object>} invoice object
46
+ * @memberof FAMISDb
47
+ */
48
+ getInvoiceByFingerPrint(fingerPrint: string): Promise<object>;
49
+ /**
50
+ *
51
+ * Get all invoices associated with a specified account number
52
+ * @param {string} accountNumber
53
+ * @returns {Promise<array>} invoice objects
54
+ * @memberof FAMISDb
55
+ */
56
+ getInvoicesByAccount(accountNumber: string): Promise<any[]>;
57
+ /**
58
+ *
59
+ * Get all invoice ordered by and sorted by paramaters passed
60
+ * @param {string} [orderBy='date']
61
+ * @param {string} [dir='desc']
62
+ * @param {boolean} [deleted=false]
63
+ * @param {integer} [page=null]
64
+ * @param {integer} [limit=null]
65
+ * @returns {Promise<array>} invoice objects
66
+ * @memberof FAMISDb
67
+ */
68
+ getAllInvoices(orderBy?: string, dir?: string, deleted?: boolean, page?: integer, limit?: integer): Promise<any[]>;
69
+ /**
70
+ *
71
+ * Retreives invoices from the latest date
72
+ * @returns {Promise<array>} invoice objects
73
+ * @memberof FAMISDb
74
+ */
75
+ getLatestInvoices(): Promise<any[]>;
76
+ /**
77
+ *
78
+ * Returns all held invoices
79
+ * @returns {Promise<array>} held invoice objects
80
+ * @memberof FAMISDb
81
+ */
82
+ getHeldInvoices(orderBy?: string, dir?: string, page?: any, limit?: any): Promise<any[]>;
83
+ /**
84
+ *
85
+ * Returns all awaiting email invoices
86
+ * @returns {Promise<array>} awaiting email invoice objects
87
+ * @memberof FAMISDb
88
+ */
89
+ getInvoicesAwaitingEmail(): Promise<any[]>;
90
+ /**
91
+ *
92
+ * Search invoices by originating system generated invoice number
93
+ * @param {string} number
94
+ * @returns {Promise<array>} invoice objects
95
+ * @memberof FAMISDb
96
+ */
97
+ searchInvoicesByNumber(number: string): Promise<any[]>;
98
+ /**
99
+ *
100
+ * Search invoices by FAMIS invoice number
101
+ * @param {string} famis
102
+ * @returns {Promise<array>} invoice objects
103
+ * @memberof FAMISDb
104
+ */
105
+ searchInvoicesByFamis(famis: string): Promise<any[]>;
106
+ /**
107
+ *
108
+ * Adds an invoice
109
+ * @param {object} invoice
110
+ * @param {string} type
111
+ * @param {string} famisInvoiceNumber
112
+ * @returns {Promise<object>} invoice
113
+ * @memberof FAMISDb
114
+ */
115
+ addInvoice(invoice: object, type: string, famisInvoiceNumber: string): Promise<object>;
116
+ /**
117
+ *
118
+ * Updates an invoice
119
+ * @param {string} uid
120
+ * @param {object} invoice
121
+ * @returns {Promise<object>} invoice object
122
+ * @memberof FAMISDb
123
+ */
124
+ updateInvoice(uid: string, invoice: object): Promise<object>;
125
+ /**
126
+ *
127
+ * Toggles an invoice as paid
128
+ * @param {string} uid
129
+ * @param {boolean} invoiced
130
+ * @returns {Promise<object>} invoice object
131
+ * @memberof FAMISDb
132
+ */
133
+ markInvoiced(uid: string, invoiced: boolean): Promise<object>;
134
+ /**
135
+ *
136
+ * Toggles an invoice as emailed
137
+ * @param {string} uid
138
+ * @param {boolean} emailed
139
+ * @returns {Promise<object>} invoice object
140
+ * @memberof FAMISDb
141
+ */
142
+ markEmailed(uid: string, emailed: boolean): Promise<object>;
143
+ /**
144
+ *
145
+ * Sets an invoice's deletion date
146
+ * @param {string} uid
147
+ * @param {date} deleted
148
+ * @returns {Promise<object>} invoice object
149
+ * @memberof FAMISDb
150
+ */
151
+ setDeleted(uid: string, deleted: date): Promise<object>;
152
+ /**
153
+ *
154
+ * Sets an invoice's posted date
155
+ * @param {string} uid
156
+ * @param {date} postedDate
157
+ * @returns {Promise<object>} invoice object
158
+ * @memberof FAMISDb
159
+ */
160
+ setInvoicePostedDate(uid: string, postedDate: date): Promise<object>;
161
+ /**
162
+ *
163
+ * Sets an invoice's fingerprint
164
+ * @param {string} uid
165
+ * @param {string} fingerprint
166
+ * @returns {Promise<object>} invoice object
167
+ * @memberof FAMISDb
168
+ */
169
+ setInvoiceFingerPrint(uid: string, fingerprint: string): Promise<object>;
170
+ /**
171
+ *
172
+ * Get PI accounts by account number
173
+ * @param {string} number
174
+ * @param {string} campus
175
+ * @param {boolean} [historical=false]
176
+ * @returns {Promise<object>} account object
177
+ * @memberof FAMISDb
178
+ */
179
+ getByAccountNumber(number: string, campus: string, historical?: boolean): Promise<object>;
180
+ /**
181
+ *
182
+ * Search PI accounts by partial account number
183
+ * @param {string} number
184
+ * @returns {Promise<array>} account object(s)
185
+ * @memberof FAMISDb
186
+ */
187
+ searchByAccountNumber(number: string): Promise<any[]>;
188
+ /**
189
+ *
190
+ * Get PI Accounts by UIN
191
+ * @param {string} uin
192
+ * @returns {Promise<array>} account object array
193
+ * @memberof FAMISDb
194
+ */
195
+ getAccountsByUin(uin: string): Promise<any[]>;
196
+ /**
197
+ *
198
+ * Get PI accounts by responsible UIN
199
+ * @param {string} uin
200
+ * @returns {Promise<array>} account object array
201
+ * @memberof FAMISDb
202
+ */
203
+ getAccountsByResponsibleUin(uin: string): Promise<any[]>;
204
+ /**
205
+ *
206
+ * Get next FAMIS invoice number in sequence for specified invoice type
207
+ * @param {string} invoice
208
+ * @returns {Promise<string>} next invoice number in sequence
209
+ * @memberof FAMISDb
210
+ */
211
+ getNextFAMISInvoiceNumber(type: any): Promise<string>;
212
+ /**
213
+ *
214
+ * Get matching expense code for specified revenue code
215
+ * @param {string} revenue
216
+ * @returns {Promise<string>} expense code
217
+ * @memberof FAMISDb
218
+ */
219
+ getExpenseCodeByRevenue(revenue: string): Promise<string>;
220
+ /**
221
+ *
222
+ * Get revenue code object
223
+ * @param {string} revenue
224
+ * @returns {Promise<object>} revenue code object
225
+ * @memberof FAMISDb
226
+ */
227
+ getRevenueCode(revenue: string): Promise<object>;
228
+ /**
229
+ *
230
+ * Get expense code object
231
+ * @param {string} code
232
+ * @returns {Promise<object>} expense code object
233
+ * @memberof FAMISDb
234
+ */
235
+ getExpenseCode(code: string): Promise<object>;
236
+ /**
237
+ *
238
+ * Check if expense code is within the allowable range for specified account and the specified fiscal year (defaults to current)
239
+ * @param {string} account
240
+ * @param {string} code
241
+ * @param {integer} fiscal
242
+ * @returns {Promise<boolean>} truthy value
243
+ * @memberof FAMISDb
244
+ */
245
+ allowableExpenseCode(accountNumber: any, code: string, fiscal: integer): Promise<boolean>;
246
+ /**
247
+ *
248
+ * Get allowable expense code ranges for specified account
249
+ * @param {string} account
250
+ * @returns {Promise<boolean>} expense code range object(s)
251
+ * @memberof FAMISDb
252
+ */
253
+ getAllowableExpenseCodes(accountNumber: any, fiscal: any): Promise<boolean>;
254
+ /**
255
+ *
256
+ * Get core by id
257
+ * @param {string} id
258
+ * @returns {Promise<object>} core object
259
+ * @memberof FAMISDb
260
+ */
261
+ getCoreById(id: string): Promise<object>;
262
+ /**
263
+ *
264
+ * Get core by account number
265
+ * @param {string} account
266
+ * @returns {Promise<object>} core object
267
+ * @memberof FAMISDb
268
+ */
269
+ getCoreByAccount(account: string): Promise<object>;
270
+ /**
271
+ *
272
+ * Get core current revenue account number
273
+ * @param {string} coreId
274
+ * @returns {Promise<object>} core object
275
+ * @memberof FAMISDb
276
+ */
277
+ getCoreCurrentAccount(coreId: string): Promise<object>;
278
+ /**
279
+ *
280
+ * Get system part by ID
281
+ * @param {number} id
282
+ * @returns {Promise<object>} system part object
283
+ * @memberof FAMISDb
284
+ */
285
+ getSystemById(id: number): Promise<object>;
286
+ /**
287
+ *
288
+ * Get system part by two digit part number
289
+ * @param {string} number
290
+ * @returns {Promise<object>} system part object
291
+ * @memberof FAMISDb
292
+ */
293
+ getSystemByPartNumber(number: string): Promise<object>;
294
+ /**
295
+ *
296
+ * Get all enabled cores
297
+ * @param {string} date
298
+ * @returns {Promise<array>} core objects
299
+ * @memberof FAMISDb
300
+ */
301
+ getEnabledCores(date: string): Promise<any[]>;
302
+ /**
303
+ *
304
+ * Get all cores
305
+ * @returns {Promise<array>} core objects
306
+ * @memberof FAMISDb
307
+ */
308
+ getAllCores(): Promise<any[]>;
309
+ /**
310
+ *
311
+ * Get a core's users by core ID
312
+ * @param {number} coreId
313
+ * @returns {Promise<array>} user objects
314
+ * @memberof FAMISDb
315
+ */
316
+ getCoreUsers(coreId: number): Promise<any[]>;
317
+ /**
318
+ *
319
+ * Get a user's cores they manage
320
+ * @param {string} userId
321
+ * @returns {Promise<array>} core objects
322
+ * @memberof FAMISDb
323
+ */
324
+ getUserCores(userId: string): Promise<any[]>;
325
+ /**
326
+ *
327
+ * Get a system part's users by system ID
328
+ * @param {number} systemId
329
+ * @returns {Promise<array>} user objects
330
+ * @memberof FAMISDb
331
+ */
332
+ getSystemUsers(systemId: number): Promise<any[]>;
333
+ /**
334
+ *
335
+ * Get a user's system parts they manage
336
+ * @param {*} userId
337
+ * @returns {Promise<object>} system objects
338
+ * @memberof FAMISDb
339
+ */
340
+ getUserSystemParts(userId: any): Promise<object>;
341
+ /**
342
+ *
343
+ * Get all system parts
344
+ * @returns {Promise<object>} system objects
345
+ * @memberof FAMISDb
346
+ */
347
+ getAllSystemParts(): Promise<object>;
348
+ /**
349
+ *
350
+ * Get all admin users
351
+ * @returns {Promise<array>} array of user objects
352
+ * @memberof FAMISDb
353
+ */
354
+ getAdminUsers(): Promise<any[]>;
355
+ /**
356
+ *
357
+ * Get user
358
+ * @param {string} userId
359
+ * @returns {Promise<object>} user object
360
+ * @memberof FAMISDb
361
+ */
362
+ getUser(userId: string): Promise<object>;
363
+ /**
364
+ *
365
+ * Update user
366
+ * @param {object} user
367
+ * @returns {Promise<object>} user object
368
+ * @memberof FAMISDb
369
+ */
370
+ updateUser(user: object): Promise<object>;
371
+ /**
372
+ *
373
+ * Get customer by customer account number
374
+ * @param {string} accountNumber
375
+ * @param {string} campusCode
376
+ * @returns {Promise<object>} customer account object
377
+ * @memberof FAMISDb
378
+ */
379
+ getCustomerNumber(accountNumber: string, campusCode: string): Promise<object>;
380
+ /**
381
+ *
382
+ * Get current fiscal year
383
+ * @returns {<integer>} fiscal year
384
+ * @memberof FAMISDb
385
+ */
386
+ getCurrentFiscalYear(): <integer>() => any;
387
+ /**
388
+ *
389
+ * Return fingerprint of invoice
390
+ * @param {object} invoice json object
391
+ * @returns {<string>} fingerprint
392
+ * @memberof FAMISDb
393
+ */
394
+ getInvoiceFingerPrint(invoice: object): <string>() => any;
395
+ /**
396
+ *
397
+ * Return formatted account number
398
+ * @param {string} accountNumber unformatted 13 digit famis account number
399
+ * @returns {<string>} formatted 13 digits famis account number
400
+ * @memberof FAMISDb
401
+ */
402
+ formatAccountNumber(accountNumber: string): <string_1>() => any;
403
+ /**
404
+ * @typedef {Object} HighRisk
405
+ * @property {boolean} isHighRisk - indicates if invoice triggers SRS high risk policy
406
+ * @property {object} flaggedTransactions - object of transactions that flag
407
+ */
408
+ /**
409
+ *
410
+ * Is invoice flagged by SRS high risk policies
411
+ * @param {object} invoice json object
412
+ * @returns {Promise<HighRisk>} high risk object
413
+ * @memberof FAMISDb
414
+ */
415
+ isSrsHighRisk(invoice: object): Promise<{
416
+ /**
417
+ * - indicates if invoice triggers SRS high risk policy
418
+ */
419
+ isHighRisk: boolean;
420
+ /**
421
+ * - object of transactions that flag
422
+ */
423
+ flaggedTransactions: object;
424
+ }>;
425
+ /**
426
+ * @typedef {Object} Comment
427
+ * @property {integer} id - db generated id
428
+ * @property {string} uid - uid
429
+ * @property {string} invoice_id - invoice id
430
+ * @property {string} user_id - user uid
431
+ * @property {string} comment - text of comment
432
+ * @property {string} type - type of comment
433
+ * @property {date} created - created date
434
+ * @property {date} deleted - deleted date
435
+ */
436
+ /**
437
+ *
438
+ * Create/update invoice comment
439
+ * @param {Comment} comment json object
440
+ * @returns {Promise<Comment>} comment object
441
+ * @memberof FAMISDb
442
+ */
443
+ saveComment(comment: {
444
+ /**
445
+ * - db generated id
446
+ */
447
+ id: integer;
448
+ /**
449
+ * - uid
450
+ */
451
+ uid: string;
452
+ /**
453
+ * - invoice id
454
+ */
455
+ invoice_id: string;
456
+ /**
457
+ * - user uid
458
+ */
459
+ user_id: string;
460
+ /**
461
+ * - text of comment
462
+ */
463
+ comment: string;
464
+ /**
465
+ * - type of comment
466
+ */
467
+ type: string;
468
+ /**
469
+ * - created date
470
+ */
471
+ created: date;
472
+ /**
473
+ * - deleted date
474
+ */
475
+ deleted: date;
476
+ }): Promise<{
477
+ /**
478
+ * - db generated id
479
+ */
480
+ id: integer;
481
+ /**
482
+ * - uid
483
+ */
484
+ uid: string;
485
+ /**
486
+ * - invoice id
487
+ */
488
+ invoice_id: string;
489
+ /**
490
+ * - user uid
491
+ */
492
+ user_id: string;
493
+ /**
494
+ * - text of comment
495
+ */
496
+ comment: string;
497
+ /**
498
+ * - type of comment
499
+ */
500
+ type: string;
501
+ /**
502
+ * - created date
503
+ */
504
+ created: date;
505
+ /**
506
+ * - deleted date
507
+ */
508
+ deleted: date;
509
+ }>;
510
+ /**
511
+ *
512
+ * Get invoice comments
513
+ * @param {string} invoiceUid invoice uid
514
+ * @returns {Promise(<Comment[]>} array of comment objects
515
+ * @memberof FAMISDb
516
+ */
517
+ getInvoiceComments(invoiceUid: string): Promise<any>;
518
+ /**
519
+ * @typedef {Object} CommentFile
520
+ * @property {integer} id - db generated id
521
+ * @property {string} uid - uid
522
+ * @property {string} invoice_id - invoice uid
523
+ * @property {string} comment_id - comment uid
524
+ * @property {string} original_filename - original file name
525
+ * @property {string} filename - generate unique filename on filesystem
526
+ * @property {date} created - created date
527
+ * @property {date} deleted - deleted date
528
+ */
529
+ /**
530
+ *
531
+ * Create/update invoice comment file
532
+ * @param {CommentFile} commentFile json object
533
+ * @returns {Promise<CommentFile>} comment object
534
+ * @memberof FAMISDb
535
+ */
536
+ saveCommentFile(commentFile: {
537
+ /**
538
+ * - db generated id
539
+ */
540
+ id: integer;
541
+ /**
542
+ * - uid
543
+ */
544
+ uid: string;
545
+ /**
546
+ * - invoice uid
547
+ */
548
+ invoice_id: string;
549
+ /**
550
+ * - comment uid
551
+ */
552
+ comment_id: string;
553
+ /**
554
+ * - original file name
555
+ */
556
+ original_filename: string;
557
+ /**
558
+ * - generate unique filename on filesystem
559
+ */
560
+ filename: string;
561
+ /**
562
+ * - created date
563
+ */
564
+ created: date;
565
+ /**
566
+ * - deleted date
567
+ */
568
+ deleted: date;
569
+ }): Promise<{
570
+ /**
571
+ * - db generated id
572
+ */
573
+ id: integer;
574
+ /**
575
+ * - uid
576
+ */
577
+ uid: string;
578
+ /**
579
+ * - invoice uid
580
+ */
581
+ invoice_id: string;
582
+ /**
583
+ * - comment uid
584
+ */
585
+ comment_id: string;
586
+ /**
587
+ * - original file name
588
+ */
589
+ original_filename: string;
590
+ /**
591
+ * - generate unique filename on filesystem
592
+ */
593
+ filename: string;
594
+ /**
595
+ * - created date
596
+ */
597
+ created: date;
598
+ /**
599
+ * - deleted date
600
+ */
601
+ deleted: date;
602
+ }>;
603
+ /**
604
+ *
605
+ * Get invoice comment files
606
+ * @param {string} commentUid comment uid
607
+ * @returns {Promise(<CommentFile[]>} array of comment file objects
608
+ * @memberof FAMISDb
609
+ */
610
+ getCommentFiles(commentUid: string): Promise<any>;
611
+ /**
612
+ *
613
+ * Get invoice comment file
614
+ * @param {string} fileUid file uid
615
+ * @returns {Promise(<CommentFile>} array of comment file objects
616
+ * @memberof FAMISDb
617
+ */
618
+ getCommentFile(fileUid: string): Promise<any>;
619
+ }
package/index.js CHANGED
@@ -37,7 +37,13 @@ const pad = (str, max, right) => {
37
37
  return retVal;
38
38
  };
39
39
 
40
- const sanitizeAccountNumber = (account) => pad(account.replace(/\D/g,''), 13, true);
40
+ const sanitizeAccountNumber = (account) => {
41
+ if (account.substring(0,2) === 'RC') {
42
+ return account.replace(/\W/g, '');
43
+ } else {
44
+ return pad(account.replace(/\D/g,''), 13, true);
45
+ }
46
+ };
41
47
 
42
48
  const getCoreAccountNumber = (famis) => {
43
49
  const { sellingCampusCode, sellingAccountNumber, sellingSupportAccount } = famis;
@@ -1159,6 +1165,7 @@ class FAMISDb {
1159
1165
  'cores.id',
1160
1166
  'core_accounts.account',
1161
1167
  'core_accounts.effective',
1168
+ 'core_accounts.active',
1162
1169
  'cores.facility',
1163
1170
  'cores.contact',
1164
1171
  'cores.contactEmail',
@@ -1420,6 +1427,53 @@ class FAMISDb {
1420
1427
  return retVal;
1421
1428
  }
1422
1429
 
1430
+ /**
1431
+ *
1432
+ * Get all active accounts
1433
+ * @returns {Promise<array>} core objects
1434
+ * @memberof FAMISDb
1435
+ */
1436
+ async getActiveAccounts() {
1437
+ let records;
1438
+ let retVal = [];
1439
+ try {
1440
+ const accounts = this.db('core_accounts')
1441
+ .select(
1442
+ 'core_accounts.coreId',
1443
+ 'core_accounts.account',
1444
+ 'core_accounts.effective',
1445
+ )
1446
+ .where({active: true})
1447
+ .as("core_accounts");
1448
+ records = await this.db('cores')
1449
+ .select(
1450
+ 'cores.id',
1451
+ 'core_accounts.account',
1452
+ 'core_accounts.active',
1453
+ 'cores.facility',
1454
+ 'cores.contact',
1455
+ 'cores.contactEmail',
1456
+ 'cores.systemId',
1457
+ 'cores.enabled',
1458
+ 'cores.deleted',
1459
+ 'cores.coreEmail',
1460
+ 'cores.corePhone',
1461
+ 'cores.coreAddress',
1462
+ 'cores.from_email',
1463
+ 'cores.invoice_email'
1464
+ )
1465
+ .join(accounts, 'cores.id', '=', 'core_accounts.coreId')
1466
+ .where('enabled', '1')
1467
+ .orderBy('cores.id', 'desc');
1468
+ if (records.length) {
1469
+ retVal = records;
1470
+ }
1471
+ } catch (e) {
1472
+ throw e;
1473
+ }
1474
+ return retVal;
1475
+ }
1476
+
1423
1477
  /**
1424
1478
  *
1425
1479
  * Get a system part's users by system ID
@@ -1859,4 +1913,4 @@ class FAMISDb {
1859
1913
  }
1860
1914
  }
1861
1915
 
1862
- module.exports = FAMISDb;
1916
+ module.exports = FAMISDb;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamu-dor/famis-db",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "DB library for FAMIS database",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -19,7 +19,7 @@
19
19
  "@paralleldrive/cuid2": "^2.2.2",
20
20
  "awaity": "^1.0.0",
21
21
  "knex": "^3.1.0",
22
- "pg": "^8.11.3",
22
+ "pg": "^8.12.0",
23
23
  "rev-hash": "^3.0.0"
24
24
  }
25
- }
25
+ }