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

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "src/index.ts": {
3
3
  "file": "main.cjs",
4
- "isEntry": true,
5
- "src": "src/index.ts"
4
+ "src": "src/index.ts",
5
+ "isEntry": true
6
6
  }
7
7
  }
package/dist/index.d.mts CHANGED
@@ -68,8 +68,8 @@ export declare interface Contact {
68
68
 
69
69
  export declare interface Core {
70
70
  id: number;
71
- account: string;
72
- effective: string;
71
+ account?: string;
72
+ effective?: string;
73
73
  facility: string;
74
74
  contact: string;
75
75
  contactEmail: string;
@@ -81,7 +81,7 @@ export declare interface Core {
81
81
  coreAddress: string | null;
82
82
  from_email: string | null;
83
83
  invoice_email: string | null;
84
- systemPart: SystemPart;
84
+ systemPart?: SystemPart;
85
85
  system_part?: string;
86
86
  system_name?: string;
87
87
  system_abbrev?: string;
@@ -90,11 +90,13 @@ export declare interface Core {
90
90
  }
91
91
 
92
92
  export declare interface CoreAccount {
93
- id: number;
93
+ id?: number;
94
94
  account: string;
95
95
  coreId: number;
96
- effective: Date;
97
- active: boolean | null;
96
+ coreAccountId?: number;
97
+ coreAccountActive?: boolean | null;
98
+ effective?: Date | null;
99
+ active?: boolean | null;
98
100
  }
99
101
 
100
102
  export declare interface CoreAccountEmail {
@@ -115,6 +117,7 @@ export declare interface CoreUser {
115
117
  id?: number;
116
118
  userId: string;
117
119
  coreId: number;
120
+ coreUserId?: number;
118
121
  email?: boolean | null;
119
122
  }
120
123
 
@@ -673,7 +676,7 @@ declare class FAMISDb {
673
676
  * @returns {Promise<Core>} core object
674
677
  * @memberof FAMISDb
675
678
  */
676
- updateCore(core: Core): Promise<Core>;
679
+ updateCore(core: Core): Promise<Core | undefined>;
677
680
  /**
678
681
  *
679
682
  * Add core
@@ -698,6 +701,14 @@ declare class FAMISDb {
698
701
  * @memberof FAMISDb
699
702
  */
700
703
  addCoreAccount(account: CoreAccount): Promise<CoreAccount>;
704
+ /**
705
+ *
706
+ * Delete core account
707
+ * @param {coreAccountId} string core account id
708
+ * @returns {Promise<CoreAccount>} core account object
709
+ * @memberof FAMISDb
710
+ */
711
+ deleteCoreAccount(coreAccountId: string): Promise<CoreAccount>;
701
712
  /**
702
713
  *
703
714
  * Get system part by ID
@@ -749,15 +760,21 @@ declare class FAMISDb {
749
760
  * @memberof FAMISDb
750
761
  */
751
762
  updateCoreUser(user: CoreUser): Promise<CoreUser>;
763
+ /**
764
+ * This function adds a new CoreUser to the database. If the user already exists, it updates the existing record.
765
+ * @param {CoreUser} coreUser - The CoreUser object containing details about the user.
766
+ * @param {User} [user] - An optional User object that could contain additional details.
767
+ * @return {Promise<CoreUser>} A Promise that resolves to the newly added or updated CoreUser, if successfully added and returned from the database; otherwise it rejects with an error.
768
+ */
769
+ addCoreUser(coreUser: CoreUser, user?: User): Promise<CoreUser>;
752
770
  /**
753
771
  *
754
- * Add core user
755
- * @param {CoreUser} coreUser core user object
756
- * @param {User} user user object
772
+ * Delete core user
773
+ * @param {coreUserId} string core user object
757
774
  * @returns {Promise<CoreUser>} core user object
758
775
  * @memberof FAMISDb
759
776
  */
760
- addCoreUser(coreUser: CoreUser, user?: User): Promise<CoreUser>;
777
+ deleteCoreUser(coreUserId: string): Promise<CoreUser>;
761
778
  /**
762
779
  *
763
780
  * Get a user's cores they manage
@@ -948,21 +965,28 @@ declare class FAMISDb {
948
965
  */
949
966
  getCoreAccountAdditionalEmailsByAccount(accountNumber: string): Promise<CoreAccountEmail[] | []>;
950
967
  /**
951
- * Add an additional delivery email to an expense account for a core
952
- * @param {string} accountNumber - 13 digit famis account or customernumber
968
+ * Get additional delivery emails to expense accounts for a core by core id
969
+ * and account number
953
970
  * @param {number} coreId - Core ID
954
- * @param {string} email - email address
971
+ * @param {string} account - account number
972
+ * @returns {Promise<CoreAccountEmail[]|[]>} - Promise that resolves to an account object
973
+ * @memberof FAMISDb
974
+ */
975
+ getCoreAccountAdditionalEmailsByCoreIdAccount(coreId: number, account: string): Promise<CoreAccountEmail[] | []>;
976
+ /**
977
+ * Add an additional delivery email to an expense account for a core
978
+ * @param {CoreAccountEmail} record - core account email delivery record
955
979
  * @returns {Promise<CoreAccountEmail>} - Promise that resolves to an account object
956
980
  * @memberof FAMISDb
957
981
  */
958
- addCoreAccountAdditionalEmails(accountNumber: string, coreId: number, email: string): Promise<CoreAccountEmail | null>;
982
+ addCoreAccountAdditionalEmail(record: CoreAccountEmail): Promise<CoreAccountEmail | null>;
959
983
  /**
960
984
  * Remove an additional delivery email to an expense account for a core
961
985
  * @param {string} uid - uid for core account email record
962
986
  * @returns {Promise<CoreAccountEmail>} - Promise that resolves to an account object
963
987
  * @memberof FAMISDb
964
988
  */
965
- removeCoreAccountAdditionalEmails(uid: string): Promise<CoreAccountEmail | null>;
989
+ removeCoreAccountAdditionalEmail(uid: string): Promise<CoreAccountEmail | null>;
966
990
  }
967
991
  export default FAMISDb;
968
992
 
@@ -1133,6 +1157,7 @@ declare class FAMISDb {
1133
1157
  usersSystemId?: number | null;
1134
1158
  systemId?: number | null;
1135
1159
  coreId?: number | null;
1160
+ coreUserId?: number | null;
1136
1161
  cores?: CorePayload | null;
1137
1162
  systems?: SystemPart[] | [] | null;
1138
1163
  deleted?: Date | null;
package/dist/index.d.ts CHANGED
@@ -68,8 +68,8 @@ export declare interface Contact {
68
68
 
69
69
  export declare interface Core {
70
70
  id: number;
71
- account: string;
72
- effective: string;
71
+ account?: string;
72
+ effective?: string;
73
73
  facility: string;
74
74
  contact: string;
75
75
  contactEmail: string;
@@ -81,7 +81,7 @@ export declare interface Core {
81
81
  coreAddress: string | null;
82
82
  from_email: string | null;
83
83
  invoice_email: string | null;
84
- systemPart: SystemPart;
84
+ systemPart?: SystemPart;
85
85
  system_part?: string;
86
86
  system_name?: string;
87
87
  system_abbrev?: string;
@@ -90,11 +90,13 @@ export declare interface Core {
90
90
  }
91
91
 
92
92
  export declare interface CoreAccount {
93
- id: number;
93
+ id?: number;
94
94
  account: string;
95
95
  coreId: number;
96
- effective: Date;
97
- active: boolean | null;
96
+ coreAccountId?: number;
97
+ coreAccountActive?: boolean | null;
98
+ effective?: Date | null;
99
+ active?: boolean | null;
98
100
  }
99
101
 
100
102
  export declare interface CoreAccountEmail {
@@ -115,6 +117,7 @@ export declare interface CoreUser {
115
117
  id?: number;
116
118
  userId: string;
117
119
  coreId: number;
120
+ coreUserId?: number;
118
121
  email?: boolean | null;
119
122
  }
120
123
 
@@ -673,7 +676,7 @@ declare class FAMISDb {
673
676
  * @returns {Promise<Core>} core object
674
677
  * @memberof FAMISDb
675
678
  */
676
- updateCore(core: Core): Promise<Core>;
679
+ updateCore(core: Core): Promise<Core | undefined>;
677
680
  /**
678
681
  *
679
682
  * Add core
@@ -698,6 +701,14 @@ declare class FAMISDb {
698
701
  * @memberof FAMISDb
699
702
  */
700
703
  addCoreAccount(account: CoreAccount): Promise<CoreAccount>;
704
+ /**
705
+ *
706
+ * Delete core account
707
+ * @param {coreAccountId} string core account id
708
+ * @returns {Promise<CoreAccount>} core account object
709
+ * @memberof FAMISDb
710
+ */
711
+ deleteCoreAccount(coreAccountId: string): Promise<CoreAccount>;
701
712
  /**
702
713
  *
703
714
  * Get system part by ID
@@ -749,15 +760,21 @@ declare class FAMISDb {
749
760
  * @memberof FAMISDb
750
761
  */
751
762
  updateCoreUser(user: CoreUser): Promise<CoreUser>;
763
+ /**
764
+ * This function adds a new CoreUser to the database. If the user already exists, it updates the existing record.
765
+ * @param {CoreUser} coreUser - The CoreUser object containing details about the user.
766
+ * @param {User} [user] - An optional User object that could contain additional details.
767
+ * @return {Promise<CoreUser>} A Promise that resolves to the newly added or updated CoreUser, if successfully added and returned from the database; otherwise it rejects with an error.
768
+ */
769
+ addCoreUser(coreUser: CoreUser, user?: User): Promise<CoreUser>;
752
770
  /**
753
771
  *
754
- * Add core user
755
- * @param {CoreUser} coreUser core user object
756
- * @param {User} user user object
772
+ * Delete core user
773
+ * @param {coreUserId} string core user object
757
774
  * @returns {Promise<CoreUser>} core user object
758
775
  * @memberof FAMISDb
759
776
  */
760
- addCoreUser(coreUser: CoreUser, user?: User): Promise<CoreUser>;
777
+ deleteCoreUser(coreUserId: string): Promise<CoreUser>;
761
778
  /**
762
779
  *
763
780
  * Get a user's cores they manage
@@ -948,21 +965,28 @@ declare class FAMISDb {
948
965
  */
949
966
  getCoreAccountAdditionalEmailsByAccount(accountNumber: string): Promise<CoreAccountEmail[] | []>;
950
967
  /**
951
- * Add an additional delivery email to an expense account for a core
952
- * @param {string} accountNumber - 13 digit famis account or customernumber
968
+ * Get additional delivery emails to expense accounts for a core by core id
969
+ * and account number
953
970
  * @param {number} coreId - Core ID
954
- * @param {string} email - email address
971
+ * @param {string} account - account number
972
+ * @returns {Promise<CoreAccountEmail[]|[]>} - Promise that resolves to an account object
973
+ * @memberof FAMISDb
974
+ */
975
+ getCoreAccountAdditionalEmailsByCoreIdAccount(coreId: number, account: string): Promise<CoreAccountEmail[] | []>;
976
+ /**
977
+ * Add an additional delivery email to an expense account for a core
978
+ * @param {CoreAccountEmail} record - core account email delivery record
955
979
  * @returns {Promise<CoreAccountEmail>} - Promise that resolves to an account object
956
980
  * @memberof FAMISDb
957
981
  */
958
- addCoreAccountAdditionalEmails(accountNumber: string, coreId: number, email: string): Promise<CoreAccountEmail | null>;
982
+ addCoreAccountAdditionalEmail(record: CoreAccountEmail): Promise<CoreAccountEmail | null>;
959
983
  /**
960
984
  * Remove an additional delivery email to an expense account for a core
961
985
  * @param {string} uid - uid for core account email record
962
986
  * @returns {Promise<CoreAccountEmail>} - Promise that resolves to an account object
963
987
  * @memberof FAMISDb
964
988
  */
965
- removeCoreAccountAdditionalEmails(uid: string): Promise<CoreAccountEmail | null>;
989
+ removeCoreAccountAdditionalEmail(uid: string): Promise<CoreAccountEmail | null>;
966
990
  }
967
991
  export default FAMISDb;
968
992
 
@@ -1133,6 +1157,7 @@ declare class FAMISDb {
1133
1157
  usersSystemId?: number | null;
1134
1158
  systemId?: number | null;
1135
1159
  coreId?: number | null;
1160
+ coreUserId?: number | null;
1136
1161
  cores?: CorePayload | null;
1137
1162
  systems?: SystemPart[] | [] | null;
1138
1163
  deleted?: Date | null;
package/dist/main.cjs CHANGED
@@ -1218,9 +1218,9 @@ class FAMISDb {
1218
1218
  ];
1219
1219
  try {
1220
1220
  rows = await this.db.with("coreaccounts", (qb) => {
1221
- qb.select("accounts.*", "core_accounts.active", "core_accounts.coreId", "core_accounts.effective").from("core_accounts").join("accounts", "core_accounts.account", "accounts.account_number");
1221
+ qb.select("accounts.*", "core_accounts.active as coreAccountActive", "core_accounts.coreId", "core_accounts.effective", "core_accounts.id as coreAccountId").from("core_accounts").join("accounts", "core_accounts.account", "accounts.account_number");
1222
1222
  }).with("coreusers", (qb) => {
1223
- qb.select("users.*", "user_cores.email", "user_cores.coreId").from("user_cores").join("users", "user_cores.userId", "users.id");
1223
+ qb.select("users.*", "user_cores.email", "user_cores.coreId", "user_cores.id as coreUserId").from("user_cores").join("users", "user_cores.userId", "users.id");
1224
1224
  }).from("cores").leftJoin("system", "system.id", "cores.systemId").where(this.db.raw(query)).orderBy(sortColumn, sortDirection).leftJoin(
1225
1225
  this.db.from("user_cores").join("coreusers", { "user_cores.userId": "coreusers.id", "user_cores.coreId": "coreusers.coreId" }).select(
1226
1226
  "user_cores.coreId",
@@ -1305,9 +1305,9 @@ class FAMISDb {
1305
1305
  */
1306
1306
  ];
1307
1307
  records = await this.db.with("coreaccounts", (qb) => {
1308
- qb.select("accounts.*", "core_accounts.coreId", "core_accounts.effective").from("core_accounts").join("accounts", "core_accounts.account", "accounts.account_number");
1308
+ qb.select("accounts.*", "core_accounts.coreId", "core_accounts.active as coreAccountActive", "core_accounts.effective", "core_accounts.id as coreAccountId").from("core_accounts").join("accounts", "core_accounts.account", "accounts.account_number");
1309
1309
  }).with("coreusers", (qb) => {
1310
- qb.select("users.*", "user_cores.email", "user_cores.coreId").from("user_cores").join("users", "user_cores.userId", "users.id");
1310
+ qb.select("users.*", "user_cores.email", "user_cores.coreId", "user_cores.id as coreUserId").from("user_cores").join("users", "user_cores.userId", "users.id");
1311
1311
  }).from("cores").leftJoin("system", "system.id", "cores.systemId").where(type, operator, search).leftJoin(
1312
1312
  this.db.from("user_cores").join("coreusers", { "user_cores.userId": "coreusers.id", "user_cores.coreId": "coreusers.coreId" }).select(
1313
1313
  "user_cores.coreId",
@@ -1406,12 +1406,12 @@ class FAMISDb {
1406
1406
  */
1407
1407
  async updateCore(core) {
1408
1408
  let retVal;
1409
- const columns = ["id", "account", "effective", "facility", "contact", "contactEmail", "systemId", "enabled", "deleted", "coreEmail", "corePhone", "coreAddress", "from_email", "invoice_email"];
1409
+ const columns = ["id", "facility", "contact", "contactEmail", "systemId", "enabled", "deleted", "coreEmail", "corePhone", "coreAddress", "from_email", "invoice_email"];
1410
+ const { id, ...record } = core;
1410
1411
  try {
1411
- if ("id" in core) {
1412
- retVal = await this.db("cores").returning(columns).update(core).where("id", core.id);
1413
- const systemPart = this.getSystemById(retVal.systemId);
1414
- retVal.systemPart = systemPart;
1412
+ if (id) {
1413
+ await this.db("cores").returning(columns).update(record).where("id", id);
1414
+ retVal = await this.getCore("cores.id", "=", id.toString());
1415
1415
  }
1416
1416
  } catch (e) {
1417
1417
  throw e;
@@ -1447,9 +1447,10 @@ class FAMISDb {
1447
1447
  async updateCoreAccount(account) {
1448
1448
  let retVal;
1449
1449
  const columns = ["id", "account", "effective", "coreId", "active"];
1450
+ const { id, ...record } = account;
1450
1451
  try {
1451
1452
  if ("id" in account) {
1452
- retVal = await this.db("core_accounts").returning(columns).update(account).where("id", account.id);
1453
+ retVal = await this.db("core_accounts").returning(columns).update(record).where("id", id);
1453
1454
  }
1454
1455
  } catch (e) {
1455
1456
  throw e;
@@ -1473,6 +1474,22 @@ class FAMISDb {
1473
1474
  }
1474
1475
  return retVal;
1475
1476
  }
1477
+ /**
1478
+ *
1479
+ * Delete core account
1480
+ * @param {coreAccountId} string core account id
1481
+ * @returns {Promise<CoreAccount>} core account object
1482
+ * @memberof FAMISDb
1483
+ */
1484
+ async deleteCoreAccount(coreAccountId) {
1485
+ let retVal;
1486
+ try {
1487
+ retVal = await this.db("core_accounts").where("id", coreAccountId).delete();
1488
+ } catch (e) {
1489
+ throw e;
1490
+ }
1491
+ return retVal;
1492
+ }
1476
1493
  /**
1477
1494
  *
1478
1495
  * Get system part by ID
@@ -1523,23 +1540,33 @@ class FAMISDb {
1523
1540
  let records;
1524
1541
  let retVal = [];
1525
1542
  try {
1526
- records = await this.db("cores").select(
1527
- "cores.id",
1528
- "core_accounts.account",
1529
- "core_accounts.effective",
1530
- "core_accounts.active",
1531
- "cores.facility",
1532
- "cores.contact",
1533
- "cores.contactEmail",
1534
- "cores.systemId",
1535
- "cores.enabled",
1536
- "cores.deleted",
1537
- "cores.coreEmail",
1538
- "cores.corePhone",
1539
- "cores.coreAddress",
1540
- "cores.from_email",
1541
- "cores.invoice_email"
1542
- ).join("core_accounts", "cores.id", "=", "core_accounts.coreId").where("enabled", "1").andWhere("core_accounts.active", "True").groupBy("cores.id").orderBy("cores.id", "desc");
1543
+ records = await this.db.with("coreaccounts", (qb) => {
1544
+ qb.select("accounts.*", "core_accounts.active as coreAccountActive", "core_accounts.coreId", "core_accounts.effective", "core_accounts.id as coreAccountId").from("core_accounts").join("accounts", "core_accounts.account", "accounts.account_number");
1545
+ }).with("coreusers", (qb) => {
1546
+ qb.select("users.*", "user_cores.email", "user_cores.coreId", "user_cores.id as coreUserId").from("user_cores").join("users", "user_cores.userId", "users.id");
1547
+ }).from("cores").leftJoin(
1548
+ this.db.from("user_cores").join("coreusers", { "user_cores.userId": "coreusers.id", "user_cores.coreId": "coreusers.coreId" }).select(
1549
+ "user_cores.coreId",
1550
+ this.db.raw(
1551
+ "case when count(coreusers) = 0 then '[]' else jsonb_agg(coreusers.*) end as users"
1552
+ )
1553
+ ).groupBy(["user_cores.coreId"]).as("user_cores"),
1554
+ "user_cores.coreId",
1555
+ "cores.id"
1556
+ ).leftJoin(
1557
+ this.db.from("core_accounts").join("coreaccounts", { "core_accounts.account": "coreaccounts.account_number", "core_accounts.coreId": "coreaccounts.coreId" }).select(
1558
+ "core_accounts.coreId",
1559
+ this.db.raw(
1560
+ "case when count(coreaccounts) = 0 then '[]' else jsonb_agg(coreaccounts.*) end as accounts"
1561
+ )
1562
+ ).groupBy(["core_accounts.coreId"]).as("core_accounts"),
1563
+ "core_accounts.coreId",
1564
+ "cores.id"
1565
+ ).select(
1566
+ "cores.*",
1567
+ "user_cores.users",
1568
+ "core_accounts.accounts"
1569
+ ).where("enabled", "1").orderBy("cores.id", "desc");
1543
1570
  if (records.length) {
1544
1571
  retVal = records;
1545
1572
  }
@@ -1608,9 +1635,10 @@ class FAMISDb {
1608
1635
  async updateCoreUser(user) {
1609
1636
  let retVal;
1610
1637
  const columns = ["id", "userId", "coreId", "email"];
1638
+ const { id, ...record } = user;
1611
1639
  try {
1612
1640
  if ("id" in user) {
1613
- retVal = await this.db("user_cores").returning(columns).update(user).where("id", user.id);
1641
+ retVal = await this.db("user_cores").returning(columns).update(record).where("id", id);
1614
1642
  }
1615
1643
  } catch (e) {
1616
1644
  throw e;
@@ -1618,12 +1646,10 @@ class FAMISDb {
1618
1646
  return retVal;
1619
1647
  }
1620
1648
  /**
1621
- *
1622
- * Add core user
1623
- * @param {CoreUser} coreUser core user object
1624
- * @param {User} user user object
1625
- * @returns {Promise<CoreUser>} core user object
1626
- * @memberof FAMISDb
1649
+ * This function adds a new CoreUser to the database. If the user already exists, it updates the existing record.
1650
+ * @param {CoreUser} coreUser - The CoreUser object containing details about the user.
1651
+ * @param {User} [user] - An optional User object that could contain additional details.
1652
+ * @return {Promise<CoreUser>} A Promise that resolves to the newly added or updated CoreUser, if successfully added and returned from the database; otherwise it rejects with an error.
1627
1653
  */
1628
1654
  async addCoreUser(coreUser, user) {
1629
1655
  let retVal;
@@ -1644,6 +1670,22 @@ class FAMISDb {
1644
1670
  }
1645
1671
  return retVal;
1646
1672
  }
1673
+ /**
1674
+ *
1675
+ * Delete core user
1676
+ * @param {coreUserId} string core user object
1677
+ * @returns {Promise<CoreUser>} core user object
1678
+ * @memberof FAMISDb
1679
+ */
1680
+ async deleteCoreUser(coreUserId) {
1681
+ let retVal;
1682
+ try {
1683
+ retVal = await this.db("user_cores").where("id", coreUserId).delete();
1684
+ } catch (e) {
1685
+ throw e;
1686
+ }
1687
+ return retVal;
1688
+ }
1647
1689
  /**
1648
1690
  *
1649
1691
  * Get a user's cores they manage
@@ -2093,23 +2135,38 @@ class FAMISDb {
2093
2135
  return response;
2094
2136
  }
2095
2137
  /**
2096
- * Add an additional delivery email to an expense account for a core
2097
- * @param {string} accountNumber - 13 digit famis account or customernumber
2138
+ * Get additional delivery emails to expense accounts for a core by core id
2139
+ * and account number
2098
2140
  * @param {number} coreId - Core ID
2099
- * @param {string} email - email address
2141
+ * @param {string} account - account number
2142
+ * @returns {Promise<CoreAccountEmail[]|[]>} - Promise that resolves to an account object
2143
+ * @memberof FAMISDb
2144
+ */
2145
+ async getCoreAccountAdditionalEmailsByCoreIdAccount(coreId, account) {
2146
+ let response = [];
2147
+ try {
2148
+ const records = await this.db("core_account_emails").where({
2149
+ core_id: coreId,
2150
+ account_number: account
2151
+ }).whereNull("deleted");
2152
+ response = records;
2153
+ } catch (e) {
2154
+ console.log(e);
2155
+ throw e;
2156
+ }
2157
+ return response;
2158
+ }
2159
+ /**
2160
+ * Add an additional delivery email to an expense account for a core
2161
+ * @param {CoreAccountEmail} record - core account email delivery record
2100
2162
  * @returns {Promise<CoreAccountEmail>} - Promise that resolves to an account object
2101
2163
  * @memberof FAMISDb
2102
2164
  */
2103
- async addCoreAccountAdditionalEmails(accountNumber, coreId, email) {
2165
+ async addCoreAccountAdditionalEmail(record) {
2104
2166
  let response = null;
2105
2167
  const columns = ["uid", "core_id", "account_number", "email", "created", "deleted"];
2106
2168
  try {
2107
- const records = await this.db("core_account_emails").returning(columns).insert({
2108
- core_id: coreId,
2109
- account_number: accountNumber,
2110
- email,
2111
- created: this.db.raw("NOW")
2112
- });
2169
+ const records = await this.db("core_account_emails").returning(columns).insert(record);
2113
2170
  response = records.length ? records[0] : records;
2114
2171
  } catch (e) {
2115
2172
  console.log(e);
@@ -2123,12 +2180,12 @@ class FAMISDb {
2123
2180
  * @returns {Promise<CoreAccountEmail>} - Promise that resolves to an account object
2124
2181
  * @memberof FAMISDb
2125
2182
  */
2126
- async removeCoreAccountAdditionalEmails(uid) {
2183
+ async removeCoreAccountAdditionalEmail(uid) {
2127
2184
  let response = null;
2128
2185
  const columns = ["uid", "core_id", "account_number", "email", "created", "deleted"];
2129
2186
  try {
2130
2187
  const records = await this.db("core_account_emails").returning(columns).update({
2131
- deleted: this.db.raw("NOW")
2188
+ deleted: this.db.raw("CURRENT_TIMESTAMP")
2132
2189
  }).where({ uid });
2133
2190
  response = records.length ? records[0] : records;
2134
2191
  } catch (e) {