@tamu-dor/famis-db 3.0.3 → 3.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.
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
@@ -721,10 +723,11 @@ declare class FAMISDb {
721
723
  *
722
724
  * Get system part by ID
723
725
  * @param {number} id
726
+ * @param {string[]} excludeFields - fields to exclude from results
724
727
  * @returns {Promise<SystemPart>} system part object
725
728
  * @memberof FAMISDb
726
729
  */
727
- getSystemById(id: number): Promise<SystemPart>;
730
+ getSystemById(id: number, excludeFields?: string[]): Promise<SystemPart>;
728
731
  /**
729
732
  *
730
733
  * 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
@@ -721,10 +723,11 @@ declare class FAMISDb {
721
723
  *
722
724
  * Get system part by ID
723
725
  * @param {number} id
726
+ * @param {string[]} excludeFields - fields to exclude from results
724
727
  * @returns {Promise<SystemPart>} system part object
725
728
  * @memberof FAMISDb
726
729
  */
727
- getSystemById(id: number): Promise<SystemPart>;
730
+ getSystemById(id: number, excludeFields?: string[]): Promise<SystemPart>;
728
731
  /**
729
732
  *
730
733
  * 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
262
  invoice.core = await this.getCoreByAccount(account);
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
  );
@@ -1749,14 +1760,24 @@ class FAMISDb {
1749
1760
  *
1750
1761
  * Get system part by ID
1751
1762
  * @param {number} id
1763
+ * @param {string[]} excludeFields - fields to exclude from results
1752
1764
  * @returns {Promise<SystemPart>} system part object
1753
1765
  * @memberof FAMISDb
1754
1766
  */
1755
- async getSystemById(id) {
1767
+ async getSystemById(id, excludeFields = []) {
1756
1768
  let records;
1757
1769
  let retVal;
1770
+ const fields = systemPartFields.map((f) => `system.${f}`);
1771
+ if (excludeFields.length) {
1772
+ excludeFields.forEach((f) => {
1773
+ const idx = fields.findIndex((field) => field.includes(f));
1774
+ if (idx > -1) {
1775
+ fields.splice(idx, 1);
1776
+ }
1777
+ });
1778
+ }
1758
1779
  try {
1759
- records = await this.db("system").where("id", id).orderBy("id", "desc");
1780
+ records = await this.db("system").select(fields).where("id", id).orderBy("id", "desc");
1760
1781
  if (records.length) {
1761
1782
  retVal = records[0];
1762
1783
  }