feat: added the compliance/customers route

feat: added customers list page

feat: created the Customer type on the gql server and consume it

Currently only with the 'name' property

feat: added query on gql to get the customers list with the needed props

feat: added the currently available props to the front end table

fix: consider only sent txs for the aggregations on the customers list

fix: replace ExpTable with a non-expandable one

fix: remove unused properties from gql and front-end

fix: fixed the customers list columns width

fix: the last active table column was reading the wrong property

chore: remove debug logging

fix: use the correct table columns to check for txs that should be
considered on the customers list page

fix: use the international format for phone numbers

feat: added the search box

fix: remove ordering from the gql customers list query and moved it to
the front-end)

fix: removed the search box

chore: refactor the customers list table into a new component

chore: cleanup code

fix: fixed styles from customer list page header

feat: created customer profile page and started a transition feature
from the customer list

refactor: make components out of customers list table and profile page

feat: selecting a customer now transitions to its profile page

feat: added the customer transactions list table

fix: fix tx class button margins

fix: fix tx class icon margins on the customer list

fix: fixed crypto value

style: fixed the table column widths

feat: added the requirements column (no data yet, though)

feat: added the header with the customer details (no image yet, though)

feat: created the skeleton for the properties cards

feat: create the breadcrumb on the customer profile page (no link yet)

feat: added the children container in the property card

feat: added block customer action button

feat: added action buttons to the property cards

feat: added a children prop to the property card component

feat: added extra properties to the customer gql query

feat: added override fields to the customers gql query

style: added conditional styles to the property card component

feat: added children to the customer property cards

feat: create the edit button function on the property card

feat: add error properties to the txs (from gql)

style: fix action left editing action button and right property card
margins

feat: created a mutation to update a customer

feat: added the customer auth override state to the gql query

feat: fix the routing to the individual customer profile pages

feat: made the 'Customers' label on the breadcrumb work as a link

style: fixed the breadcrumb separator

style: fixed the customer name style

feat: made the action to block and authorize a customer as a toggle

feat: removed the 'Super user' switch (left for v2)

style: added the crossed camera icon on the photo

style: fixed the rejected icons

refactor: refactored some styles that were repetitive

refactor: created constants for the override possible states

feat: created functions for the authorization and blocking of overrides

refactor: renamed setOverride to updateCustomer

fix: remove current unused features

feat: make the property cards fields read-only

feat: setup id card photo and front camera photo image servers

feat: add id card photo on the corresponding property card

feat: add front camera photo on the customer profile header

feat: added gql cache to update the front-end after any mutation

style: added the crossed camera icon when there's no id card photo

refactor: extracted the PropertyCard component to another file

fix: deactivated the cache for the transactions (no need for it)

refactor: removed unused styles

fix: fixed front-camera-photo img path

fix: changed gql local data updates from cache to query refetch

refactor: move override status constants to the property card class

refactor: make the image servers URI a const dependent on the build

fix: remove requirements column from customer tx table (left for future
version)

fix: add aliases to gql query to correctly show errors on tx table

style: fix the transaction errors styles

feat: add terms and conditions page

feat: add modal preview

feat: remove preview

fix: increase space between switch and fields

feat: added the compliance/customers route

feat: added customers list page

feat: created the Customer type on the gql server and consume it

Currently only with the 'name' property

feat: added query on gql to get the customers list with the needed props

feat: added the currently available props to the front end table

fix: consider only sent txs for the aggregations on the customers list

fix: replace ExpTable with a non-expandable one

fix: remove unused properties from gql and front-end

fix: fixed the customers list columns width

fix: the last active table column was reading the wrong property

chore: remove debug logging

fix: use the correct table columns to check for txs that should be
considered on the customers list page

fix: use the international format for phone numbers

feat: added the search box

fix: remove ordering from the gql customers list query and moved it to
the front-end)

fix: removed the search box

chore: refactor the customers list table into a new component

chore: cleanup code

fix: fixed styles from customer list page header

fix: removed unused code

refactor: move transactions to a custom resolver in the customer's query

refactor: break the CustomerProfile component into several smaller ones

style: changed the table row error color from red to no change and the
error text from tomato to comet

fix: removed repeated function (wrong merge)

fix: make the updateCustomer function updates only what's explicitly
told so

style: return with the table row error style

refactor: create a function to test if a value is null prior to passing
it through another function

fix: make t&c changes backwards compatible

chore: bump eslint import library to activate rule

fix: stop showing object on empty column

fix: get machine logs page up-to-date

fix: small admin fixes

feat: add terms and conditions page

feat: add modal preview

feat: remove preview

fix: increase space between switch and fields

