Merge pull request #1683 from RafaelTaranto/feat/save-last-auth-attempt-customer
LAM-1108 feat: save last auth attempt per customer
This commit is contained in:
commit
35d38e0dee
5 changed files with 34 additions and 8 deletions
|
|
@ -494,7 +494,7 @@ function getCustomersList (phone = null, name = null, address = null, id = null,
|
|||
const sql = `SELECT id, authorized_override, days_suspended, is_suspended, front_camera_path, front_camera_override,
|
||||
phone, email, sms_override, id_card_data, id_card_data_override, id_card_data_expiration,
|
||||
id_card_photo_path, id_card_photo_override, us_ssn, us_ssn_override, sanctions, sanctions_at,
|
||||
sanctions_override, total_txs, total_spent, GREATEST(created, last_transaction, last_data_provided) AS last_active, fiat AS last_tx_fiat,
|
||||
sanctions_override, total_txs, total_spent, GREATEST(created, last_transaction, last_data_provided, last_auth_attempt) AS last_active, fiat AS last_tx_fiat,
|
||||
fiat_code AS last_tx_fiat_code, tx_class AS last_tx_class, custom_fields, notes, is_test_customer
|
||||
FROM (
|
||||
SELECT c.id, c.authorized_override,
|
||||
|
|
@ -502,7 +502,7 @@ function getCustomersList (phone = null, name = null, address = null, id = null,
|
|||
c.suspended_until > NOW() AS is_suspended,
|
||||
c.front_camera_path, c.front_camera_override,
|
||||
c.phone, c.email, c.sms_override, c.id_card_data, c.id_card_data_override, c.id_card_data_expiration,
|
||||
c.id_card_photo_path, c.id_card_photo_override, c.us_ssn, c.us_ssn_override, c.sanctions,
|
||||
c.id_card_photo_path, c.id_card_photo_override, c.us_ssn, c.us_ssn_override, c.sanctions, c.last_auth_attempt,
|
||||
GREATEST(c.phone_at, c.email_at, c.id_card_data_at, c.front_camera_at, c.id_card_photo_at, c.us_ssn_at) AS last_data_provided,
|
||||
c.sanctions_at, c.sanctions_override, c.is_test_customer, c.created, t.tx_class, t.fiat, t.fiat_code, t.created as last_transaction, cn.notes,
|
||||
row_number() OVER (partition by c.id order by t.created desc) AS rn,
|
||||
|
|
@ -553,13 +553,14 @@ function getCustomerById (id) {
|
|||
const sql = `SELECT id, authorized_override, days_suspended, is_suspended, front_camera_path, front_camera_at, front_camera_override,
|
||||
phone, phone_at, email, email_at, phone_override, sms_override, id_card_data_at, id_card_data, id_card_data_override, id_card_data_expiration,
|
||||
id_card_photo_path, id_card_photo_at, id_card_photo_override, us_ssn_at, us_ssn, us_ssn_override, sanctions, sanctions_at,
|
||||
sanctions_override, total_txs, total_spent, LEAST(created, last_transaction) AS last_active, fiat AS last_tx_fiat,
|
||||
sanctions_override, total_txs, total_spent, GREATEST(created, last_transaction, last_auth_attempt, last_data_provided) AS last_active, fiat AS last_tx_fiat,
|
||||
fiat_code AS last_tx_fiat_code, tx_class AS last_tx_class, subscriber_info, subscriber_info_at, custom_fields, notes, is_test_customer
|
||||
FROM (
|
||||
SELECT c.id, c.authorized_override,
|
||||
greatest(0, date_part('day', c.suspended_until - now())) AS days_suspended,
|
||||
GREATEST(c.phone_at, c.email_at, c.id_card_data_at, c.front_camera_at, c.id_card_photo_at, c.us_ssn_at) AS last_data_provided,
|
||||
c.suspended_until > now() AS is_suspended,
|
||||
c.front_camera_path, c.front_camera_override, c.front_camera_at,
|
||||
c.front_camera_path, c.front_camera_override, c.front_camera_at, c.last_auth_attempt,
|
||||
c.phone, c.phone_at, c.email, c.email_at, c.phone_override, c.sms_override, c.id_card_data, c.id_card_data_at, c.id_card_data_override, c.id_card_data_expiration,
|
||||
c.id_card_photo_path, c.id_card_photo_at, c.id_card_photo_override, c.us_ssn, c.us_ssn_at, c.us_ssn_override, c.sanctions,
|
||||
c.sanctions_at, c.sanctions_override, c.subscriber_info, c.subscriber_info_at, c.is_test_customer, c.created, t.tx_class, t.fiat, t.fiat_code, t.created as last_transaction, cn.notes,
|
||||
|
|
@ -921,6 +922,11 @@ function disableTestCustomer (customerId) {
|
|||
return db.none(sql, [customerId])
|
||||
}
|
||||
|
||||
function updateLastAuthAttempt (customerId) {
|
||||
const sql = `UPDATE customers SET last_auth_attempt=NOW() WHERE id=$1`
|
||||
return db.none(sql, [customerId])
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
add,
|
||||
addWithEmail,
|
||||
|
|
@ -943,5 +949,6 @@ module.exports = {
|
|||
updateEditedPhoto,
|
||||
updateTxCustomerPhoto,
|
||||
enableTestCustomer,
|
||||
disableTestCustomer
|
||||
disableTestCustomer,
|
||||
updateLastAuthAttempt
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ const T = require('../time')
|
|||
const plugins = require('../plugins')
|
||||
const Tx = require('../tx')
|
||||
const loyalty = require('../loyalty')
|
||||
const logger = require('../logger')
|
||||
|
||||
function updateCustomerCustomInfoRequest (customerId, patch, req, res) {
|
||||
if (_.isNil(patch.data)) {
|
||||
|
|
@ -203,6 +204,12 @@ function addOrUpdateCustomer (customerData, config, isEmailAuth) {
|
|||
return addFunction(customerData)
|
||||
})
|
||||
.then(customer => customers.getById(customer.id))
|
||||
.then(customer => {
|
||||
customers.updateLastAuthAttempt(customer.id).catch(() => {
|
||||
logger.info('failure updating last auth attempt for customer ', customer.id)
|
||||
})
|
||||
return customer
|
||||
})
|
||||
.then(customer => {
|
||||
return Tx.customerHistory(customer.id, maxDaysThreshold)
|
||||
.then(result => {
|
||||
|
|
|
|||
13
migrations/1716969535424-customer-last-auth-attempt.js
Normal file
13
migrations/1716969535424-customer-last-auth-attempt.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
const db = require('./db')
|
||||
|
||||
exports.up = function (next) {
|
||||
let sql = [
|
||||
'ALTER TABLE customers ADD COLUMN last_auth_attempt timestamptz'
|
||||
]
|
||||
|
||||
db.multi(sql, next)
|
||||
}
|
||||
|
||||
exports.down = function (next) {
|
||||
next()
|
||||
}
|
||||
|
|
@ -641,7 +641,6 @@ const CustomerProfile = memo(() => {
|
|||
<TransactionsList
|
||||
customer={customerData}
|
||||
data={sortedTransactions}
|
||||
locale={locale}
|
||||
loading={loading}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -17,12 +17,12 @@ import mainStyles from '../CustomersList.styles'
|
|||
|
||||
const useStyles = makeStyles(mainStyles)
|
||||
|
||||
const TransactionsList = ({ customer, data, loading, locale }) => {
|
||||
const TransactionsList = ({ customer, data, loading }) => {
|
||||
const classes = useStyles()
|
||||
const LastTxIcon = customer.lastTxClass === 'cashOut' ? TxOutIcon : TxInIcon
|
||||
const hasData = !(R.isEmpty(data) || R.isNil(data))
|
||||
|
||||
const timezone = locale.timezone
|
||||
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||
const tableSpacingClasses = {
|
||||
[classes.titleAndButtonsContainer]: loading || (!loading && !hasData),
|
||||
[classes.txTableSpacing]: !loading && hasData
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue