Merge pull request #1864 from RafaelTaranto/fix/display-name-on-custom-data
LAM-314 fix: name on customer if custom data is filled
This commit is contained in:
commit
4c270dcd65
1 changed files with 39 additions and 17 deletions
|
|
@ -1,9 +1,13 @@
|
||||||
import db from './db.js'
|
import db from './db.js'
|
||||||
import { ExpressionBuilder, sql } from 'kysely'
|
import { ExpressionBuilder } from 'kysely'
|
||||||
import { Customers, DB } from './types/types.js'
|
import { Customers, DB, EditedCustomerData } from './types/types.js'
|
||||||
import { jsonObjectFrom } from 'kysely/helpers/postgres'
|
import { jsonArrayFrom } from 'kysely/helpers/postgres'
|
||||||
|
|
||||||
type CustomerEB = ExpressionBuilder<DB & { c: Customers }, 'c'>
|
type CustomerEB = ExpressionBuilder<DB & { c: Customers }, 'c'>
|
||||||
|
type CustomerWithEditedEB = ExpressionBuilder<
|
||||||
|
DB & { c: Customers } & { e: EditedCustomerData | null },
|
||||||
|
'c' | 'e'
|
||||||
|
>
|
||||||
|
|
||||||
const TX_PASSTHROUGH_ERROR_CODES = [
|
const TX_PASSTHROUGH_ERROR_CODES = [
|
||||||
'operatorCancel',
|
'operatorCancel',
|
||||||
|
|
@ -87,6 +91,23 @@ function joinTxsTotals(eb: CustomerEB) {
|
||||||
.as('txStats')
|
.as('txStats')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectNewestIdCardData(eb: CustomerWithEditedEB, ref: any) {
|
||||||
|
return eb
|
||||||
|
.case()
|
||||||
|
.when(
|
||||||
|
eb.and([
|
||||||
|
eb(ref('e.idCardDataAt'), 'is not', null),
|
||||||
|
eb.or([
|
||||||
|
eb(ref('c.idCardDataAt'), 'is', null),
|
||||||
|
eb(ref('e.idCardDataAt'), '>', ref('c.idCardDataAt')),
|
||||||
|
]),
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
.then(ref('e.idCardData'))
|
||||||
|
.else(ref('c.idCardData'))
|
||||||
|
.end()
|
||||||
|
}
|
||||||
|
|
||||||
interface GetCustomerListOptions {
|
interface GetCustomerListOptions {
|
||||||
withCustomInfoRequest: boolean
|
withCustomInfoRequest: boolean
|
||||||
}
|
}
|
||||||
|
|
@ -101,22 +122,23 @@ function getCustomerList(
|
||||||
): Promise<any[]> {
|
): Promise<any[]> {
|
||||||
return db
|
return db
|
||||||
.selectFrom('customers as c')
|
.selectFrom('customers as c')
|
||||||
|
.leftJoin('editedCustomerData as e', 'e.customerId', 'c.id')
|
||||||
.leftJoinLateral(joinTxsTotals, join => join.onTrue())
|
.leftJoinLateral(joinTxsTotals, join => join.onTrue())
|
||||||
.leftJoinLateral(joinLatestTx, join => join.onTrue())
|
.leftJoinLateral(joinLatestTx, join => join.onTrue())
|
||||||
.select(({ eb, fn, val, ref }) => [
|
.select(({ eb, fn, val, ref }) => [
|
||||||
'id',
|
'c.id',
|
||||||
'authorizedOverride',
|
'c.authorizedOverride',
|
||||||
'frontCameraPath',
|
'c.frontCameraPath',
|
||||||
'frontCameraOverride',
|
'c.frontCameraOverride',
|
||||||
'idCardPhotoPath',
|
'c.idCardPhotoPath',
|
||||||
'idCardPhotoOverride',
|
'c.idCardPhotoOverride',
|
||||||
'idCardData',
|
selectNewestIdCardData(eb, ref).as('idCardData'),
|
||||||
'idCardDataOverride',
|
'c.idCardDataOverride',
|
||||||
'email',
|
'c.email',
|
||||||
'usSsn',
|
'c.usSsn',
|
||||||
'usSsnOverride',
|
'c.usSsnOverride',
|
||||||
'sanctions',
|
'c.sanctions',
|
||||||
'sanctionsOverride',
|
'c.sanctionsOverride',
|
||||||
'txStats.totalSpent',
|
'txStats.totalSpent',
|
||||||
'txStats.totalTxs',
|
'txStats.totalTxs',
|
||||||
ref('lastTx.fiatCode').as('lastTxFiatCode'),
|
ref('lastTx.fiatCode').as('lastTxFiatCode'),
|
||||||
|
|
@ -144,7 +166,7 @@ function getCustomerList(
|
||||||
])
|
])
|
||||||
.$if(options.withCustomInfoRequest, qb =>
|
.$if(options.withCustomInfoRequest, qb =>
|
||||||
qb.select(({ eb, ref }) =>
|
qb.select(({ eb, ref }) =>
|
||||||
jsonObjectFrom(
|
jsonArrayFrom(
|
||||||
eb
|
eb
|
||||||
.selectFrom('customersCustomInfoRequests')
|
.selectFrom('customersCustomInfoRequests')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue