@@ -22,14 +22,14 @@ export async function insertUser(
22
22
return knex . transaction ( async ( transaction : Transaction ) => {
23
23
const insertedAddresses = await knex
24
24
. insert ( {
25
- pay_id : payId ,
25
+ payId,
26
26
} )
27
27
. into < Account > ( 'account' )
28
28
. transacting ( transaction )
29
29
. returning ( 'id' )
30
30
. then ( async ( ids ) => {
31
- const accountID = ids [ 0 ]
32
- const mappedAddresses = addAccountIDToAddresses ( addresses , accountID )
31
+ const accountId = ids [ 0 ]
32
+ const mappedAddresses = addAccountIdToAddresses ( addresses , accountId )
33
33
return insertAddresses ( mappedAddresses , transaction )
34
34
} )
35
35
. then ( transaction . commit )
@@ -55,23 +55,23 @@ export async function replaceUser(
55
55
) : Promise < readonly AddressInformation [ ] | null > {
56
56
return knex . transaction ( async ( transaction : Transaction ) => {
57
57
const updatedAddresses = await knex < Account > ( 'account' )
58
- . where ( 'pay_id ' , oldPayId )
59
- . update ( { pay_id : newPayId } )
58
+ . where ( 'payId ' , oldPayId )
59
+ . update ( { payId : newPayId } )
60
60
. transacting ( transaction )
61
61
. returning ( 'id' )
62
62
. then ( async ( ids ) => {
63
- const accountID = ids [ 0 ]
64
- if ( accountID === undefined ) {
63
+ const accountId = ids [ 0 ]
64
+ if ( accountId === undefined ) {
65
65
return null
66
66
}
67
67
68
68
// Delete existing addresses associated with that user
69
69
await knex < Address > ( 'address' )
70
70
. delete ( )
71
- . where ( 'account_id ' , accountID )
71
+ . where ( 'accountId ' , accountId )
72
72
. transacting ( transaction )
73
73
74
- const mappedAddresses = addAccountIDToAddresses ( addresses , accountID )
74
+ const mappedAddresses = addAccountIdToAddresses ( addresses , accountId )
75
75
return insertAddresses ( mappedAddresses , transaction )
76
76
} )
77
77
. then ( transaction . commit )
@@ -90,7 +90,7 @@ export async function replaceUser(
90
90
export async function removeUser ( payId : string ) : Promise < void > {
91
91
await knex < Account > ( 'account' )
92
92
. delete ( )
93
- . where ( 'pay_id ' , payId )
93
+ . where ( 'payId ' , payId )
94
94
. then ( ( count ) => {
95
95
/* istanbul ignore if */
96
96
if ( count > 1 ) {
@@ -109,25 +109,25 @@ export async function removeUser(payId: string): Promise<void> {
109
109
// HELPER FUNCTIONS
110
110
111
111
interface DatabaseAddress extends AddressInformation {
112
- account_id : string
112
+ accountId : string
113
113
}
114
114
115
115
/**
116
116
* Maps an array of AddressInformation objects into an array of DatabaseAddress objects,
117
- * by adding an 'account_id ' property to each object.
117
+ * by adding an 'accountId ' property to each object.
118
118
*
119
119
* @param addresses - An array of payment addresses we want to insert into the database.
120
- * @param accountID - The account ID to add to all the addresses to allow inserting the addresses into the database.
120
+ * @param accountId - The account ID to add to all the addresses to allow inserting the addresses into the database.
121
121
*
122
- * @returns A new array of DatabaseAddress objects, where each address has a new property 'account_id '.
122
+ * @returns A new array of DatabaseAddress objects, where each address has a new property 'accountId '.
123
123
*/
124
- function addAccountIDToAddresses (
124
+ function addAccountIdToAddresses (
125
125
addresses : readonly AddressInformation [ ] ,
126
- accountID : string ,
126
+ accountId : string ,
127
127
) : readonly DatabaseAddress [ ] {
128
128
return addresses . map ( ( address ) => ( {
129
- account_id : accountID ,
130
- payment_network : address . payment_network . toUpperCase ( ) ,
129
+ accountId ,
130
+ paymentNetwork : address . paymentNetwork . toUpperCase ( ) ,
131
131
environment : address . environment ?. toUpperCase ( ) ,
132
132
details : address . details ,
133
133
} ) )
@@ -151,5 +151,5 @@ async function insertAddresses(
151
151
. insert ( addresses )
152
152
. into < Address > ( 'address' )
153
153
. transacting ( transaction )
154
- . returning ( [ 'payment_network ' , 'environment' , 'details' ] )
154
+ . returning ( [ 'paymentNetwork ' , 'environment' , 'details' ] )
155
155
}
0 commit comments