From 6735408cd54d5d78f07c3cdf7c1e5e5c43c53aee Mon Sep 17 00:00:00 2001 From: kndone Date: Thu, 30 Nov 2023 00:47:36 +0800 Subject: [PATCH] chore: revert to before the deploy broke --- src/models/loan.js | 2 +- src/routes/auth.js | 5 ----- src/routes/deposit-ledgers.js | 20 ++---------------- src/routes/deposits.js | 39 ++++++++++++----------------------- src/routes/loan-ledgers.js | 24 ++------------------- src/routes/loans.js | 39 ++++++++++++++--------------------- 6 files changed, 33 insertions(+), 96 deletions(-) diff --git a/src/models/loan.js b/src/models/loan.js index d3948fe..51d98ef 100644 --- a/src/models/loan.js +++ b/src/models/loan.js @@ -145,7 +145,7 @@ LoanSchema.pre('save', function (next) { * @prop {Date} releaseDate - Date when the loan cash was released to the loanee. * @prop {Date} nextInterestDate - When the loan will next gain interest. * @prop {Boolean} isPaidForCurrentPeriod - Whether or not the loan is already paid for the current payment period. - * @prop {Object} coborrower - Loan coborrower. Contains the `name` (NameSchema), `birthday` (Date), `occupation`, and `contact_no` (both Strings) of the coborrower. + * @prop {Object} coborrower - Loan coborrower. Contains the name (NameSchema), birthday (Date), occupation, and contact number (both Strings) of the coborrower. * @prop {mongoose.Decimal128} originalLoanAmount - Original amount loaned. * @prop {LoanTransactionSchema[]} ledger - List of transactions making up the loan. * @prop {String} status - Status of the loan. Must be "pending", "approved", "released", "rejected", or "complete". diff --git a/src/routes/auth.js b/src/routes/auth.js index dead74f..f083aed 100644 --- a/src/routes/auth.js +++ b/src/routes/auth.js @@ -69,11 +69,6 @@ router.post('/login', (req, res, next) => { * @function * @memberof module:routes/auth~router-auth * @inner - * - * @param {String} username - Officer's username for account logins. - * @param {String} password - Password of officer for account logins. - * @param {NameSchema} name - Officer's name. An object that follows the `nameSchema` schema. - * @param {String} role - Officer's role. Can either be "manager", "treasurer", or "credit committee". */ router.post('/register-officer', (req, res, next) => { passport.authenticate('admin', { session: false }, async (err, admin, info) => { diff --git a/src/routes/deposit-ledgers.js b/src/routes/deposit-ledgers.js index 428eabd..4701a2b 100644 --- a/src/routes/deposit-ledgers.js +++ b/src/routes/deposit-ledgers.js @@ -95,7 +95,7 @@ router.get('/:txID', async (req, res, next) => { /** * PUT / * - * Create a new transaction under this deposit. Also updates the deposit's balance accordingly. + * Create a new transaction under this deposit. req.body must be a valid document following the . * * Request body must be a JSON object containing the fields specified in the `parameters` section. * @@ -103,14 +103,6 @@ router.get('/:txID', async (req, res, next) => { * @function * @memberof module:routes/deposit-ledgers~router-deposit-ledgers * @inner - * @param {String} ORNumber - Deposit OR number. Manually inputted, duplicates are allowed. - * @param {Date} transactionDate - Date the transaction was made. - * @param {Date} submissionDate - Date the transaction was submitted to the system. - * @param {String} transactionType - Type of transaction. Must be either 'Deposit' or 'Withdrawal'. - * @param {mongoose.Decimal128} amount - Amount paid during transaction. - * @param {mongoose.Decimal128} interest - Interest gained during transaction. Separate transactions are made every time interest is calculated. - * @param {mongoose.Decimal128} balance - Remaining balance in the deposit account after transaction. - * @param {NameSchema} officerInCharge - Name of the officer in charge of the transaction. Object following the `NameSchema` schema. */ router.put('/', async (req, res, next) => { passport.authenticate('is-manager', { session: false }, async (err, manager, info) => { @@ -157,22 +149,14 @@ router.put('/', async (req, res, next) => { /** * PATCH /:txID * - * Update a transaction in this deposit. + * Update a transaction. * * Request body must be a JSON object containing the fields specified in the `parameters` section. - * txID is the transaction ID of the deposit. * * @name patch/:txID * @function * @memberof module:routes/deposit-ledgers~router-deposit-ledgers * @inner - * @param {String} ORNumber - Deposit OR number. Manually inputted, duplicates are allowed. - * @param {Date} transactionDate - Date the transaction was made. - * @param {Date} submissionDate - Date the transaction was submitted to the system. - * @param {mongoose.Decimal128} amount - Amount paid during transaction. - * @param {mongoose.Decimal128} interest - Interest gained during transaction. Separate transactions are made every time interest is calculated. - * @param {mongoose.Decimal128} balance - Remaining balance in the deposit account after transaction. - * @param {NameSchema} officerInCharge - Name of the officer in charge of the transaction. */ router.patch('/:txID', async (req, res, next) => { passport.authenticate('is-manager', { session: false }, async (err, manager, info) => { diff --git a/src/routes/deposits.js b/src/routes/deposits.js index 2332888..847c9eb 100644 --- a/src/routes/deposits.js +++ b/src/routes/deposits.js @@ -61,13 +61,7 @@ router.get('/', async (req, res, next) => { /** * GET /get/:depositid * - * Get a deposit given its deposit ID. - * depositID is the ID of the deposit. - * - * @name get/:depositid - * @function - * @memberof module:routes/deposits~router-deposits - * @inner + * Get a deposit given its deposit ID */ router.get('/:depositID', async (req, res, next) => { passport.authenticate('is-manager', { session: false }, async (err, manager, info) => { @@ -90,9 +84,7 @@ router.get('/:depositID', async (req, res, next) => { /** * GET /:username * - * Get all deposits of a member given their username. - * username is the username to search by. - * + * Get all deposits of a member given their username * @name get/:username * @function * @memberof module:routes/deposits~router-deposits @@ -129,21 +121,15 @@ router.get('/user/:username', async (req, res, next) => { /** * PUT /:username * - * Create a new deposit of a member given their username. + * Create a new deposit of a member given their username * - * Request body must be a JSON object containing the fields specified in the `parameters` section. - * username is the username of the member that owns the deposit. * + * + * Request body must be a JSON object containing the fields specified in the `parameters` section. * @name put/:username * @function * @memberof module:routes/deposits~router-deposits * @inner - * - * @param {String} username - Username of the user that owns this deposit. - * @param {Date} approvalDate - Date the deposit was approved. - * @param {mongoose.Decimal128} originalDepositAmount - Original amount that was deposited. - * @param {String} status - Current deposit status. One of 'pending', 'accepted', 'rejected', or 'complete'. - * @param {String} category - Deposit category. One of 'shareCapital', 'savings', or 'timeDeposit'. */ router.put('/user/:username', async (req, res, next) => { passport.authenticate('is-manager', { session: false }, async (err, manager, info) => { @@ -160,6 +146,8 @@ router.put('/user/:username', async (req, res, next) => { const submissionDate = Date.now() + console.log(req.body.category) + const allSettings = await DepositSettings.findOne().lean() if (!allSettings[req.body.category]) { return res.status(400).json({ @@ -219,19 +207,16 @@ router.put('/user/:username', async (req, res, next) => { /** * PATCH /:depositID * - * Edit a deposit (except the deposit's ledger). + * Edit a deposit * - * depositID represents the ID of the deposit to edit. + * req.body contains the data of the deposit to edit. Finds a deposit in the database using depositID. + * NOTE: Does not edit deposit IDs. * * Request body must be a JSON object containing the fields specified in the `parameters` section. * @name patch/:depositID * @function * @memberof module:routes/deposits~router-deposits * @inner - * - * @param {mongoose.Decimal128} originalDepositAmount - Original amount that was deposited. - * @param {String} status - Current deposit status. One of 'pending', 'accepted', 'rejected', or 'complete'. - * @param {String} category - Deposit category. One of 'shareCapital', 'savings', or 'timeDeposit'. */ router.patch('/:depositID', async (req, res, next) => { passport.authenticate('is-manager', { session: false }, async (err, manager, info) => { @@ -273,7 +258,9 @@ router.patch('/:depositID', async (req, res, next) => { /** * DELETE /:depositID * - * Marks a deposit as deleted. + * Delete a deposit. + * + * This functionality only soft deletes the deposit. * * Request body must be a JSON object containing the fields specified in the `parameters` section. * diff --git a/src/routes/loan-ledgers.js b/src/routes/loan-ledgers.js index 4393ce8..a6852f7 100644 --- a/src/routes/loan-ledgers.js +++ b/src/routes/loan-ledgers.js @@ -93,7 +93,7 @@ router.get('/:txID', (req, res, next) => { /** * PUT / * - * Create a new transaction. Also updates the loan's outstanding balance. + * Create a new transaction * * Request body must be a JSON object containing the fields specified in the `parameters` section. * @@ -101,17 +101,6 @@ router.get('/:txID', (req, res, next) => { * @function * @memberof module:routes/loan-ledgers~router-loan-ledgers * @inner - * - * @param {String} ORNumber - OR number of transaction. Does not have to be unique. - * @param {Date} transactionDate - Date the transaction was made. - * @param {mongoose.Decimal128} amountPaid - Amount paid during transaction. - * @param {mongoose.Decimal128} amountDue - Other amounts due in this transaction outside of interests or fines. - * @param {mongoose.Decimal128} balance - Outstanding loan balance after transaction. - * @param {mongoose.Decimal128} interestPaid - Amount of interest paid during transaction. - * @param {mongoose.Decimal128} interestDue - Amount of interest added to the loan during transaction. - * @param {mongoose.Decimal128} finesDue - Amount of fines paid during transaction. - * @param {mongoose.Decimal128} finesPaid - Amount of fines added to the loan during transaction. - * @param {NameSchema} officerInCharge - Name of the officer in charge of the transaction. */ router.put('/', (req, res, next) => { passport.authenticate('is-manager', { session: false }, async (err, manager, info) => { @@ -173,7 +162,7 @@ router.put('/', (req, res, next) => { /** * PATCH /:txID * - * Update a transaction. txID is the ID of the transaction to update. + * Update a transaction * * Request body must be a JSON object containing the fields specified in the `parameters` section. * @@ -181,15 +170,6 @@ router.put('/', (req, res, next) => { * @function * @memberof module:routes/loan-ledgers~router-loan-ledgers * @inner - * - * @param {String} ORNumber - OR number of transaction. Does not have to be unique. - * @param {Date} transactionDate - Date the transaction was made. - * @param {Date} submissionDate - Date the transaction was submitted to the system. - * @param {mongoose.Decimal128} amountPaid - Amount paid during transaction. - * @param {mongoose.Decimal128} balance - Outstanding loan balance after transaction. - * @param {mongoose.Decimal128} interestPaid - Amount of interest paid during transaction. - * @param {mongoose.Decimal128} finesPaid - Amount of fines added to the loan during transaction. - * @param {NameSchema} officerInCharge - Name of the officer in charge of the transaction. */ router.patch('/:txID', (req, res, next) => { passport.authenticate('is-manager', { session: false }, async (err, manager, info) => { diff --git a/src/routes/loans.js b/src/routes/loans.js index 678d0b6..454ee08 100644 --- a/src/routes/loans.js +++ b/src/routes/loans.js @@ -40,7 +40,7 @@ router.use( /** * GET / * - * Get all loans. + * Get all loans * * @name get * @function @@ -81,8 +81,7 @@ router.get('/', async (req, res, next) => { /** * GET /:loanID * - * Get a loan given its loan ID. - * + * Get a loan given its loan ID * @name get * @function * @memberof module:routes/loans~router-loans @@ -122,7 +121,7 @@ router.get('/:loanID', async (req, res, next) => { /** * GET /user/:username * - * Get all loans for a loanee given their username. + * Get all loans for a loanee given their username * @name get/user/:username * @function * @memberof module:routes/loans~router-loans @@ -167,7 +166,7 @@ router.get('/user/:username', async (req, res, next) => { /** * PUT /user/:username * - * Create a new loan application for a loanee. + * Create a new loan application for a loanee * * Request body must be a JSON object containing the fields specified in the `parameters` section. * @@ -175,15 +174,6 @@ router.get('/user/:username', async (req, res, next) => { * @function * @memberof module:routes/loans~router-loans * @inner - * - * @param {String} username - Username of the loanee. - * @param {String} loanType - Type of loan. Can be "emergency", "multipurpose", "educational", "pettyCash", "commercial", or "livelihood". - * @param {Number} term - Term of the loan. How many payments are to be made to complete the loan. - * @param {String} paymentFrequency - How often payments are made for the loan. - * @param {Object} coborrower - Loan coborrower. Contains the `name` (NameSchema), `birthday` (Date), `occupation`, and `contact_no` (both Strings) of the coborrower. - * @param {mongoose.Decimal128} amount - Original amount loaned. - * @param {String} status - Status of the loan. Must be "pending", "approved", "released", "rejected", or "complete". - * @param {String} classification - Classification of the loan. Must be "new" or "renewal". */ router.put('/user/:username', async (req, res, next) => { passport.authenticate('is-manager', { session: false }, async (err, manager, info) => { @@ -246,9 +236,17 @@ router.put('/user/:username', async (req, res, next) => { /** * POST /:loanID/review * - * Approve or reject a loan application, then automatically insert a transaction for initial deductions if approved. + * Approve or reject a loan application * - * loanID is the loan ID to review. + * req.body must be of the form: + * { + * approved: boolean + * oic: { + * last: + * middle: + * first: + * } + * } * * Request body must be a JSON object containing the fields specified in the `parameters` section. * @@ -256,8 +254,6 @@ router.put('/user/:username', async (req, res, next) => { * @function * @memberof module:routes/loans~router-loans * @inner - * @param {boolean} approved - Whether or not the loan is approved. Value is true if approved, and false if rejected. - * @param {NameSchema} oic - The name of the officer in charge of the review. Is an object that follows the NameSchema. */ router.post('/:loanID/review', async (req, res, next) => { passport.authenticate('is-manager', { session: false }, async (err, manager, info) => { @@ -378,11 +374,6 @@ router.post('/:loanID/review', async (req, res, next) => { * @function * @memberof module:routes/loans~router-loans * @inner - * - * @param {String} loanType - Type of loan. Can be "emergency", "multipurpose", "educational", "pettyCash", "commercial", or "livelihood". - * @param {Number} term - Term of the loan. How many payments are to be made to complete the loan. - * @param {String} paymentFrequency - How often payments are made for the loan. - * @param {Object} coborrower - Loan coborrower. Contains the `name` (NameSchema), `birthday` (Date), `occupation`, and `contact_no` (both Strings) of the coborrower. */ router.patch('/:loanID', async (req, res, next) => { passport.authenticate('is-manager', { session: false }, async (err, manager, info) => { @@ -482,7 +473,7 @@ router.patch('/:loanID', async (req, res, next) => { * the deleted loan will still be visible in the database * * Request body must be a JSON object containing the fields specified in the `parameters` section. - * + * * @name delete/:loanID * @function * @memberof module:routes/loans~router-loans