Skip to content

Commit

Permalink
Merge pull request #1761 from siiky/chore/lam-1241/customer-routes
Browse files Browse the repository at this point in the history
LAM-1244 refactor: don't send transactions' `expired` field
  • Loading branch information
RafaelTaranto authored Nov 29, 2024
2 parents 38e6ae6 + 9d4808a commit 89ec3d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
15 changes: 15 additions & 0 deletions lib/middlewares/addRWBytes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const addRWBytes = () => (req, res, next) => {
const handle = () => {
res.removeListener('finish', handle)
res.removeListener('close', handle)
res.bytesRead = req.connection.bytesRead
res.bytesWritten = req.connection.bytesWritten
}

res.on('finish', handle)
res.on('close', handle)

next()
}

module.exports = addRWBytes
9 changes: 7 additions & 2 deletions lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ const nocache = require('nocache')

const logger = require('./logger')

const addRWBytes = require('./middlewares/addRWBytes')
const authorize = require('./middlewares/authorize')
const computeSchema = require('./middlewares/compute-schema')
const errorHandler = require('./middlewares/errorHandler')
const filterOldRequests = require('./middlewares/filterOldRequests')
const computeSchema = require('./middlewares/compute-schema')
const findOperatorId = require('./middlewares/operatorId')
const populateDeviceId = require('./middlewares/populateDeviceId')
const populateSettings = require('./middlewares/populateSettings')
Expand Down Expand Up @@ -50,11 +51,15 @@ const configRequiredRoutes = [
]

// middleware setup
app.use(addRWBytes())
app.use(compression({ threshold: 500 }))
app.use(helmet())
app.use(nocache())
app.use(express.json({ limit: '2mb' }))
app.use(morgan(':method :url :status :response-time ms -- :req[content-length]/:res[content-length] b', { stream: logger.stream }))

morgan.token('bytesRead', (_req, res) => res.bytesRead)
morgan.token('bytesWritten', (_req, res) => res.bytesWritten)
app.use(morgan(':method :url :status :response-time ms -- :bytesRead/:bytesWritten B', { stream: logger.stream }))

// app /pair and /ca routes
app.use('/', pairingRoutes)
Expand Down
2 changes: 1 addition & 1 deletion lib/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function cancel (txId) {
}

function customerHistory (customerId, thresholdDays) {
const sql = `SELECT * FROM (
const sql = `SELECT ch.id, ch.created, ch.fiat, ch.direction FROM (
SELECT txIn.id, txIn.created, txIn.fiat, 'cashIn' AS direction,
((NOT txIn.send_confirmed) AND (txIn.created <= now() - interval $3)) AS expired
FROM cash_in_txs txIn
Expand Down

0 comments on commit 89ec3d4

Please sign in to comment.