Skip to content

Commit

Permalink
Merge pull request #95 from Cavdy/frontend-app
Browse files Browse the repository at this point in the history
Frontend app
  • Loading branch information
Cavdy committed Apr 25, 2019
2 parents dddf0a5 + 8a4290b commit be4dcd3
Show file tree
Hide file tree
Showing 8 changed files with 775 additions and 772 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,5 @@ module.exports = {
}
}],
"max-len": ["error", { "code": 80 }],
"linebreak-style": [
"error",
"windows"
]
}
};
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ typings/

# next.js build output
.next

# vs code
.DS_Store
19 changes: 12 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
language: node_js
node_js:
- "stable"
cache:
directories:
- "node_modules"
- "8"
before_install: cd ./server
install:
- npm install
script:
- npm run test
after_success:
- npm run coverage
cache:
directories:
- "node_modules"
env:
global:
- CODECLIMATE_REPO_TOKEN=c14abfc89b0eb06fcb10f480f4b3e47142ac181c60c21f0131b570e72b1fbeb7
- CODECLIMATE_REPO_TOKEN=c14abfc89b0eb06fcb10f480f4b3e47142ac181c60c21f0131b570e72b1fbeb7
- JWTSECRETKEY=5634
- DB_CONFIG=postgres://xwrxubeu:u4wOQ6oxpvRCK6yWk5qK4rzaiisTPeoN@isilo.db.elephantsql.com:5432/xwrxubeu
- ADMIN_PWD=$2a$10$CmmIst1.D3QjaWuafKbBaOuAFu0r9o7xxQY.0SMKiAN.h9z52a2y2
script:
- npm run test
services:
- postgresql
3 changes: 0 additions & 3 deletions server/v1/config/database.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
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') {
Expand Down
3 changes: 3 additions & 0 deletions server/v1/config/migration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import dotenv from 'dotenv';
import dbConnection from './database';

dotenv.config();

const Migration = {
/**
* Migration
Expand Down
260 changes: 130 additions & 130 deletions server/v1/services/users.js
Original file line number Diff line number Diff line change
@@ -1,130 +1,130 @@
import dbConnection from '../config/database';

const UsersServices = {
/**
* Get all users
* @constructor
* @param {*} staff - get token details to check if staff or admin
* @param {*} queryLimit - Get query parameter
*/
async getAllUsers(staff, queryLimit) {
let returnStatus; let returnSuccess = ''; let returnError = '';
// check the users table
const userDetails = await dbConnection
.dbConnect('SELECT id, type, isadmin FROM users WHERE email=$1',
[staff.email]);
const { type, isadmin } = userDetails.rows[0];

if (type === 'staff' || isadmin === true) {
if (typeof queryLimit !== 'undefined') {
const allAccounts = await dbConnection
.dbConnect('SELECT * from users LIMIT $1', [queryLimit]);
returnStatus = 200;
returnSuccess = allAccounts.rows;
} else {
const allAccounts = await dbConnection
.dbConnect('SELECT * from users LIMIT $1', [10]);
returnStatus = 200;
returnSuccess = allAccounts.rows;
}
} else {
returnStatus = 401;
returnError = 'You don\'t have permission to view this page';
}
return {
returnStatus,
returnSuccess,
returnError,
};
},

/**
* Get user's accounts by email
* @constructor
* @param {*} email - get user's email
*/
async getUsersAccounts(email) {
let returnStatus; let returnSuccess = ''; let returnError = '';
const allAccounts = await dbConnection
.dbConnect('SELECT email from users WHERE email=$1', [email]);
if (allAccounts.rows.length > 0) {
const accountDbData = await dbConnection
.dbConnect('SELECT * from accounts WHERE email=$1', [email]);
if (accountDbData.rows.length > 0) {
returnStatus = 200;
returnSuccess = accountDbData.rows;
} else {
returnStatus = 404;
returnError = 'no account found for this user';
}
} else {
returnStatus = 404;
returnError = 'email does not exist';
}
return {
returnStatus,
returnSuccess,
returnError,
};
},

/**
* Delete user
* @constructor
* @param {*} id - get user id
* @param {*} staff - get token details to check if staff or admin
*/
async deleteUser(id, staff) {
let returnStatus; let returnSuccess = ''; let returnError = '';
// check the users table
const userDetails = await dbConnection
.dbConnect('SELECT id, type, isadmin FROM users WHERE email=$1',
[staff.email]);
const { type, isadmin } = userDetails.rows[0];

if (type === 'staff') {
const checkusers = await dbConnection
.dbConnect('SELECT type FROM users WHERE id=$1', [id]);
if (checkusers.rows.length > 0) {
if (checkusers.rows[0].type === 'client') {
const accountDbData = await dbConnection
.dbConnect('DELETE FROM users WHERE id=$1', [id]);
if (accountDbData.command === 'DELETE') {
returnStatus = 200;
returnSuccess = 'Account successfully deleted';
}
} else {
returnStatus = 401;
returnError = 'you must be an admin to delete this staff';
}
} else {
returnStatus = 404;
returnError = 'no account found';
}
} else if (isadmin === true) {
const checkusers = await dbConnection
.dbConnect('SELECT type FROM users WHERE id=$1', [id]);
if (checkusers.rows.length > 0) {
const accountDbData = await dbConnection
.dbConnect('DELETE FROM users WHERE id=$1', [id]);
if (accountDbData.command === 'DELETE') {
returnStatus = 200;
returnSuccess = 'Account successfully deleted';
}
} else {
returnStatus = 404;
returnError = 'no account found';
}
} else {
returnStatus = 401;
returnError = 'You don\'t have permission to view this page';
}
return {
returnStatus,
returnSuccess,
returnError,
};
},
};

