Skip to content

Commit

Permalink
Merge pull request #70 from Cavdy/api
Browse files Browse the repository at this point in the history
Api
  • Loading branch information
Cavdy committed Apr 19, 2019
2 parents 46087b7 + fd2d2d6 commit e5148d2
Show file tree
Hide file tree
Showing 38 changed files with 1,415 additions and 771 deletions.
16 changes: 14 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
{
"presets": [
"@babel/preset-env"
"presets": [
"@babel/preset-env"
],
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"absoluteRuntime": false,
"corejs": false,
"helpers": true,
"regenerator": true,
"useESModules": false
}
]
]
}
6 changes: 6 additions & 0 deletions .directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Dolphin]
Timestamp=2019,4,17,3,23,17
Version=4

[Settings]
HiddenFilesShown=true
38 changes: 30 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "banking web app",
"main": "app.js",
"scripts": {
"server": "DEBUG=query nodemon --exec babel-node ./server/v1/config/database.js",
"start": "node ./server/build/app.js",
"build": "babel -d ./server/build ./server/v1 -s",
"dev": "nodemon --exec babel-node ./server/v1/app.js",
"test": "mocha ./server/v1 --recursive --require @babel/register --exit || true",
"test": "mocha --timeout 20000 ./server/v1 --recursive --require @babel/register --exit || true",
"generate-lcov": "nyc report --reporter=text-lcov > lcov.info",
"coveralls-coverage": "coveralls < lcov.info",
"codeclimate-coverage": "codeclimate-test-reporter < lcov.info",
Expand All @@ -30,7 +31,9 @@
},
"homepage": "https://github.com/Cavdy/Banka#readme",
"dependencies": {
"@babel/polyfill": "^7.4.3",
"@babel/register": "^7.4.0",
"@babel/runtime": "^7.4.3",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"chai": "^4.2.0",
Expand All @@ -43,20 +46,22 @@
"jsonwebtoken": "^8.5.0",
"mocha": "^6.1.3",
"pg": "^7.8.1",
"pg-connection-string": "^2.0.0",
"swagger-ui-express": "^4.0.2"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/node": "^7.2.2",
"@babel/plugin-transform-runtime": "^7.4.3",
"@babel/preset-env": "^7.3.1",
"codeclimate-test-reporter": "^0.5.1",
"coveralls": "^3.0.3",
"mocha-lcov-reporter": "^1.3.0",
"nyc": "^13.3.0",
"eslint": "^5.13.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.16.0",
"nodemon": "^1.18.10"
"mocha-lcov-reporter": "^1.3.0",
"nodemon": "^1.18.10",
"nyc": "^13.3.0"
}
}
53 changes: 53 additions & 0 deletions q
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
id | email | firstname | lastname | accountnumber | createdon | owner | type | status | balance
----+---------------------+-----------+----------+---------------+-----------+-------+---------+---------+---------
1 | banka872@banka4.com | | | 3702581476 | 17/4/2019 | 50 | savings | active | 0
2 | banka872@banka4.com | | | 3872146107 | 17/4/2019 | 50 | savings | active | 0
5 | banka872@banka4.com | cavdy | isaiah | 3548652217 | 17/4/2019 | 50 | savings | active | 0
6 | banka872@banka4.com | cavdy | isaiah | 3491564558 | 17/4/2019 | 50 | savings | active | 0
7 | banka872@banka4.com | cavdy | isaiah | 3146859791 | 17/4/2019 | 54 | savings | active | 0
8 | banka872@banka4.com | cavdy | isaiah | 3779533562 | 17/4/2019 | 55 | savings | active | 0
3 | banka872@banka4.com | cavdy | isaiah | 3699742813 | 17/4/2019 | 50 | savings | dormant | 0
10 | banka872@banka4.com | cavdy | isaiah | 3484311663 | 17/4/2019 | 57 | savings | active | 0
11 | banka872@banka4.com | cavdy | isaiah | 3204762909 | 17/4/2019 | 57 | savings | active | 0
12 | banka872@banka4.com | cavdy | isaiah | 3877851924 | 17/4/2019 | 59 | savings | active | 0
13 | banka872@banka4.com | cavdy | isaiah | 3072181085 | 17/4/2019 | 60 | savings | active | 0
14 | banka872@banka4.com | cavdy | isaiah | 3432650514 | 17/4/2019 | 60 | savings | active | 0
15 | banka872@banka4.com | cavdy | isaiah | 3983443368 | 17/4/2019 | 61 | savings | active | 0
16 | banka872@banka4.com | cavdy | isaiah | 3438930243 | 17/4/2019 | 61 | savings | active | 0
17 | banka872@banka4.com | cavdy | isaiah | 3655609161 | 17/4/2019 | 62 | savings | active | 0
18 | banka872@banka4.com | cavdy | isaiah | 3297739483 | 17/4/2019 | 62 | savings | active | 0
19 | banka872@banka4.com | cavdy | isaiah | 3633960829 | 17/4/2019 | 62 | savings | active | 0
20 | banka872@banka4.com | cavdy | isaiah | 3003801983 | 17/4/2019 | 63 | savings | active | 0
21 | banka872@banka4.com | cavdy | isaiah | 3453420061 | 17/4/2019 | 63 | savings | active | 0
22 | banka872@banka4.com | cavdy | isaiah | 3797532048 | 17/4/2019 | 63 | savings | active | 0
23 | admin@banka.com | cavdy | ikenna | 3515833161 | 17/4/2019 | 64 | savings | active | 0
24 | banka872@banka4.com | cavdy | isaiah | 3931715014 | 17/4/2019 | 65 | savings | active | 0
25 | banka872@banka4.com | cavdy | isaiah | 3502561578 | 17/4/2019 | 65 | savings | active | 0
26 | banka872@banka4.com | cavdy | isaiah | 3261422912 | 17/4/2019 | 65 | savings | active | 0
27 | banka872@banka4.com | cavdy | isaiah | 3298245957 | 17/4/2019 | 67 | savings | active | 0
28 | banka872@banka4.com | cavdy | isaiah | 3461967601 | 17/4/2019 | 67 | savings | active | 0
29 | banka872@banka4.com | cavdy | isaiah | 3243384247 | 17/4/2019 | 67 | savings | active | 0
30 | admin@banka.com | cavdy | ikenna | 3563254210 | 17/4/2019 | 68 | savings | active | 0
31 | banka872@banka4.com | cavdy | isaiah | 3534066798 | 17/4/2019 | 69 | savings | active | 0
32 | banka872@banka4.com | cavdy | isaiah | 3482397810 | 17/4/2019 | 69 | savings | active | 0
33 | banka872@banka4.com | cavdy | isaiah | 3110547517 | 17/4/2019 | 69 | savings | active | 0
34 | banka872@banka4.com | cavdy | isaiah | 3437719577 | 17/4/2019 | 69 | savings | active | 0
35 | banka872@banka4.com | cavdy | isaiah | 3548538073 | 17/4/2019 | 71 | savings | active | 0
36 | banka872@banka4.com | cavdy | isaiah | 3703724774 | 17/4/2019 | 73 | savings | active | 0
37 | banka872@banka4.com | cavdy | isaiah | 3124616562 | 17/4/2019 | 75 | savings | active | 0
38 | banka872@banka4.com | cavdy | isaiah | 3057087124 | 17/4/2019 | 77 | savings | active | 0
39 | banka872@banka4.com | cavdy | isaiah | 3753591929 | 17/4/2019 | 79 | savings | active | 0
40 | banka872@banka4.com | cavdy | isaiah | 3008302349 | 17/4/2019 | 81 | savings | active | 0
41 | banka872@banka4.com | cavdy | isaiah | 3164295216 | 17/4/2019 | 83 | savings | active | 0
42 | banka872@banka4.com | cavdy | isaiah | 3355341006 | 17/4/2019 | 85 | savings | active | 0
43 | banka872@banka4.com | cavdy | isaiah | 3043952815 | 17/4/2019 | 87 | savings | active | 0
44 | banka872@banka4.com | cavdy | isaiah | 3331809305 | 17/4/2019 | 89 | savings | active | 0
45 | banka872@banka4.com | cavdy | isaiah | 3983804072 | 17/4/2019 | 91 | savings | active | 0
46 | banka872@banka4.com | cavdy | isaiah | 3446930353 | 17/4/2019 | 93 | savings | active | 0
47 | banka872@banka4.com | cavdy | isaiah | 3571949659 | 17/4/2019 | 95 | savings | active | 0
48 | banka872@banka4.com | cavdy | isaiah | 3242133029 | 17/4/2019 | 97 | savings | active | 0
49 | banka872@banka4.com | cavdy | isaiah | 3384304769 | 17/4/2019 | 107 | savings | active | 0
50 | banka872@banka4.com | cavdy | isaiah | 3429391534 | 17/4/2019 | 107 | savings | active | 0
51 | banka872@banka4.com | cavdy | isaiah | 3344395362 | 17/4/2019 | 107 | savings | active | 0
(49 rows)

