-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feedback fixes Seperate migration from database, write more test cases, write comments with jsdocs, make login and signup form in one, added more eslint configurations, fix auth to have prefix v1, fix eslint disable, fix codeclimate badge, fix on delete error, make initial account draft on creation, fix whitespace on signup form [Starts #165546870]
- Loading branch information
Showing
34 changed files
with
3,053 additions
and
1,843 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,43 @@ | ||
module.exports = { | ||
"extends": "airbnb-base" | ||
}; | ||
"extends": "airbnb-base", | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"jquery": true, | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"one-var": 0, | ||
"one-var-declaration-per-line": 0, | ||
"new-cap": 0, | ||
"consistent-return": 0, | ||
"no-param-reassign": 0, | ||
"comma-dangle": 0, | ||
"curly": ["error", "multi-line"], | ||
"import/no-unresolved": [2, { | ||
"commonjs": true | ||
}], | ||
"no-shadow": ["error", { | ||
"allow": ["req", "res", "err"] | ||
}], | ||
"valid-jsdoc": ["error", { | ||
"requireReturn": true, | ||
"requireReturnType": true, | ||
"requireParamDescription": false, | ||
"requireReturnDescription": true | ||
}], | ||
"require-jsdoc": ["error", { | ||
"require": { | ||
"FunctionDeclaration": true, | ||
"MethodDefinition": true, | ||
"ClassDeclaration": true | ||
} | ||
}], | ||
"max-len": ["error", { "code": 80 }], | ||
"linebreak-style": [ | ||
"error", | ||
"windows" | ||
] | ||
} | ||
}; |
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
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,47 +1,45 @@ | ||
import express from 'express'; | ||
import bodyParser from 'body-parser'; | ||
import cors from 'cors'; | ||
import debug from 'debug'; | ||
import swaggerUi from 'swagger-ui-express'; | ||
import dbConnection from './config/database'; | ||
import swaggerDocument from '../swagger'; | ||
import RegisterRoute from './routes/register'; | ||
import LoginRoute from './routes/login'; | ||
import CreateAccountRoute from './routes/createAccount'; | ||
import TransactionRoute from './routes/transaction'; | ||
import UsersRoute from './routes/users'; | ||
import jwtMiddleware from './middleware/jwt'; | ||
|
||
// instantiate expressjs | ||
const app = express(); | ||
const PORT = process.env.PORT || 5100; | ||
|
||
app.use(cors()); | ||
|
||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
|
||
// swagger | ||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); | ||
|
||
// creating database tables | ||
dbConnection.createTable(); | ||
|
||
// Index Route | ||
app.get('/', (req, res) => { | ||
res.send('welcome to Banka API'); | ||
}); | ||
|
||
// creating the api version route | ||
app.use('/api/auth/signup', RegisterRoute); | ||
app.use('/api/auth/signin', LoginRoute); | ||
app.use('/api/v1/accounts', jwtMiddleware.checkToken, CreateAccountRoute); | ||
app.use('/api/v1/transactions', jwtMiddleware.checkToken, TransactionRoute); | ||
app.use('/api/v1/users', jwtMiddleware.checkToken, UsersRoute); | ||
|
||
// listening to our port | ||
app.listen(PORT, () => { | ||
debug('server')(`server running on port: ${PORT}`); | ||
}); | ||
|
||
export default app; | ||
import express from 'express'; | ||
import bodyParser from 'body-parser'; | ||
import cors from 'cors'; | ||
import debug from 'debug'; | ||
import swaggerUi from 'swagger-ui-express'; | ||
import migration from './config/migration'; | ||
import swaggerDocument from '../swagger'; | ||
import AuthRoute from './routes/auth'; | ||
import CreateAccountRoute from './routes/accounts'; | ||
import TransactionRoute from './routes/transaction'; | ||
import UsersRoute from './routes/users'; | ||
import jwtMiddleware from './middleware/jwt'; | ||
|
||
// instantiate expressjs | ||
const app = express(); | ||
const PORT = process.env.PORT || 5100; | ||
|
||
app.use(cors()); | ||
|
||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
|
||
// swagger | ||
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument)); | ||
|
||
// creating database tables | ||
migration.createTable(); | ||
|
||
// Index Route | ||
app.get('/', (req, res) => { | ||
res.send('welcome to Banka API'); | ||
}); | ||
|
||
// creating the api version route | ||
app.use('/api/v1/auth', AuthRoute); | ||
app.use('/api/v1/accounts', jwtMiddleware.checkToken, CreateAccountRoute); | ||
app.use('/api/v1/transactions', jwtMiddleware.checkToken, TransactionRoute); | ||
app.use('/api/v1/users', jwtMiddleware.checkToken, UsersRoute); | ||
|
||
// listening to our port | ||
app.listen(PORT, () => { | ||
debug('server')(`server running on port: ${PORT}`); | ||
}); | ||
|
||
export default app; |
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,107 +1,61 @@ | ||
import { Pool } from 'pg'; | ||
import debug from 'debug'; | ||
import dotenv from 'dotenv'; | ||
import { parse } from 'pg-connection-string'; | ||
|
||
dotenv.config(); | ||
|
||
let conString; | ||
|
||
if (process.env.HEROKU_ACCESS === 'heroku_access') { | ||
conString = parse(process.env.BANKA_DB); | ||
} else { | ||
conString = parse(process.env.DB_CONFIG); | ||
} | ||
|
||
const pool = new Pool(conString); | ||
|
||
const dbConnection = { | ||
async createTable() { | ||
const users = | ||
`CREATE TABLE IF NOT EXISTS | ||
users ( | ||
id SERIAL PRIMARY KEY UNIQUE, | ||
email VARCHAR(80) UNIQUE, | ||
firstName VARCHAR(20), | ||
lastName VARCHAR(20), | ||
password VARCHAR(80), | ||
type VARCHAR(10), | ||
isAdmin BOOLEAN | ||
)`; | ||
|
||
const accounts = | ||
`CREATE TABLE IF NOT EXISTS | ||
accounts ( | ||
id SERIAL PRIMARY KEY UNIQUE, | ||
email VARCHAR(80), | ||
firstName VARCHAR(20), | ||
lastName VARCHAR(20), | ||
accountNumber BIGINT UNIQUE, | ||
createdOn VARCHAR(40), | ||
owner INTEGER, | ||
type VARCHAR(10), | ||
status VARCHAR(10), | ||
balance FLOAT | ||
)`; | ||
|
||
const transactions = | ||
`CREATE TABLE IF NOT EXISTS | ||
transactions ( | ||
id SERIAL PRIMARY KEY UNIQUE, | ||
createdOn VARCHAR(40), | ||
type VARCHAR(10), | ||
accountNumber BIGINT, | ||
cashier INTEGER, | ||
amount FLOAT, | ||
oldBalance FLOAT, | ||
newBalance FLOAT | ||
)`; | ||
|
||
try { | ||
return (async () => { | ||
const client = await pool.connect(); | ||
try { | ||
await client.query(users); | ||
await client.query(accounts); | ||
await client.query(transactions); | ||
await client.query('INSERT into users(email, firstName, lastName, password, type, isAdmin) values($1, $2, $3, $4, $5, $6)', | ||
['admin@banka.com', 'cavdy', 'admin', process.env.ADMIN_PWD, 'staff', true]); | ||
} finally { | ||
client.release(); | ||
} | ||
})(); | ||
} catch (e) { | ||
return debug('query')(e.stack); | ||
} | ||
}, | ||
async dbConnect(passedQuery, passedData) { | ||
try { | ||
return (async () => { | ||
const client = await pool.connect(); | ||
try { | ||
return await client.query(passedQuery, passedData); | ||
} finally { | ||
client.release(); | ||
} | ||
})(); | ||
} catch (e) { | ||
return debug('query')(e.stack); | ||
} | ||
}, | ||
async dbTesting(passedQuery) { | ||
try { | ||
return (async () => { | ||
const client = await pool.connect(); | ||
try { | ||
return await client.query(passedQuery); | ||
} finally { | ||
client.release(); | ||
} | ||
})(); | ||
} catch (e) { | ||
return debug('query')(e.stack); | ||
} | ||
}, | ||
}; | ||
|
||
export default dbConnection; | ||
import { Pool } from 'pg'; | ||
import debug from 'debug'; | ||
import dotenv from 'dotenv'; | ||
import { parse } from 'pg-connection-string'; | ||
|
||
dotenv.config(); | ||
|
||
let conString; | ||
|
||
if (process.env.HEROKU_ACCESS === 'heroku_access') { | ||
conString = parse(process.env.BANKA_DB); | ||
} else { | ||
conString = parse(process.env.DB_CONFIG); | ||
} | ||
|
||
const pool = new Pool(conString); | ||
|
||
const dbConnection = { | ||
/** | ||
* Connect to database | ||
* @constructor | ||
* @param {*} passedQuery - passed in SQL query. | ||
* @param {*} passedData -passed in db values | ||
*/ | ||
async dbConnect(passedQuery, passedData) { | ||
try { | ||
return (async () => { | ||
const client = await pool.connect(); | ||
try { | ||
return await client.query(passedQuery, passedData); | ||
} finally { | ||
client.release(); | ||
} | ||
})(); | ||
} catch (e) { | ||
return debug('query')(e.stack); | ||
} | ||
}, | ||
|
||
/** | ||
* Connect to database - For test | ||
* @constructor | ||
* @param {*} passedQuery - passed in SQL query. | ||
*/ | ||
async dbTesting(passedQuery) { | ||
try { | ||
return (async () => { | ||
const client = await pool.connect(); | ||
try { | ||
return await client.query(passedQuery); | ||
} finally { | ||
client.release(); | ||
} | ||
})(); | ||
} catch (e) { | ||
return debug('query')(e.stack); | ||
} | ||
}, | ||
}; | ||
|
||
export default dbConnection; |
Oops, something went wrong.