feat: added the compliance/customers route

feat: added customers list page

feat: created the Customer type on the gql server and consume it

Currently only with the 'name' property

feat: added query on gql to get the customers list with the needed props

feat: added the currently available props to the front end table

fix: consider only sent txs for the aggregations on the customers list

fix: replace ExpTable with a non-expandable one

fix: remove unused properties from gql and front-end

fix: fixed the customers list columns width

fix: the last active table column was reading the wrong property

chore: remove debug logging

fix: use the correct table columns to check for txs that should be
considered on the customers list page

fix: use the international format for phone numbers

feat: added the search box

fix: remove ordering from the gql customers list query and moved it to
the front-end)

fix: removed the search box

chore: refactor the customers list table into a new component

chore: cleanup code

fix: fixed styles from customer list page header

fix: make t&c changes backwards compatible

fix: stop showing object on empty column

fix: get machine logs page up-to-date

feat: add terms and conditions page

feat: add modal preview

feat: remove preview

fix: increase space between switch and fields

feat: added the compliance/customers route

feat: added customers list page

feat: created the Customer type on the gql server and consume it

Currently only with the 'name' property

feat: added query on gql to get the customers list with the needed props

feat: added the currently available props to the front end table

fix: consider only sent txs for the aggregations on the customers list

fix: replace ExpTable with a non-expandable one

fix: remove unused properties from gql and front-end

fix: fixed the customers list columns width

fix: the last active table column was reading the wrong property

chore: remove debug logging

fix: use the correct table columns to check for txs that should be
considered on the customers list page

fix: use the international format for phone numbers

feat: added the search box

fix: remove ordering from the gql customers list query and moved it to
the front-end)

fix: removed the search box

chore: refactor the customers list table into a new component

chore: cleanup code

fix: fixed styles from customer list page header

fix: make t&c changes backwards compatible

fix: stop showing object on empty column

fix: get machine logs page up-to-date

fix: small admin fixes

feat: create add machine page

feat: add terms and conditions page

feat: add modal preview

feat: remove preview

fix: increase space between switch and fields

feat: added the compliance/customers route

feat: added customers list page

feat: created the Customer type on the gql server and consume it

Currently only with the 'name' property

feat: added query on gql to get the customers list with the needed props

feat: added the currently available props to the front end table

fix: consider only sent txs for the aggregations on the customers list

fix: replace ExpTable with a non-expandable one

fix: remove unused properties from gql and front-end

fix: fixed the customers list columns width

fix: the last active table column was reading the wrong property

chore: remove debug logging

fix: use the correct table columns to check for txs that should be
considered on the customers list page

fix: use the international format for phone numbers

feat: added the search box

fix: remove ordering from the gql customers list query and moved it to
the front-end)

fix: removed the search box

chore: refactor the customers list table into a new component

chore: cleanup code

fix: fixed styles from customer list page header

fix: make t&c changes backwards compatible

fix: stop showing object on empty column

fix: get machine logs page up-to-date

feat: create add machine page

fix: fixed wrong merging

fix: more fixes from last merge

fix: export needed functions that wasn't exported from the customers
module

fix: removed the customer profile route from the header

fix: replaced old dataTable with new component

feat: added onClick event to new DataTable
This commit is contained in:
Liordino Neto 2020-02-06 20:36:56 -03:00 committed by Taranto
parent 840788e044
commit c808ca3be9
29 changed files with 1215 additions and 106 deletions

View file