2 changes: 0 additions & 2 deletions server/v1/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import debug from 'debug';
import swaggerUi from 'swagger-ui-express';
import swaggerDocument from '../swagger';
import RegisterRoute from './routes/register';
import CreateStaffRoute from './routes/createStaffs';
import LoginRoute from './routes/login';
import CreateAccountRoute from './routes/createAccount';
import TransactionRoute from './routes/transaction';
Expand All @@ -32,7 +31,6 @@ app.get('/', (req, res) => {
// creating the api version route
app.use('/api/auth/signup', RegisterRoute);
app.use('/api/auth/signin', LoginRoute);
app.use('/api/auth/addstaff', jwtMiddleware.checkToken, CreateStaffRoute);
app.use('/api/v1/accounts', jwtMiddleware.checkToken, CreateAccountRoute);
app.use('/api/v1/transactions', jwtMiddleware.checkToken, TransactionRoute);
app.use('/api/v1/users', jwtMiddleware.checkToken, UsersRoute);
Expand Down
27 changes: 27 additions & 0 deletions server/v1/config/account.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- Accounts SQL query

-- create accounts table
CREATE TABLE 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
);

-- select all from accounts table
SELECT * FROM accounts LIMIT 10

-- select account number fro accounts
SELECT accountNumber FROM accounts WHERE accountNumber=$1, ['accountNumber']

-- insert into accounts table
INSERT into accounts values($1), ['value']

-- delete from accounts table
DELETE FROM accounts;
43 changes: 43 additions & 0 deletions server/v1/config/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Pool } from 'pg';
import debug from 'debug';
import dotenv from 'dotenv';
import { parse } from 'pg-connection-string';

