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

Commit

Permalink
Browse files Browse the repository at this point in the history
…a-2-server into Sprint-4
  • Loading branch information
kndonetm committed Nov 23, 2023
2 parents 9a5826c + 6c97fa3 commit 1bda438
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"agenda": "^5.0.0",
"argon2": "0.30.3",
"argon2": "0.31.2",
"cookie-parser": "~1.4.6",
"cors": "^2.8.5",
"debug": "~4.3.4",
Expand Down
7 changes: 7 additions & 0 deletions src/models/loan.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ const LoanSchema = new Schema({
dueDate: {
type: Date
},
releaseDate: {
type: Date
},
isPaidForCurrentPeriod: {
type: Boolean,
default: false
},
coborrower: {
name: NameSchema,
birthday: Date,
Expand Down
44 changes: 23 additions & 21 deletions src/routes/loans.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,31 +321,33 @@ router.patch('/:loanID', async (req, res, next) => {
const { loanID } = req.params

const existingLoan = await Loan.findOne({ loanID })
if (!existingLoan) {
if (!existingLoan)
return res.status(404).json({ message: 'Loan application does not exist' })
} else {
// Do not edit loan ledgers, loan IDs, submission dates, or approval dates.
const loanInfo = { ...req.body }
if (loanInfo.ledger) {
delete loanInfo.ledger
}
delete loanInfo.loanID
delete loanInfo.submissionDate
delete loanInfo.approvalDate
delete loanInfo.originalLoanAmount

if (
Object.entries(loanInfo.coborrower.name).every(([, val]) => {
return val === '' || val === null
})
) {
loanInfo.coborrower = null
}

await Loan.updateOne({ loanID }, loanInfo, { runValidators: true })
// Do not edit loan ledgers, loan IDs, submission dates, or approval dates.
const loanInfo = { ...req.body }
if (loanInfo.ledger) {
delete loanInfo.ledger
}
delete loanInfo.loanID
delete loanInfo.submissionDate
delete loanInfo.approvalDate
delete loanInfo.originalLoanAmount

if (existingLoan.status === 'approved' && loanInfo.status === 'released')
loanInfo.releaseDate = Date.now()

return res.json({ message: 'Loan application successfully edited', error: false })
if (
Object.entries(loanInfo.coborrower.name).every(([, val]) => {
return val === '' || val === null
})
) {
loanInfo.coborrower = null
}

await Loan.updateOne({ loanID }, loanInfo, { runValidators: true })

return res.json({ message: 'Loan application successfully edited', error: false })
} catch (error) {
if (error.name === 'ValidationError') {
return res.status(400).json({
Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ __metadata:
languageName: node
linkType: hard

"@mapbox/node-pre-gyp@npm:^1.0.10":
"@mapbox/node-pre-gyp@npm:^1.0.11":
version: 1.0.11
resolution: "@mapbox/node-pre-gyp@npm:1.0.11"
dependencies:
Expand Down Expand Up @@ -1382,14 +1382,14 @@ __metadata:
languageName: node
linkType: hard

"argon2@npm:0.30.3":
version: 0.30.3
resolution: "argon2@npm:0.30.3"
"argon2@npm:0.31.2":
version: 0.31.2
resolution: "argon2@npm:0.31.2"
dependencies:
"@mapbox/node-pre-gyp": "npm:^1.0.10"
"@mapbox/node-pre-gyp": "npm:^1.0.11"
"@phc/format": "npm:^1.0.0"
node-addon-api: "npm:^5.0.0"
checksum: af617195c75562a40cdad3043128c472b041cc20a97b0441ca479938d2fcda1165d5035033175c1857b94aa8a1abb46e6413b23265f2507890f7309e4e406b8e
node-addon-api: "npm:^7.0.0"
checksum: 017165bc2da279fadbaedf955297db933944d7669ec0d3333579ed7f561c98b74474b46fb546e740b844ee5f4a902ca2e845487a90a1ef44a3f7928d4f18133f
languageName: node
linkType: hard

Expand Down Expand Up @@ -3659,12 +3659,12 @@ __metadata:
languageName: node
linkType: hard

"node-addon-api@npm:^5.0.0":
version: 5.1.0
resolution: "node-addon-api@npm:5.1.0"
"node-addon-api@npm:^7.0.0":
version: 7.0.0
resolution: "node-addon-api@npm:7.0.0"
dependencies:
node-gyp: "npm:latest"
checksum: 595f59ffb4630564f587c502119cbd980d302e482781021f3b479f5fc7e41cf8f2f7280fdc2795f32d148e4f3259bd15043c52d4a3442796aa6f1ae97b959636
checksum: f1a54ae38f6cbd4cdfe69d1b2f3f0c4a3d227eb50f5073f0a3b985d29a0c39c94b82c88213e5075ee1bc262f2e869841c733ebe7111a5e376f1732649edf6a93
languageName: node
linkType: hard

Expand Down Expand Up @@ -4766,7 +4766,7 @@ __metadata:
dependencies:
"@rushstack/eslint-patch": "npm:^1.6.0"
agenda: "npm:^5.0.0"
argon2: "npm:0.30.3"
argon2: "npm:0.31.2"
cookie-parser: "npm:~1.4.6"
cors: "npm:^2.8.5"
debug: "npm:~4.3.4"
Expand Down

0 comments on commit 1bda438

Please sign in to comment.