lamassu-server/lib/new-admin/graphql/schema.js
Liordino Neto c808ca3be9 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
2020-05-09 18:19:20 +01:00

272 lines
6.8 KiB
JavaScript

const { gql } = require('apollo-server-express')
const { GraphQLDateTime } = require('graphql-iso-date')
const { GraphQLJSON, GraphQLJSONObject } = require('graphql-type-json')
const got = require('got')
const machineLoader = require('../../machine-loader')
const customers = require('../../customers')
const { machineAction } = require('../machines')
const logs = require('../../logs')
const supportLogs = require('../../support_logs')
const settingsLoader = require('../../new-settings-loader')
const serverVersion = require('../../../package.json').version
const transactions = require('../transactions')
const funding = require('../funding')
const supervisor = require('../supervisor')
const serverLogs = require('../server-logs')
const pairing = require('../pairing')
const { accounts: accountsConfig, coins, countries, currencies, languages } = require('../config')
// TODO why does server logs messages can be null?
const typeDefs = gql`
scalar JSON
scalar JSONObject
scalar Date
type Currency {
code: String!
display: String!
}
type CryptoCurrency {
code: String!
display: String!
}
type Country {
code: String!
display: String!
}
type Language {
code: String!
display: String!
}
type MachineStatus {
label: String!
type: String!
}
type Machine {
name: String!
deviceId: ID!
paired: Boolean!
cashbox: Int
cassette1: Int
cassette2: Int
statuses: [MachineStatus]
}
type Customer {
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
lastTxFiat: String
lastTxFiatCode: String
lastTxClass: String
}
type AccountConfig {
code: String!
display: String!
class: String!
cryptos: [String]
}
type MachineLog {
id: ID!
logLevel: String!
timestamp: Date!
message: String!
}
type ServerLog {
id: ID!
logLevel: String!
timestamp: Date!
message: String
}
type CoinFunds {
cryptoCode: String!
fundingAddress: String!
fundingAddressUrl: String!
confirmedBalance: String!
pending: String!
fiatConfirmedBalance: String!
fiatPending: String!
fiatCode: String!
display: String!
unitScale: String!
}
type ProcessStatus {
name: String!
state: String!
uptime: Date!
}
type Transaction {
id: ID!
txClass: String!
deviceId: ID!
toAddress: String
cryptoAtoms: String!
cryptoCode: String!
fiat: String!
fiatCode: String!
fee: String
txHash: String
phone: String
error: String
created: Date
send: Boolean
sendConfirmed: Boolean
timedout: Boolean
sendTime: Date
errorCode: String
operatorCompleted: Boolean
sendPending: Boolean
cashInFee: String
cashInFeeCrypto: String
minimumTx: Float
customerId: ID
txVersion: Int!
termsAccepted: Boolean
commissionPercentage: String
rawTickerPrice: String
isPaperWallet: Boolean
customerPhone: String
customerIdCardDataNumber: String
customerIdCardDataExpiration: Date
customerIdCardData: JSONObject
customerName: String
customerFrontCameraPath: String
customerIdCardPhotoPath: String
expired: Boolean
machineName: String
}
type Query {
countries: [Country]
currencies: [Currency]
languages: [Language]
accountsConfig: [AccountConfig]
cryptoCurrencies: [CryptoCurrency]
machines: [Machine]
customers: [Customer]
customer(customerId: ID!): Customer
machineLogs(deviceId: ID!): [MachineLog]
funding: [CoinFunds]
serverVersion: String!
uptime: [ProcessStatus]
serverLogs: [ServerLog]
transactions: [Transaction]
accounts: [JSONObject]
config: JSONObject
}
type SupportLogsResponse {
id: ID!
timestamp: Date!
deviceId: ID
}
enum MachineAction {
resetCashOutBills
unpair
reboot
restartServices
}
type Mutation {
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]
saveAccounts(accounts: [JSONObject]): [JSONObject]
}
`
const notify = () => got.post('http://localhost:3030/dbChange')
.catch(e => console.error('Error: lamassu-server not responding'))
const resolvers = {
JSON: GraphQLJSON,
JSONObject: GraphQLJSONObject,
Date: GraphQLDateTime,
Customer: {
transactions: parent => transactions.getCustomerTransactions(parent.id)
},
Query: {
countries: () => countries,
currencies: () => currencies,
languages: () => languages,
accountsConfig: () => accountsConfig,
cryptoCurrencies: () => coins,
machines: () => machineLoader.getMachineNames(),
customers: () => customers.getCustomersList(),
customer: (...[, { customerId }]) => customers.getCustomerById(customerId),
funding: () => funding.getFunding(),
machineLogs: (...[, { deviceId }]) => logs.simpleGetMachineLogs(deviceId),
serverVersion: () => serverVersion,
uptime: () => supervisor.getAllProcessInfo(),
serverLogs: () => serverLogs.getServerLogs(),
transactions: () => transactions.batch(),
config: () => settingsLoader.getConfig(),
accounts: () => settingsLoader.getAccounts()
},
Mutation: {
machineAction: (...[, { deviceId, action }]) => machineAction({ deviceId, action }),
machineSupportLogs: (...[, { deviceId }]) => supportLogs.insert(deviceId),
createPairingTotem: (...[, { name }]) => pairing.totem(name),
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()
return it
})
}
}
module.exports = { resolvers, typeDefs }