dotenv.config();

const conString = parse(process.env.DB_CONFIG);

const pool = new Pool(conString);

const dbConnection = {
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;
28 changes: 28 additions & 0 deletions server/v1/config/transaction.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Transactions SQL query

-- create transactions table
CREATE TABLE transactions (
id SERIAL PRIMARY KEY UNIQUE,
createdOn VARCHAR(40),
type VARCHAR(10),
accountNumber BIGINT,
cashier INTEGER,
amount FLOAT,
oldBalance FLOAT,
newBalance FLOAT
);

-- select all from transactions table
SELECT * FROM transactions LIMIT 10

-- select account number fro transactions
SELECT accountNumber FROM transactions WHERE accountNumber=$1, ['accountNumber']

-- insert into transactions table
INSERT into transactions values($1), ['value']

-- update
UPDATE transactions SET balance=$1 WHERE accountnumber=$2, [newBalance, accountNumber]

-- delete from transactions table
DELETE FROM transactions;
27 changes: 27 additions & 0 deletions server/v1/config/user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- Users SQL query

-- create users table
CREATE TABLE users (
id SERIAL PRIMARY KEY UNIQUE,
email VARCHAR(80) UNIQUE,
firstName VARCHAR(20),
lastName VARCHAR(20),
password VARCHAR(80),
type VARCHAR(10),
isAdmin BOOLEAN
);

-- select all from users table
SELECT * FROM users LIMIT 10

-- select email fro users
SELECT email FROM users WHERE email=$1, ['email']

-- insert into users table
INSERT into users values($1), ['value']

-- delete from users table
DELETE FROM users;

-- admin
INSERT into users(email, firstName, lastName, password, type, isAdmin) values('admin@banka.com', 'cavdy', 'ikenna', '$2a$10$CmmIst1.D3QjaWuafKbBaOuAFu0r9o7xxQY.0SMKiAN.h9z52a2y2', 'staff', true)
Loading

0 comments on commit e5148d2

Please sign in to comment.