export default UsersServices;
import dbConnection from '../config/database';

const UsersServices = {
/**
* Get all users
* @constructor
* @param {*} staff - get token details to check if staff or admin
* @param {*} queryLimit - Get query parameter
*/
async getAllUsers(staff, queryLimit) {
let returnStatus; let returnSuccess = ''; let returnError = '';
// check the users table
const userDetails = await dbConnection
.dbConnect('SELECT id, type, isadmin FROM users WHERE email=$1',
[staff.email]);
const { type, isadmin } = userDetails.rows[0];

if (type === 'staff' || isadmin === true) {
if (typeof queryLimit !== 'undefined') {
const allAccounts = await dbConnection
.dbConnect('SELECT * from users LIMIT $1', [queryLimit]);
returnStatus = 200;
returnSuccess = allAccounts.rows;
} else {
const allAccounts = await dbConnection
.dbConnect('SELECT * from users LIMIT $1', [10]);
returnStatus = 200;
returnSuccess = allAccounts.rows;
}
} else {
returnStatus = 401;
returnError = 'You don\'t have permission to view this page';
}
return {
returnStatus,
returnSuccess,
returnError,
};
},

/**
* Get user's accounts by email
* @constructor
* @param {*} email - get user's email
*/
async getUsersAccounts(email) {
let returnStatus; let returnSuccess = ''; let returnError = '';
const allAccounts = await dbConnection
.dbConnect('SELECT email from users WHERE email=$1', [email]);
if (allAccounts.rows.length > 0) {
const accountDbData = await dbConnection
.dbConnect('SELECT * from accounts WHERE email=$1', [email]);
if (accountDbData.rows.length > 0) {
returnStatus = 200;
returnSuccess = accountDbData.rows;
} else {
returnStatus = 404;
returnError = 'no account found for this user';
}
} else {
returnStatus = 404;
returnError = 'email does not exist';
}
return {
returnStatus,
returnSuccess,
returnError,
};
},

/**
* Delete user
* @constructor
* @param {*} id - get user id
* @param {*} staff - get token details to check if staff or admin
*/
async deleteUser(id, staff) {
let returnStatus; let returnSuccess = ''; let returnError = '';
// check the users table
const userDetails = await dbConnection
.dbConnect('SELECT id, type, isadmin FROM users WHERE email=$1',
[staff.email]);
const { type, isadmin } = userDetails.rows[0];

if (type === 'staff') {
const checkusers = await dbConnection
.dbConnect('SELECT type FROM users WHERE id=$1', [id]);
if (checkusers.rows.length > 0) {
if (checkusers.rows[0].type === 'client') {
const accountDbData = await dbConnection
.dbConnect('DELETE FROM users WHERE id=$1', [id]);
if (accountDbData.command === 'DELETE') {
returnStatus = 200;
returnSuccess = 'Account successfully deleted';
}
} else {
returnStatus = 401;
returnError = 'you must be an admin to delete this staff';
}
} else {
returnStatus = 404;
returnError = 'no account found';
}
} else if (isadmin === true) {
const checkusers = await dbConnection
.dbConnect('SELECT type FROM users WHERE id=$1', [id]);
if (checkusers.rows.length > 0) {
const accountDbData = await dbConnection
.dbConnect('DELETE FROM users WHERE id=$1', [id]);
if (accountDbData.command === 'DELETE') {
returnStatus = 200;
returnSuccess = 'Account successfully deleted';
}
} else {
returnStatus = 404;
returnError = 'no account found';
}
} else {
returnStatus = 401;
returnError = 'You don\'t have permission to view this page';
}
return {
returnStatus,
returnSuccess,
returnError,
};
},
};

export default UsersServices;
Loading

0 comments on commit be4dcd3

Please sign in to comment.