-
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.
- Loading branch information
Showing
8 changed files
with
775 additions
and
772 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 |
---|---|---|
|
@@ -35,9 +35,5 @@ module.exports = { | |
} | ||
}], | ||
"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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,6 @@ typings/ | |
|
||
# next.js build output | ||
.next | ||
|
||
# vs code | ||
.DS_Store |
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,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 |
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,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; |
Oops, something went wrong.