@tamu-dor/famis-db 3.0.0-beta.2 → 3.0.0-beta.3

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
@@ -67,16 +67,16 @@ export declare interface Contact {
67
67
  }
68
68
 
69
69
  export declare interface Core {
70
- id: number;
70
+ id?: number;
71
71
  account?: string;
72
72
  effective?: string;
73
- facility: string;
73
+ facility?: string;
74
74
  contact: string;
75
75
  contactEmail: string;
76
76
  systemId: number;
77
77
  enabled: boolean;
78
78
  deleted: string | null;
79
- coreEmail: string;
79
+ coreEmail?: string | null;
80
80
  corePhone: string | null;
81
81
  coreAddress: string | null;
82
82
  from_email: string | null;
@@ -91,7 +91,7 @@ export declare interface Core {
91
91
 
92
92
  export declare interface CoreAccount {
93
93
  id?: number;
94
- account: string;
94
+ account?: string;
95
95
  coreId: number;
96
96
  coreAccountId?: number;
97
97
  coreAccountActive?: boolean | null;
@@ -100,9 +100,9 @@ export declare interface CoreAccount {
100
100
  }
101
101
 
102
102
  export declare interface CoreAccountEmail {
103
- uid: string;
104
- core_id: number;
105
- account_number: string;
103
+ uid?: string;
104
+ core_id?: number;
105
+ account_number?: string;
106
106
  email: string;
107
107
  created?: Date | null;
108
108
  deleted?: Date | null;
@@ -115,7 +115,7 @@ export declare interface CorePayload {
115
115
 
116
116
  export declare interface CoreUser {
117
117
  id?: number;
118
- userId: string;
118
+ userId?: string;
119
119
  coreId: number;
120
120
  coreUserId?: number;
121
121
  email?: boolean | null;
@@ -282,7 +282,14 @@ declare class FAMISDb {
282
282
  private db;
283
283
  private people;
284
284
  constructor(config: any, people: any);
285
- init(config: any, people: any): void;
285
+ /**
286
+ * Initializes the database connection and sets up the Knex instance for interacting with PostgreSQL database.
287
+ *
288
+ * @param {any} config - The configuration object that includes details about how to connect to a PostgreSQL database. This should include properties such as `host`, `user`, `password`, etc.
289
+ * @param {any} people - The data related to the 'people' entity. It could be an array of person objects or any other format depending on your application requirements.
290
+ * @param {boolean} debug - A flag indicating whether to enable debugging for Knex queries. Defaults to `false`. If set to `true`, it will log all SQL queries that are executed against the database in the console.
291
+ */
292
+ init(config: any, people?: any, debug?: boolean): void;
286
293
  /**
287
294
  *
288
295
  * Extract customer account and po number
@@ -918,6 +925,13 @@ declare class FAMISDb {
918
925
  * @property {date} created - created date
919
926
  * @property {date} deleted - deleted date
920
927
  */
928
+ /**
929
+ * Create an invoice comment file.
930
+ * @param {InvoiceCommentFile} file - JSON object representing the comment file
931
+ * @returns {Promise<InvoiceCommentFile>} - Promise that resolves to the comment file object
932
+ * @memberof FAMISDb
933
+ */
934
+ saveCommentFile(file: InvoiceCommentFile): Promise<InvoiceCommentFile | null>;
921
935
  /**
922
936
  * Get invoice comment files.
923
937
  * @param {string} commentUid - Comment UID
@@ -1046,9 +1060,9 @@ declare class FAMISDb {
1046
1060
 
1047
1061
  export declare interface InvoiceComment {
1048
1062
  id?: number;
1049
- uid: string;
1063
+ uid?: string;
1050
1064
  invoice_id: string;
1051
- user_id: string;
1065
+ user_id?: string | null;
1052
1066
  comment: string | null;
1053
1067
  type: string | null;
1054
1068
  created: string | null;
@@ -1056,7 +1070,7 @@ declare class FAMISDb {
1056
1070
  }
1057
1071
 
1058
1072
  export declare type InvoiceCommentFile = {
1059
- id: number;
1073
+ id?: number;
1060
1074
  uid: string;
1061
1075
  invoice_id: string;
1062
1076
  comment_id: string;
@@ -1126,9 +1140,9 @@ declare class FAMISDb {
1126
1140
  fein: string;
1127
1141
  agency: string;
1128
1142
  checkAddress: string;
1129
- credit: boolean;
1130
- creditUrl: string;
1131
- creditFee: string;
1143
+ credit?: boolean | null;
1144
+ creditUrl?: string | null;
1145
+ creditFee?: string | null;
1132
1146
  part: string;
1133
1147
  abbrev: string;
1134
1148
  aggiebuy: string;
package/dist/index.d.ts CHANGED
@@ -67,16 +67,16 @@ export declare interface Contact {
67
67
  }
68
68
 
69
69
  export declare interface Core {
70
- id: number;
70
+ id?: number;
71
71
  account?: string;
72
72
  effective?: string;
73
- facility: string;
73
+ facility?: string;
74
74
  contact: string;
75
75
  contactEmail: string;
76
76
  systemId: number;
77
77
  enabled: boolean;
78
78
  deleted: string | null;
79
- coreEmail: string;
79
+ coreEmail?: string | null;
80
80
  corePhone: string | null;
81
81
  coreAddress: string | null;
82
82
  from_email: string | null;
@@ -91,7 +91,7 @@ export declare interface Core {
91
91
 
92
92
  export declare interface CoreAccount {
93
93
  id?: number;
94
- account: string;
94
+ account?: string;
95
95
  coreId: number;
96
96
  coreAccountId?: number;
97
97
  coreAccountActive?: boolean | null;
@@ -100,9 +100,9 @@ export declare interface CoreAccount {
100
100
  }
101
101
 
102
102
  export declare interface CoreAccountEmail {
103
- uid: string;
104
- core_id: number;
105
- account_number: string;
103
+ uid?: string;
104
+ core_id?: number;
105
+ account_number?: string;
106
106
  email: string;
107
107
  created?: Date | null;
108
108
  deleted?: Date | null;
@@ -115,7 +115,7 @@ export declare interface CorePayload {
115
115
 
116
116
  export declare interface CoreUser {
117
117
  id?: number;
118
- userId: string;
118
+ userId?: string;
119
119
  coreId: number;
120
120
  coreUserId?: number;
121
121
  email?: boolean | null;
@@ -282,7 +282,14 @@ declare class FAMISDb {
282
282
  private db;
283
283
  private people;
284
284
  constructor(config: any, people: any);
285
- init(config: any, people: any): void;
285
+ /**
286
+ * Initializes the database connection and sets up the Knex instance for interacting with PostgreSQL database.
287
+ *
288
+ * @param {any} config - The configuration object that includes details about how to connect to a PostgreSQL database. This should include properties such as `host`, `user`, `password`, etc.
289
+ * @param {any} people - The data related to the 'people' entity. It could be an array of person objects or any other format depending on your application requirements.
290
+ * @param {boolean} debug - A flag indicating whether to enable debugging for Knex queries. Defaults to `false`. If set to `true`, it will log all SQL queries that are executed against the database in the console.
291
+ */
292
+ init(config: any, people?: any, debug?: boolean): void;
286
293
  /**
287
294
  *
288
295
  * Extract customer account and po number
@@ -918,6 +925,13 @@ declare class FAMISDb {
918
925
  * @property {date} created - created date
919
926
  * @property {date} deleted - deleted date
920
927
  */
928
+ /**
929
+ * Create an invoice comment file.
930
+ * @param {InvoiceCommentFile} file - JSON object representing the comment file
931
+ * @returns {Promise<InvoiceCommentFile>} - Promise that resolves to the comment file object
932
+ * @memberof FAMISDb
933
+ */
934
+ saveCommentFile(file: InvoiceCommentFile): Promise<InvoiceCommentFile | null>;
921
935
  /**
922
936
  * Get invoice comment files.
923
937
  * @param {string} commentUid - Comment UID
@@ -1046,9 +1060,9 @@ declare class FAMISDb {
1046
1060
 
1047
1061
  export declare interface InvoiceComment {
1048
1062
  id?: number;
1049
- uid: string;
1063
+ uid?: string;
1050
1064
  invoice_id: string;
1051
- user_id: string;
1065
+ user_id?: string | null;
1052
1066
  comment: string | null;
1053
1067
  type: string | null;
1054
1068
  created: string | null;
@@ -1056,7 +1070,7 @@ declare class FAMISDb {
1056
1070
  }
1057
1071
 
1058
1072
  export declare type InvoiceCommentFile = {
1059
- id: number;
1073
+ id?: number;
1060
1074
  uid: string;
1061
1075
  invoice_id: string;
1062
1076
  comment_id: string;
@@ -1126,9 +1140,9 @@ declare class FAMISDb {
1126
1140
  fein: string;
1127
1141
  agency: string;
1128
1142
  checkAddress: string;
1129
- credit: boolean;
1130
- creditUrl: string;
1131
- creditFee: string;
1143
+ credit?: boolean | null;
1144
+ creditUrl?: string | null;
1145
+ creditFee?: string | null;
1132
1146
  part: string;
1133
1147
  abbrev: string;
1134
1148
  aggiebuy: string;
package/dist/main.cjs CHANGED
@@ -195,11 +195,18 @@ class FAMISDb {
195
195
  this.init(config, people);
196
196
  }
197
197
  }
198
- init(config, people) {
198
+ /**
199
+ * Initializes the database connection and sets up the Knex instance for interacting with PostgreSQL database.
200
+ *
201
+ * @param {any} config - The configuration object that includes details about how to connect to a PostgreSQL database. This should include properties such as `host`, `user`, `password`, etc.
202
+ * @param {any} people - The data related to the 'people' entity. It could be an array of person objects or any other format depending on your application requirements.
203
+ * @param {boolean} debug - A flag indicating whether to enable debugging for Knex queries. Defaults to `false`. If set to `true`, it will log all SQL queries that are executed against the database in the console.
204
+ */
205
+ init(config, people = null, debug = false) {
199
206
  this.db = knex({
200
207
  client: "pg",
201
208
  connection: config,
202
- debug: true,
209
+ debug,
203
210
  pool: {
204
211
  min: 0,
205
212
  max: 10,
@@ -690,7 +697,7 @@ class FAMISDb {
690
697
  */
691
698
  async updateInvoice(uid, invoice) {
692
699
  let records;
693
- invoice.details.forEach((d) => {
700
+ invoice.data.details.forEach((d) => {
694
701
  if (!d.other) {
695
702
  d.other = "0.00";
696
703
  }
@@ -702,19 +709,25 @@ class FAMISDb {
702
709
  }
703
710
  });
704
711
  try {
712
+ const {
713
+ comments,
714
+ isIdt,
715
+ poNumber,
716
+ totalAmount,
717
+ data,
718
+ customerAccount,
719
+ sellingAccount,
720
+ fingerprint,
721
+ ...rest
722
+ } = invoice;
705
723
  const record = {
706
- number: invoice.number,
707
- lab: invoice.lab,
708
- totalAmount: parseFloat(invoice.totalAmount),
709
- data: JSON.stringify(invoice),
710
- date: invoice.date,
711
- customerAccount: this.getAccountNumber(invoice.details[0].famis).accountNumber,
712
- sellingAccount: getCoreAccountNumber(invoice.details[0].famis),
713
- fingerprint: invoice.fingerprint ? invoice.fingerprint : null
724
+ ...rest,
725
+ totalAmount: parseFloat(totalAmount.replace("$", "")),
726
+ data: JSON.stringify(data),
727
+ customerAccount: this.getAccountNumber(data.details[0].famis).accountNumber,
728
+ sellingAccount: getCoreAccountNumber(data.details[0].famis),
729
+ fingerprint: fingerprint ? fingerprint : null
714
730
  };
715
- if (invoice.replace_data) {
716
- record.replace_data = invoice.replace_data;
717
- }
718
731
  records = await this.db("invoices").returning(returningColumns).update(record).where("uid", uid);
719
732
  } catch (e) {
720
733
  throw e;
@@ -2037,6 +2050,35 @@ class FAMISDb {
2037
2050
  * @property {date} created - created date
2038
2051
  * @property {date} deleted - deleted date
2039
2052
  */
2053
+ /**
2054
+ * Create an invoice comment file.
2055
+ * @param {InvoiceCommentFile} file - JSON object representing the comment file
2056
+ * @returns {Promise<InvoiceCommentFile>} - Promise that resolves to the comment file object
2057
+ * @memberof FAMISDb
2058
+ */
2059
+ async saveCommentFile(file) {
2060
+ const returningColumns2 = [
2061
+ "id",
2062
+ "uid",
2063
+ "invoice_id",
2064
+ "comment_id",
2065
+ "original_filename",
2066
+ "filename",
2067
+ "created",
2068
+ "deleted"
2069
+ ];
2070
+ let response;
2071
+ try {
2072
+ response = await this.db("invoice_comment_files").returning(returningColumns2).insert(file);
2073
+ if (response && Array.isArray(response) && response.length) {
2074
+ response = response[0];
2075
+ }
2076
+ } catch (e) {
2077
+ console.log(e);
2078
+ throw e;
2079
+ }
2080
+ return response;
2081
+ }
2040
2082
  /**
2041
2083
  * Get invoice comment files.
2042
2084
  * @param {string} commentUid - Comment UID