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

Commit

Permalink
docs: made model names uniform, added documentation to auth and db
Browse files Browse the repository at this point in the history
  • Loading branch information
kndonetm committed Nov 28, 2023
1 parent 7235e5a commit 787f07a
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 11 deletions.
36 changes: 33 additions & 3 deletions src/auth/auth.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Authorization module providing authorization-related requests
* @module auth/auth
*/

// Packages
import passport from 'passport'
import LocalStrategy from 'passport-local'
Expand All @@ -6,12 +11,22 @@ import argon2 from 'argon2'

// Schema
import Admin from '../models/admin.js'
import LoanOfficer from '../models/loan_officer.js'
import LoanOfficer from '../models/loanOfficer.js'

/**
* Configure admin login strategy
* Passport module
* @const
* @member {Object} passport
* @namespace passport-strategies
*/

/**
* Configure admin login strategy. This strategy is used to authenticate an admin.
*
* This strategy is used to authenticate an admin.
* @name admin-login
* @function
* @memberof module:auth/auth~passport-strategies
* @inner
*/
passport.use(
'admin-login',
Expand Down Expand Up @@ -46,6 +61,11 @@ passport.use(
* Configure loan officer login strategy
*
* This strategy is used to authenticate a loan officer.
*
* @name login
* @function
* @memberof module:auth/auth~passport-strategies
* @inner
*/
passport.use(
'login',
Expand Down Expand Up @@ -83,6 +103,11 @@ passport.use(
* It checks if the username is already taken and if not,
* creates a new loan officer. The admin must be logged in
* to use this strategy.
*
* @name admin
* @function
* @memberof module:auth/auth~passport-strategies
* @inner
*/
passport.use(
'admin',
Expand Down Expand Up @@ -112,6 +137,11 @@ passport.use(
* This strategy is used to authenticate an admin or a loan officer using a JWT.
* JWT authentication is used to protect endpoints that require
* authentication of either an admin or a loan officer.
*
* @name is-manager
* @function
* @memberof module:auth/auth~passport-strategies
* @inner
*/
passport.use(
'is-manager',
Expand Down
8 changes: 8 additions & 0 deletions src/db/conn.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
/**
* Module for managing connections to and from the database.
* @module db/conn
*/

import mongoose from 'mongoose'

// Default MongoDB URI
import { DEFAULT_MONGODB_URI } from './default_uri.js'

/**
* @class
*/
class Database {
/**
* Initialize the database connection
Expand Down
10 changes: 10 additions & 0 deletions src/db/default_uri.js
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
/**
* Module for storing the default URI of the MongoDB instance. Primarily used for testing.
* @module db/default_uri
*/

/**
* Default MongoDB URI
* This is the MongoDB URI that is used if the MONGODB_URI environment variable is not set in .env
* @const
*/
export const DEFAULT_MONGODB_URI = 'mongodb://localhost:27017/unboundmnl-problem-area-2'
12 changes: 12 additions & 0 deletions src/models/admin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
/**
* Database model for Admins
* @module models/admin
*/

// Import packages
import { Schema, model } from 'mongoose'
import argon2 from 'argon2'
import { v5 as uuidV5, validate as uuidValidate, version as uuidVersion } from 'uuid'

/**
* @name Admin
* @class
* @param {string} username - Username of administrators
* @param {string} password_hash - Hashed password of administrators
* @param {string} id - UUID of administrators (automatically generated on creation)
*/
const Admin = model(
'Admin',
new Schema({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Database model for Deposit Settings
*/

// Packages
import { Schema, model } from 'mongoose'

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import argon2 from 'argon2'
const router = express.Router()

// Import models
import LoanOfficer from '../models/loan_officer.js'
import LoanOfficer from '../models/loanOfficer.js'

/**
* POST /login
Expand Down
2 changes: 1 addition & 1 deletion src/routes/deposits.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const router = Router()
// Import models
import Loanee from '../models/loanee.js'
import Deposit from '../models/deposit.js'
import DepositSettings from '../models/deposit_settings.js'
import DepositSettings from '../models/depositSettings.js'

// Ledger routes
import ledgerRouter from './deposit-ledgers.js'
Expand Down
2 changes: 1 addition & 1 deletion src/routes/loans.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const router = Router()
// Import models
import Loan from '../models/loan.js'
import Loanee from '../models/loanee.js'
import LoanSettings from '../models/loan_settings.js'
import LoanSettings from '../models/loanSettings.js'

// Ledger routes
import ledgerRouter from './loan-ledgers.js'
Expand Down
2 changes: 1 addition & 1 deletion src/routes/officers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import passport from 'passport'
import argon2 from 'argon2'

// Import models
import LoanOfficer from '../models/loan_officer.js'
import LoanOfficer from '../models/loanOfficer.js'
import Admin from '../models/admin.js'

// Create router
Expand Down
4 changes: 2 additions & 2 deletions src/routes/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Router } from 'express'
import passport from 'passport'

// Schema
import LoanSettings from '../models/loan_settings.js'
import DepositSettings from '../models/deposit_settings.js'
import LoanSettings from '../models/loanSettings.js'
import DepositSettings from '../models/depositSettings.js'
import NotificationSettings from '../models/notificationSettings.js'

// Initialize router
Expand Down
2 changes: 1 addition & 1 deletion src/schedules/jobs/deposit-interests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Deposit from '../../models/deposit.js'
import DepositSettings from '../../models/deposit_settings.js'
import DepositSettings from '../../models/depositSettings.js'
import Decimal from 'decimal.js'

import moment from 'moment'
Expand Down
2 changes: 1 addition & 1 deletion src/schedules/jobs/loan-interests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Loan from '../../models/loan.js'
import LoanSettings from '../../models/loan_settings.js'
import LoanSettings from '../../models/loanSettings.js'
import Decimal from 'decimal.js'

import moment from 'moment'
Expand Down

0 comments on commit 787f07a

Please sign in to comment.