@tamu-dor/famis-db 3.0.3 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -313,10 +313,11 @@ declare class FAMISDb {
313
313
  * Process an invoice to have all necessary relationships
314
314
  * @param {object} invoice - the invoice object sent by iLab
315
315
  * @param {boolean} [historical=false] - if true use historical accounts too
316
+ * @param {string[]} excludeFields - fields to exclude from results
316
317
  * @returns {Promise<object>} invoice object
317
318
  * @memberof FAMISDb
318
319
  */
319
- processInvoice(invoice: any, historical?: boolean): Promise<any>;
320
+ processInvoice(invoice: any, historical?: boolean, excludeFields?: string[]): Promise<any>;
320
321
  /**
321
322
  *
322
323
  * Get invoice by uid
@@ -461,10 +462,11 @@ declare class FAMISDb {
461
462
  * @param {string} [sortDirection='desc']
462
463
  * @param {integer} page - page of results to return
463
464
  * @param {integer} perPage - number of results per page to return
465
+ * @param {string[]} excludeFields - fields to exclude from results
464
466
  * @returns {Promise<InvoicePayload>} invoice objects
465
467
  * @memberof FAMISDb
466
468
  */
467
- queryInvoices(query: string, sortColumn?: string, sortDirection?: SortDirection | string, page?: number, perPage?: number): Promise<InvoicePayload>;
469
+ queryInvoices(query: string, sortColumn?: string, sortDirection?: SortDirection | string, page?: number, perPage?: number, excludeFields?: string[]): Promise<InvoicePayload>;
468
470
  /**
469
471
  *
470
472
  * Adds an invoice
@@ -657,10 +659,11 @@ declare class FAMISDb {
657
659
  * @param {string} type
658
660
  * @param {string} operator
659
661
  * @param {string} search
662
+ * @param {string[]} excludeFields - fields to exclude from results
660
663
  * @returns {Promise<Core>} core object
661
664
  * @memberof FAMISDb
662
665
  */
663
- getCore(type: string, operator: string | undefined, search: string): Promise<Core>;
666
+ getCore(type: string, operator: string | undefined, search: string, excludeFields?: string[]): Promise<Core>;
664
667
  /**
665
668
  *
666
669
  * Get core by id
@@ -674,9 +677,10 @@ declare class FAMISDb {
674
677
  * Get core by account number
675
678
  * @param {string} account
676
679
  * @returns {Promise<Core>} core object
680
+ * @param {string[]} excludeFields - fields to exclude from results
677
681
  * @memberof FAMISDb
678
682
  */
679
- getCoreByAccount(account: string): Promise<Core>;
683
+ getCoreByAccount(account: string, excludeFields?: string[]): Promise<Core>;
680
684
  /**
681
685
  *
682
686
  * Update core
@@ -721,10 +725,11 @@ declare class FAMISDb {
721
725
  *
722
726
  * Get system part by ID
723
727
  * @param {number} id
728
+ * @param {string[]} excludeFields - fields to exclude from results
724
729
  * @returns {Promise<SystemPart>} system part object
725
730
  * @memberof FAMISDb
726
731
  */
727
- getSystemById(id: number): Promise<SystemPart>;
732
+ getSystemById(id: number, excludeFields?: string[]): Promise<SystemPart>;
728
733
  /**
729
734
  *
730
735
  * Get system part by two-digit part number
package/dist/index.d.ts CHANGED
@@ -313,10 +313,11 @@ declare class FAMISDb {
313
313
  * Process an invoice to have all necessary relationships
314
314
  * @param {object} invoice - the invoice object sent by iLab
315
315
  * @param {boolean} [historical=false] - if true use historical accounts too
316
+ * @param {string[]} excludeFields - fields to exclude from results
316
317
  * @returns {Promise<object>} invoice object
317
318
  * @memberof FAMISDb
318
319
  */
319
- processInvoice(invoice: any, historical?: boolean): Promise<any>;
320
+ processInvoice(invoice: any, historical?: boolean, excludeFields?: string[]): Promise<any>;
320
321
  /**
321
322
  *
322
323
  * Get invoice by uid
@@ -461,10 +462,11 @@ declare class FAMISDb {
461
462
  * @param {string} [sortDirection='desc']
462
463
  * @param {integer} page - page of results to return
463
464
  * @param {integer} perPage - number of results per page to return
465
+ * @param {string[]} excludeFields - fields to exclude from results
464
466
  * @returns {Promise<InvoicePayload>} invoice objects
465
467
  * @memberof FAMISDb
466
468
  */
467
- queryInvoices(query: string, sortColumn?: string, sortDirection?: SortDirection | string, page?: number, perPage?: number): Promise<InvoicePayload>;
469
+ queryInvoices(query: string, sortColumn?: string, sortDirection?: SortDirection | string, page?: number, perPage?: number, excludeFields?: string[]): Promise<InvoicePayload>;
468
470
  /**
469
471
  *
470
472
  * Adds an invoice
@@ -657,10 +659,11 @@ declare class FAMISDb {
657
659
  * @param {string} type
658
660
  * @param {string} operator
659
661
  * @param {string} search
662
+ * @param {string[]} excludeFields - fields to exclude from results
660
663
  * @returns {Promise<Core>} core object
661
664
  * @memberof FAMISDb
662
665
  */
663
- getCore(type: string, operator: string | undefined, search: string): Promise<Core>;
666
+ getCore(type: string, operator: string | undefined, search: string, excludeFields?: string[]): Promise<Core>;
664
667
  /**
665
668
  *
666
669
  * Get core by id
@@ -674,9 +677,10 @@ declare class FAMISDb {
674
677
  * Get core by account number
675
678
  * @param {string} account
676
679
  * @returns {Promise<Core>} core object
680
+ * @param {string[]} excludeFields - fields to exclude from results
677
681
  * @memberof FAMISDb
678
682
  */
679
- getCoreByAccount(account: string): Promise<Core>;
683
+ getCoreByAccount(account: string, excludeFields?: string[]): Promise<Core>;
680
684
  /**
681
685
  *
682
686
  * Update core
@@ -721,10 +725,11 @@ declare class FAMISDb {
721
725
  *
722
726
  * Get system part by ID
723
727
  * @param {number} id
728
+ * @param {string[]} excludeFields - fields to exclude from results
724
729
  * @returns {Promise<SystemPart>} system part object
725
730
  * @memberof FAMISDb
726
731
  */
727
- getSystemById(id: number): Promise<SystemPart>;
732
+ getSystemById(id: number, excludeFields?: string[]): Promise<SystemPart>;
728
733
  /**
729
734
  *
730
735
  * Get system part by two-digit part number
package/dist/main.cjs CHANGED
@@ -252,16 +252,18 @@ class FAMISDb {
252
252
  * Process an invoice to have all necessary relationships
253
253
  * @param {object} invoice - the invoice object sent by iLab
254
254
  * @param {boolean} [historical=false] - if true use historical accounts too
255
+ * @param {string[]} excludeFields - fields to exclude from results
255
256
  * @returns {Promise<object>} invoice object
256
257
  * @memberof FAMISDb
257
258
  */
258
- async processInvoice(invoice, historical = false) {
259
+ async processInvoice(invoice, historical = false, excludeFields = []) {
259
260
  try {
260
261
  const account = getCoreAccountNumber(invoice.data.details[0].famis);
261
- invoice.core = await this.getCoreByAccount(account);
262
+ invoice.core = await this.getCoreByAccount(account, excludeFields);
262
263
  if (invoice.core) {
263
264
  invoice.core.systemPart = await this.getSystemById(
264
- invoice.core.systemId
265
+ invoice.core.systemId,
266
+ excludeFields
265
267
  );
266
268
  } else {
267
269
  const e = Error(
@@ -632,10 +634,11 @@ class FAMISDb {
632
634
  * @param {string} [sortDirection='desc']
633
635
  * @param {integer} page - page of results to return
634
636
  * @param {integer} perPage - number of results per page to return
637
+ * @param {string[]} excludeFields - fields to exclude from results
635
638
  * @returns {Promise<InvoicePayload>} invoice objects
636
639
  * @memberof FAMISDb
637
640
  */
638
- async queryInvoices(query, sortColumn = "date", sortDirection = "desc", page = 1, perPage = 50) {
641
+ async queryInvoices(query, sortColumn = "date", sortDirection = "desc", page = 1, perPage = 50, excludeFields = []) {
639
642
  const self = this;
640
643
  let rows;
641
644
  const invFields = invoiceFields.map((f) => `invoices.${f}`);
@@ -662,6 +665,14 @@ class FAMISDb {
662
665
  ...revenueAccountDeptFields,
663
666
  ...expenseAccountBalFields
664
667
  ];
668
+ if (excludeFields.length) {
669
+ excludeFields.forEach((f) => {
670
+ const idx = fields.findIndex((field) => field.includes(f));
671
+ if (idx > -1) {
672
+ fields.splice(idx, 1);
673
+ }
674
+ });
675
+ }
665
676
  try {
666
677
  rows = await this.db.from("invoices").leftJoin(
667
678
  "accounts as expenseAccount",
@@ -713,7 +724,7 @@ class FAMISDb {
713
724
  ).where(this.db.raw(query)).whereNull("revenueAccountDepartment.sub").orderBy(sortColumn, sortDirection).select(fields).paginate({ perPage, currentPage: page, isLengthAware: true });
714
725
  rows.data = await Promise.all(
715
726
  rows.data.map(async (row) => {
716
- const rec = await self.processInvoice(row);
727
+ const rec = await self.processInvoice(row, false, excludeFields);
717
728
  return rec;
718
729
  })
719
730
  );
@@ -1485,10 +1496,11 @@ class FAMISDb {
1485
1496
  * @param {string} type
1486
1497
  * @param {string} operator
1487
1498
  * @param {string} search
1499
+ * @param {string[]} excludeFields - fields to exclude from results
1488
1500
  * @returns {Promise<Core>} core object
1489
1501
  * @memberof FAMISDb
1490
1502
  */
1491
- async getCore(type, operator = "=", search) {
1503
+ async getCore(type, operator = "=", search, excludeFields = []) {
1492
1504
  let records;
1493
1505
  let retVal;
1494
1506
  try {
@@ -1505,6 +1517,14 @@ class FAMISDb {
1505
1517
  ...expenseAccountBalFields,
1506
1518
  */
1507
1519
  ];
1520
+ if (excludeFields.length) {
1521
+ excludeFields.forEach((f) => {
1522
+ const idx = fields.findIndex((field) => field.includes(f));
1523
+ if (idx > -1) {
1524
+ fields.splice(idx, 1);
1525
+ }
1526
+ });
1527
+ }
1508
1528
  records = await this.db.with("coreaccounts", (qb) => {
1509
1529
  qb.select(
1510
1530
  "accounts.*",
@@ -1608,15 +1628,17 @@ class FAMISDb {
1608
1628
  * Get core by account number
1609
1629
  * @param {string} account
1610
1630
  * @returns {Promise<Core>} core object
1631
+ * @param {string[]} excludeFields - fields to exclude from results
1611
1632
  * @memberof FAMISDb
1612
1633
  */
1613
- async getCoreByAccount(account) {
1634
+ async getCoreByAccount(account, excludeFields) {
1614
1635
  let retVal;
1615
1636
  try {
1616
1637
  retVal = await this.getCore(
1617
1638
  "core_accounts.accounts",
1618
1639
  "@>",
1619
- `[{"account_number": "${account}"}]`
1640
+ `[{"account_number": "${account}"}]`,
1641
+ excludeFields
1620
1642
  );
1621
1643
  } catch (e) {
1622
1644
  throw e;
@@ -1749,14 +1771,24 @@ class FAMISDb {
1749
1771
  *
1750
1772
  * Get system part by ID
1751
1773
  * @param {number} id
1774
+ * @param {string[]} excludeFields - fields to exclude from results
1752
1775
  * @returns {Promise<SystemPart>} system part object
1753
1776
  * @memberof FAMISDb
1754
1777
  */
1755
- async getSystemById(id) {
1778
+ async getSystemById(id, excludeFields = []) {
1756
1779
  let records;
1757
1780
  let retVal;
1781
+ const fields = systemPartFields.map((f) => `system.${f}`);
1782
+ if (excludeFields.length) {
1783
+ excludeFields.forEach((f) => {
1784
+ const idx = fields.findIndex((field) => field.includes(f));
1785
+ if (idx > -1) {
1786
+ fields.splice(idx, 1);
1787
+ }
1788
+ });
1789
+ }
1758
1790
  try {
1759
- records = await this.db("system").where("id", id).orderBy("id", "desc");
1791
+ records = await this.db("system").select(fields).where("id", id).orderBy("id", "desc");
1760
1792
  if (records.length) {
1761
1793
  retVal = records[0];
1762
1794
  }