-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
301 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { validationResult } from 'express-validator/check'; | ||
|
||
const validate_error_or_next = (req, res, next) => { | ||
const errors = validationResult(req); | ||
if (!errors.isEmpty()) { | ||
return res.status(422).json({ errors: errors.array() }); | ||
} | ||
return next(); | ||
}; | ||
|
||
export default validate_error_or_next; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { body } from 'express-validator/check'; | ||
import { sanitizeBody } from 'express-validator/filter'; | ||
import { test_logger } from '../utils/loggers'; | ||
|
||
import validate_error_or_next from './validate_error_or_next'; | ||
|
||
const LoansValidators = { | ||
validateAmount: [ | ||
body('amount') | ||
.isFloat({ min: 50000 }) | ||
.withMessage('Amount cannot be less than 50,000') | ||
.isFloat({ max: 1000000 }) | ||
.withMessage('Amount cannot be greater than 1,000,000'), | ||
sanitizeBody('amount').toFloat(), | ||
validate_error_or_next | ||
], | ||
|
||
validateRepayAmount: [ | ||
body('amount') | ||
.isFloat() | ||
.withMessage('Repayment amount must be a number'), | ||
sanitizeBody('amount').toFloat(), | ||
validate_error_or_next | ||
], | ||
|
||
validateTenor: [ | ||
body('tenor') | ||
.isInt({ min: 1 }) | ||
.withMessage('Tenor cannot be less than 1') | ||
.isInt({ max: 12 }) | ||
.withMessage('Tenor cannot be greater than 12'), | ||
sanitizeBody('tenor').toInt(), | ||
validate_error_or_next | ||
|
||
], | ||
}; | ||
|
||
export default LoansValidators; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
import dotenv from 'dotenv'; | ||
import { test_logger } from './utils/loggers'; | ||
import { dev_logger } from './utils/loggers'; | ||
|
||
dotenv.config(); | ||
|
||
const Settings = { | ||
dbSettings: () => { | ||
const activeEnvironment = process.env.NODE_ENV.trim(); | ||
const settings = { | ||
development: { | ||
databaseName: 'quick_credit', | ||
dbHost: process.env.PGHOST.trim(), | ||
dbUser: process.env.PGUSER.trim(), | ||
dbPort: process.env.PGPORT, | ||
dbPassword: process.env.PGPASSWORD.trim(), | ||
}, | ||
production: { | ||
databaseName: 'quick_credit', | ||
dbHost: process.env.PGHOST.trim(), | ||
dbUser: process.env.PGUSER.trim(), | ||
dbPort: process.env.PGPORT, | ||
dbPassword: process.env.PGPASSWORD.trim(), | ||
}, | ||
test: { | ||
databaseName: 'testdb', | ||
dbHost: process.env.PGHOST.trim(), | ||
dbUser: process.env.PGUSER.trim(), | ||
dbPort: process.env.PGPORT, | ||
dbPassword: process.env.PGPASSWORD.trim(), | ||
} | ||
let databaseName; | ||
switch (process.env.NODE_ENV.trim()) { | ||
case 'development': | ||
databaseName = 'quick_credit'; | ||
break; | ||
case 'test': | ||
databaseName = 'testdb'; | ||
break; | ||
case 'production': | ||
databaseName = 'quick_credit'; | ||
break; | ||
} | ||
|
||
const db_settings = { | ||
databaseName, | ||
dbHost: process.env.PGHOST.trim(), | ||
dbUser: process.env.PGUSER.trim(), | ||
dbPort: process.env.PGPORT, | ||
dbPassword: process.env.PGPASSWORD.trim(), | ||
}; | ||
return settings[activeEnvironment]; | ||
return db_settings; | ||
}, | ||
jwtSecret: process.env.JWT_SECRET, | ||
}; | ||
|
||
test_logger(Settings); | ||
dev_logger(Settings); | ||
export default Settings; |
Oops, something went wrong.