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

Commit

Permalink
refator: adjust ledgers to match frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
kndonetm committed Nov 15, 2023
1 parent a05a12c commit 49aead0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
38 changes: 24 additions & 14 deletions src/models/depositTransactionSchema.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Import packages
import { Schema } from 'mongoose'

import NameSchema from './nameSchema.js'

const DepositTransactionSchema = new Schema({
transactionID: {
type: String,
Expand All @@ -10,33 +12,41 @@ const DepositTransactionSchema = new Schema({
},
ORNumber: {
type: String,
required: true,
immutable: true
required: true
},
transactionDate: {
type: Date,
required: true,
immutable: true
required: true
},
amountReceived: {
type: Number,
submissionDate: {
type: Date,
required: true
},
depositType: {
type: String,
required: true,
immutable: true
validate: {
validator: (val) => {
return 'deposit', 'withdrawal'.includes(val)
},
message: 'Deposit Type must be either "deposit" or "withdrawal"'
}
},
amountWithdrawn: {
amount: {
type: Number,
required: true,
immutable: true
required: true
},
interest: {
type: Number,
required: true,
immutable: true
required: true
},
balance: {
type: Number,
required: true,
immutable: true
required: true
},
officerInCharge: {
type: NameSchema,
required: true
}
})

Expand Down
2 changes: 1 addition & 1 deletion src/models/loanTransactionSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const LoanTransactionSchema = new Schema({
type: String,
required: true
},
paymentDate: {
transactionDate: {
type: Date,
required: true
},
Expand Down
9 changes: 7 additions & 2 deletions src/routes/deposit-ledgers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ router.get('/', async (req, res, next) => {

const { depositID } = req

const deposit = await Deposit.find({ deleted: false, depositID }).select('-__v -_id').lean()
const deposit = await Deposit.findOne({ deleted: false, depositID })
.select('-__v -_id')
.lean()

if (!deposit) return res.status(404).json({ error: true, message: 'Deposit not found' })

Expand Down Expand Up @@ -82,7 +84,10 @@ router.put('/', async (req, res, next) => {
const { ledger } = deposit

// Add transaction to ledger
ledger.push(req.body)
ledger.push({
...req.body,
transactionID: Date.now().toString(36).toUpperCase()
})

try {
// Update deposit
Expand Down
2 changes: 1 addition & 1 deletion src/routes/loan-ledgers.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ router.patch('/:txID', (req, res, next) => {

const query = {
'ledger.$.ORNumber': req.body.ORNumber,
'ledger.$.paymentDate': req.body.paymentDate,
'ledger.$.transactionDate': req.body.transactionDate,
'ledger.$.submissionDate': req.body.submissionDate,
'ledger.$.amountPaid': req.body.amountPaid,
'ledger.$.balance': req.body.balance,
Expand Down

0 comments on commit 49aead0

Please sign in to comment.