@tamu-dor/famis-db 3.0.2 → 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/main.js CHANGED
@@ -250,16 +250,18 @@ class FAMISDb {
250
250
  * Process an invoice to have all necessary relationships
251
251
  * @param {object} invoice - the invoice object sent by iLab
252
252
  * @param {boolean} [historical=false] - if true use historical accounts too
253
+ * @param {string[]} excludeFields - fields to exclude from results
253
254
  * @returns {Promise<object>} invoice object
254
255
  * @memberof FAMISDb
255
256
  */
256
- async processInvoice(invoice, historical = false) {
257
+ async processInvoice(invoice, historical = false, excludeFields = []) {
257
258
  try {
258
259
  const account = getCoreAccountNumber(invoice.data.details[0].famis);
259
260
  invoice.core = await this.getCoreByAccount(account);
260
261
  if (invoice.core) {
261
262
  invoice.core.systemPart = await this.getSystemById(
262
- invoice.core.systemId
263
+ invoice.core.systemId,
264
+ excludeFields
263
265
  );
264
266
  } else {
265
267
  const e = Error(
@@ -630,10 +632,11 @@ class FAMISDb {
630
632
  * @param {string} [sortDirection='desc']
631
633
  * @param {integer} page - page of results to return
632
634
  * @param {integer} perPage - number of results per page to return
635
+ * @param {string[]} excludeFields - fields to exclude from results
633
636
  * @returns {Promise<InvoicePayload>} invoice objects
634
637
  * @memberof FAMISDb
635
638
  */
636
- async queryInvoices(query, sortColumn = "date", sortDirection = "desc", page = 1, perPage = 50) {
639
+ async queryInvoices(query, sortColumn = "date", sortDirection = "desc", page = 1, perPage = 50, excludeFields = []) {
637
640
  const self = this;
638
641
  let rows;
639
642
  const invFields = invoiceFields.map((f) => `invoices.${f}`);
@@ -660,6 +663,14 @@ class FAMISDb {
660
663
  ...revenueAccountDeptFields,
661
664
  ...expenseAccountBalFields
662
665
  ];
666
+ if (excludeFields.length) {
667
+ excludeFields.forEach((f) => {
668
+ const idx = fields.findIndex((field) => field.includes(f));
669
+ if (idx > -1) {
670
+ fields.splice(idx, 1);
671
+ }
672
+ });
673
+ }
663
674
  try {
664
675
  rows = await this.db.from("invoices").leftJoin(
665
676
  "accounts as expenseAccount",
@@ -711,7 +722,7 @@ class FAMISDb {
711
722
  ).where(this.db.raw(query)).whereNull("revenueAccountDepartment.sub").orderBy(sortColumn, sortDirection).select(fields).paginate({ perPage, currentPage: page, isLengthAware: true });
712
723
  rows.data = await Promise.all(
713
724
  rows.data.map(async (row) => {
714
- const rec = await self.processInvoice(row);
725
+ const rec = await self.processInvoice(row, false, excludeFields);
715
726
  return rec;
716
727
  })
717
728
  );
@@ -1747,14 +1758,24 @@ class FAMISDb {
1747
1758
  *
1748
1759
  * Get system part by ID
1749
1760
  * @param {number} id
1761
+ * @param {string[]} excludeFields - fields to exclude from results
1750
1762
  * @returns {Promise<SystemPart>} system part object
1751
1763
  * @memberof FAMISDb
1752
1764
  */
1753
- async getSystemById(id) {
1765
+ async getSystemById(id, excludeFields = []) {
1754
1766
  let records;
1755
1767
  let retVal;
1768
+ const fields = systemPartFields.map((f) => `system.${f}`);
1769
+ if (excludeFields.length) {
1770
+ excludeFields.forEach((f) => {
1771
+ const idx = fields.findIndex((field) => field.includes(f));
1772
+ if (idx > -1) {
1773
+ fields.splice(idx, 1);
1774
+ }
1775
+ });
1776
+ }
1756
1777
  try {
1757
- records = await this.db("system").where("id", id).orderBy("id", "desc");
1778
+ records = await this.db("system").select(fields).where("id", id).orderBy("id", "desc");
1758
1779
  if (records.length) {
1759
1780
  retVal = records[0];
1760
1781
  }