Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
fix: accept comma-separated status for loans
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwigoric committed Nov 24, 2023
1 parent 1ab221c commit 859c7d1
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/routes/loans.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ router.get('/', async (req, res, next) => {
if (!manager) return res.status(401).json(info)

const options = { deleted: false }
if (['approved', 'pending', 'rejected'].includes(req.query.status))
options.status = req.query.status
const optionsList = []

const loans = await Loan.find(options)
const { status } = req.query
const statuses = status.split(',')
statuses.forEach((s) => {
if (['pending', 'approved', 'released', 'rejected', 'complete'].includes(s))
optionsList.push({ ...options, status: s })
})

const loans = await Loan.find({ $or: optionsList })
.select(
'-ledger -deleted -term -approvalDate ' +
'-coborrowerName -classification -__v -_id'
Expand Down Expand Up @@ -106,18 +112,16 @@ router.get('/user/:username', async (req, res, next) => {
}

const options = { username, deleted: false }
const optionsList = []

const { status } = req.query
if (
status
.split(',')
.some((s) =>
['pending', 'approved', 'released', 'rejected', 'complete'].includes(s)
)
)
options.status = req.query.status
const statuses = status.split(',')
statuses.forEach((s) => {
if (['pending', 'approved', 'released', 'rejected', 'complete'].includes(s))
optionsList.push({ ...options, status: s })
})

const loans = await Loan.find(options).select('-__v -_id').lean()
const loans = await Loan.find({ $or: optionsList }).select('-__v -_id').lean()

parseDecimal(loans)
// Return loans
Expand Down

0 comments on commit 859c7d1

Please sign in to comment.