@ -85,6 +85,30 @@ function update (id, data, userToken, txId) {
.then(camelize)
}
/**
* Update customer record
*
* @name updateCustomer
* @function
*
* @param {string} id Customer's id
* @param {object} data Fields to update
*
* @returns {Promise} Newly updated Customer
*/
async function updateCustomer (id, data) {
const formattedData = _.pick(
['authorized_override', 'id_card_photo_override', 'id_card_data_override', 'sms_override'],
_.mapKeys(_.snakeCase, data))
const sql = Pgp.helpers.update(formattedData, _.keys(formattedData), 'customers') +
' where id=$1'
await db.none(sql, [id])
return getCustomerById(id)
}
/**
* Get customer by id
*
@ -377,21 +401,24 @@ function batch () {
}, customers)))
}
// TODO: getCustomersList and getCustomerById are very similar, so this should be refactored
/**
* Query all customers, ordered by last activity
* and with aggregate columns based on their
* transactions
*
* @returns {array} Array of customers with it's
* @returns {array} Array of customers with it's transactions aggregations
*/
function getCustomersList () {
const sql = `select name, phone, total_txs, total_spent,
coalesce(tx_created, customer_created) as last_active,
fiat as last_tx_fiat, fiat_code as last_tx_fiat_code,
tx_class as last_tx_class
const sql = `select id, name, authorized_override, front_camera_path, phone, sms_override,
id_card_data, id_card_data_override, id_card_data_expiration, id_card_photo_path,
id_card_photo_override, total_txs, total_spent, created as last_active,
fiat as last_tx_fiat, fiat_code as last_tx_fiat_code, tx_class as last_tx_class
from (
select c.name, c.phone, c.created as customer_created,
t.tx_class, t.fiat, t.fiat_code, t.created as tx_created,
select c.id, c.name, c.authorized_override, c.front_camera_path, c.phone, 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, t.tx_class, t.fiat, t.fiat_code, t.created,
row_number() over (partition by c.id order by t.created desc) as rn,
sum(case when t.id is not null then 1 else 0 end) over (partition by c.id) as total_txs,
coalesce(sum(t.fiat) over (partition by c.id), 0) as total_spent
@ -410,6 +437,37 @@ function getCustomersList () {
}, customers)))
}
/**
* Query all customers, ordered by last activity
* and with aggregate columns based on their
* transactions
*
* @returns {array} Array of customers with it's transactions aggregations
*/
function getCustomerById (id) {
const sql = `select id, name, authorized_override, front_camera_path, phone, sms_override,
id_card_data, id_card_data_override, id_card_data_expiration, id_card_photo_path,
id_card_photo_override, total_txs, total_spent, created as last_active,
fiat as last_tx_fiat, fiat_code as last_tx_fiat_code, tx_class as last_tx_class
from (
select c.id, c.name, c.authorized_override, c.front_camera_path, c.phone, 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, t.tx_class, t.fiat, t.fiat_code, t.created,
row_number() over (partition by c.id order by t.created desc) as rn,
count(0) over (partition by c.id) as total_txs,
sum(t.fiat) over (partition by c.id) as total_spent
from customers c inner join (
select 'cashIn' as tx_class, id, fiat, fiat_code, created, customer_id
from cash_in_txs where send_confirmed = true union
select 'cashOut' as tx_class, id, fiat, fiat_code, created, customer_id
from cash_out_txs where confirmed_at is not null) t on c.id = t.customer_id
where c.id = $1
) as cl where rn = 1`
return db.oneOrNone(sql, [id])
.then(populateOverrideUsernames)
.then(camelize)
}
/**
* @param {String} id customer id
* @param {Object} patch customer update record
@ -515,4 +573,4 @@ function updateFrontCamera (id, patch) {
})
}
module.exports = { add, get, batch, getCustomersList, getById, update, updatePhotoCard, updateFrontCamera }
module.exports = { add, get, batch, getCustomersList, getCustomerById, getById, update, updateCustomer, updatePhotoCard, updateFrontCamera }

View file

@ -2,10 +2,12 @@ const fs = require('fs')
const path = require('path')
const express = require('express')
const https = require('https')
const serveStatic = require('serve-static')
const cors = require('cors')
const helmet = require('helmet')
const cookieParser = require('cookie-parser')
const { ApolloServer, AuthenticationError } = require('apollo-server-express')
const _ = require('lodash/fp')
const T = require('../time')
const options = require('../options')
@ -15,6 +17,8 @@ const { typeDefs, resolvers } = require('./graphql/schema')
const devMode = require('minimist')(process.argv.slice(2)).dev
const NEVER = new Date(Date.now() + 100 * T.years)
const idPhotoCardBasedir = _.get('idPhotoCardDir', options)
const frontCameraBasedir = _.get('frontCameraDir', options)
const hostname = options.hostname
if (!hostname) {
@ -55,6 +59,9 @@ apolloServer.applyMiddleware({
// cors on app for /api/register endpoint.
app.use(cors({ credentials: true, origin: devMode && 'https://localhost:3000' }))
app.use('/id-card-photo', serveStatic(idPhotoCardBasedir, {index: false}))
app.use('/front-camera-photo', serveStatic(frontCameraBasedir, {index: false}))
app.get('/api/register', (req, res, next) => {
const otp = req.query.otp

View file

@ -61,8 +61,37 @@ const typeDefs = gql`
}
type Customer {
name: String
id: ID!
name: String!
authorizedOverride: String
frontCameraPath: String
phone: String
smsOverride: String
idCardData: JSONObject
idCardDataOverride: String
idCardDataExpiration: Date
idCardPhotoPath: String
idCardPhotoOverride: String
totalTxs: Int
totalSpent: String
lastActive: Date
lastTxFiat: String
lastTxFiatCode: String
lastTxClass: String
transactions: [Transaction]
}
input CustomerInput {
name: String
authorizedOverride: String
frontCameraPath: String
phone: String
smsOverride: String
idCardData: JSONObject
idCardDataOverride: String
idCardDataExpiration: Date
idCardPhotoPath: String
idCardPhotoOverride: String
totalTxs: Int
totalSpent: String
lastActive: Date
@ -160,6 +189,7 @@ const typeDefs = gql`
cryptoCurrencies: [CryptoCurrency]
machines: [Machine]
customers: [Customer]
customer(customerId: ID!): Customer
machineLogs(deviceId: ID!): [MachineLog]
funding: [CoinFunds]
serverVersion: String!
@ -187,6 +217,7 @@ const typeDefs = gql`
machineAction(deviceId:ID!, action: MachineAction!): Machine
machineSupportLogs(deviceId: ID!): SupportLogsResponse
serverSupportLogs: SupportLogsResponse
setCustomer(customerId: ID!, customerInput: CustomerInput): Customer
saveConfig(config: JSONObject): JSONObject
createPairingTotem(name: String!): String
saveAccount(account: JSONObject): [JSONObject]
@ -201,6 +232,9 @@ const resolvers = {
JSON: GraphQLJSON,
JSONObject: GraphQLJSONObject,
Date: GraphQLDateTime,
Customer: {
transactions: parent => transactions.getCustomerTransactions(parent.id)
},
Query: {
countries: () => countries,
currencies: () => currencies,
@ -209,6 +243,7 @@ const resolvers = {
cryptoCurrencies: () => coins,
machines: () => machineLoader.getMachineNames(),
customers: () => customers.getCustomersList(),
customer: (...[, { customerId }]) => customers.getCustomerById(customerId),
funding: () => funding.getFunding(),
machineLogs: (...[, { deviceId }]) => logs.simpleGetMachineLogs(deviceId),
serverVersion: () => serverVersion,
@ -225,6 +260,7 @@ const resolvers = {
serverSupportLogs: () => serverLogs.insert(),
saveAccount: (...[, { account }]) => settingsLoader.saveAccounts([account]),
saveAccounts: (...[, { accounts }]) => settingsLoader.saveAccounts(accounts),
setCustomer: (...[, { customerId, customerInput } ]) => customers.updateCustomer(customerId, customerInput),
saveConfig: (...[, { config }]) => settingsLoader.saveConfig(config)
.then(it => {
notify()

View file

@ -61,6 +61,49 @@ function batch () {
.then(packager)
}
function getCustomerTransactions (customerId) {
const packager = _.flow(_.flatten, _.orderBy(_.property('created'), ['desc']),
_.take(NUM_RESULTS), _.map(camelize), addNames)
const cashInSql = `select 'cashIn' as tx_class, txs.*,
c.phone as customer_phone,
c.id_card_data_number as customer_id_card_data_number,
c.id_card_data_expiration as customer_id_card_data_expiration,
c.id_card_data as customer_id_card_data,
c.name as customer_name,
c.front_camera_path as customer_front_camera_path,
c.id_card_photo_path as customer_id_card_photo_path,
((not txs.send_confirmed) and (txs.created <= now() - interval $2)) as expired
from cash_in_txs as txs
left outer join customers c on txs.customer_id = c.id
where c.id = $1
order by created desc limit $3`
const cashOutSql = `select 'cashOut' as tx_class,
txs.*,
actions.tx_hash,
c.phone as customer_phone,
c.id_card_data_number as customer_id_card_data_number,
c.id_card_data_expiration as customer_id_card_data_expiration,
c.id_card_data as customer_id_card_data,
c.name as customer_name,
c.front_camera_path as customer_front_camera_path,
c.id_card_photo_path as customer_id_card_photo_path,
(extract(epoch from (now() - greatest(txs.created, txs.confirmed_at))) * 1000) >= $3 as expired
from cash_out_txs txs
inner join cash_out_actions actions on txs.id = actions.tx_id
and actions.action = 'provisionAddress'
left outer join customers c on txs.customer_id = c.id
where c.id = $1
order by created desc limit $2`
return Promise.all([
db.any(cashInSql, [customerId, cashInTx.PENDING_INTERVAL, NUM_RESULTS]),
db.any(cashOutSql, [customerId, NUM_RESULTS, REDEEMABLE_AGE])
])
.then(packager)
}
function single (txId) {
const packager = _.flow(_.compact, _.map(camelize), addNames)
@ -107,4 +150,4 @@ function cancel (txId) {
.then(() => single(txId))
}
module.exports = { batch, single, cancel }
module.exports = { batch, getCustomerTransactions, single, cancel }