Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#167730643 User Role Settings #39

Open
wants to merge 26 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
50645bb
updated travis and test
OmoloyinA Aug 29, 2019
5d29574
feature(notify-request): notify manager of travel request
OmoloyinA Sep 4, 2019
a398362
pop-up of stashed commits
OmoloyinA Sep 4, 2019
e16b72e
declaring server as a function in the entry point
OmoloyinA Sep 4, 2019
7b1af3a
setting up the project
OmoloyinA Sep 4, 2019
ce3ea15
updating the controller and test files with line-spacing
OmoloyinA Sep 5, 2019
5e8e023
updating the .env file to hold values for sendGrid
OmoloyinA Sep 5, 2019
1e22bad
created service and routes files
OmoloyinA Sep 5, 2019
46c79b7
installing @sendgrid/mail package from npm
OmoloyinA Sep 5, 2019
ebbf9d9
Checking out the socket.io client and server side
OmoloyinA Sep 8, 2019
82d0ddc
refactoring codes
OmoloyinA Sep 10, 2019
4ebc6b7
edited the entry point and routes to test with postman
OmoloyinA Sep 10, 2019
d412bd2
updating the database models, migrations and seeders files
OmoloyinA Sep 11, 2019
2bba6ea
reconfigured local project to be in sync with develop
OmoloyinA Sep 12, 2019
250f35d
updating the database
OmoloyinA Sep 13, 2019
41bb90f
changing folder structure
OmoloyinA Sep 13, 2019
3fae104
feature(approve-travel-request):enable manager to approve travel request
chuksjoe Sep 12, 2019
6f9953b
brute force of merged PR
OmoloyinA Sep 13, 2019
a6a3cfc
implementation of notification features
OmoloyinA Sep 13, 2019
b7a3902
Merge branch 'develop' into ft-notify-new-travel-167730641
OmoloyinA Sep 13, 2019
d8ecdcf
feature(notify-new-request): new travel requests
OmoloyinA Sep 13, 2019
db6cfba
feature(notify-new-request): new travel requests
OmoloyinA Sep 13, 2019
a64e64c
feature(notify-new-request): new travel requests
OmoloyinA Sep 13, 2019
63b4184
feature(notify-new-request): new travel requests
OmoloyinA Sep 13, 2019
47bf0c3
feature(role-setting): user role settings
OmoloyinA Sep 14, 2019
b275058
feature(role-settings): user role set-up
OmoloyinA Sep 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ FACEBOOK_CLIENT_ID
FACEBOOK_CLIENT_SECRET
FACEBOOK_CALLBACK_URL

EMAIL_ADD:
EMAIL_PASS:

GOOGLE_CONSUMER_KEY
GOOGLE_CONSUMER_SECRET
Expand All @@ -26,3 +28,7 @@ JWT_EMAIL_SECRET
EMAIL_ADD
EMAIL_PASS

SENDGRID_API

SENDGRID_API_KEY

1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"no-param-reassign": 0,
"comma-dangle": 0,
"arrow-parens": 0,
"max-len": 0,
"curly": ["error", "multi-line"],
"import/no-unresolved": [2, { "commonjs": true }],
"import/no-named-as-default": 0,
Expand Down
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.formatOnSaveTimeout": 0,
"editor.tabSize": 2,
"editor.wordWrap": "on"
}
16,662 changes: 8,415 additions & 8,247 deletions package-lock.json

Large diffs are not rendered by default.

159 changes: 81 additions & 78 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,80 +1,83 @@
{
"name": "archangel_barefoot_nomad",
"version": "1.0.0",
"description": "An application for company global travels and accommodation",
"main": "index.js",
"scripts": {
"build": "babel -d ./build ./src -s",
"prod": "set NODE_ENV=production&& node build/index.js",
"start": "set NODE_ENV=development&& babel-node src/index.js",
"dev": "set DEBUG=web-app && set NODE_ENV=development&& nodemon src/index.js --exec babel-node",
"test": "set NODE_ENV=test&& sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all && mocha --timeout 0 ./src/tests/*.js --require @babel/register --reporter spec --exec babel-node --exit",
"generate-lcov": "nyc report --reporter=text-lcov >lcov.info",
"coveralls-coverage": "coveralls < lcov.info",
"coverage": "nyc npm test && npm run generate-lcov && npm run coveralls-coverage",
"coveralls": "nyc --reporter=lcov --reporter=text-lcov npm test",
"create:db": "set NODE_ENV=development&& sequelize db:create",
"drop:db": "set NODE_ENV=development&& sequelize db:drop",
"undo:db": "sequelize db:migrate:undo:all",
"create:tables": "set NODE_ENV=development&& sequelize db:migrate && sequelize db:seed:all"
},
"author": "Andela Simulations Programme",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.5.5",
"@sendgrid/mail": "^6.4.0",
"bcryptjs": "^2.4.3",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"core-js": "^3.2.1",
"cors": "^2.8.4",
"coveralls": "^3.0.3",
"crypto-random-string": "^3.0.1",
"debug": "^4.1.1",
"dotenv": "^6.2.0",
"ejs": "^2.6.1",
"errorhandler": "^1.5.0",
"express": "^4.17.1",
"express-jwt": "^5.3.1",
"express-session": "^1.15.6",
"express-validator": "^6.1.1",
"jsonwebtoken": "^8.3.0",
"method-override": "^2.3.10",
"methods": "^1.1.2",
"morgan": "^1.9.1",
"nodemailer": "^6.3.0",
"passport": "^0.4.0",
"passport-facebook": "^3.0.0",
"passport-google-oauth20": "^2.0.0",
"passport-local": "^1.0.0",
"path": "^0.12.7",
"pg": "^7.12.1",
"pg-hstore": "^2.3.3",
"regenerator-runtime": "^0.13.3",
"request": "^2.87.0",
"sendgrid": "^5.2.3",
"sequelize": "^5.15.2",
"sequelize-cli": "^5.5.0",
"underscore": "^1.9.1"
},
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/node": "^7.5.5",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.5.5",
"babel-eslint": "^10.0.3",
"babel-register": "^6.26.0",
"cross-env": "^5.2.0",
"eslint": "^6.1.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^1.7.0",
"mocha": "^6.2.0",
"mocha-lcov-reporter": "^1.3.0",
"nodemon": "^1.19.1"
}
"name": "archangel_barefoot_nomad",
"version": "1.0.0",
"description": "An application for company global travels and accommodation",
"main": "index.js",
"scripts": {
"build": "babel -d ./build ./src -s",
"prod": "set NODE_ENV=production&& node build/index.js",
"start": "set NODE_ENV=development&& babel-node src/index.js",
"dev": "set DEBUG=web-app && set NODE_ENV=development&& nodemon src/index.js --exec babel-node",
"test": "set NODE_ENV=test&& sequelize db:migrate:undo:all && sequelize db:migrate && sequelize db:seed:all && mocha --timeout 0 ./src/tests/*.js --require @babel/register --reporter spec --exec babel-node --exit",
"generate-lcov": "nyc report --reporter=text-lcov >lcov.info",
"coveralls-coverage": "coveralls < lcov.info",
"coverage": "nyc npm test && npm run generate-lcov && npm run coveralls-coverage",
"coveralls": "nyc --reporter=lcov --reporter=text-lcov npm test",
"create:db": "set NODE_ENV=development&& sequelize db:create",
"drop:db": "set NODE_ENV=development&& sequelize db:drop",
"undo:db": "sequelize db:migrate:undo:all",
"create:tables": "set NODE_ENV=development&& sequelize db:migrate && sequelize db:seed:all"
},
"author": "Andela Simulations Programme",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.5.5",
"@sendgrid/mail": "^6.4.0",
"auto-bind": "^2.1.0",
"bcryptjs": "^2.4.3",
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"core-js": "^3.2.1",
"cors": "^2.8.4",
"coveralls": "^3.0.3",
"crypto-random-string": "^3.0.1",
"debug": "^4.1.1",
"dotenv": "^6.2.0",
"ejs": "^2.6.1",
"errorhandler": "^1.5.0",
"express": "^4.17.1",
"express-jwt": "^5.3.1",
"express-session": "^1.15.6",
"express-validator": "^6.1.1",
"jsonwebtoken": "^8.3.0",
"method-override": "^2.3.10",
"methods": "^1.1.2",
"morgan": "^1.9.1",
"nodemailer": "^6.3.0",
"passport": "^0.4.0",
"passport-facebook": "^3.0.0",
"passport-google-oauth20": "^2.0.0",
"passport-local": "^1.0.0",
"path": "^0.12.7",
"pg": "^7.12.1",
"pg-hstore": "^2.3.3",
"regenerator-runtime": "^0.13.3",
"request": "^2.87.0",
"sendgrid": "^5.2.3",
"sequelize": "^5.15.2",
"sequelize-cli": "^5.5.0",
"socket.io": "^2.2.0",
"socket.io-client": "^2.2.0",
"underscore": "^1.9.1"
},
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/node": "^7.5.5",
"@babel/plugin-transform-runtime": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.5.5",
"babel-eslint": "^10.0.3",
"babel-register": "^6.26.0",
"cross-env": "^5.2.0",
"eslint": "^6.1.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^1.7.0",
"mocha": "^6.2.0",
"mocha-lcov-reporter": "^1.3.0",
"nodemon": "^1.19.1"
}
}
54 changes: 54 additions & 0 deletions src/controllers/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable import/named */
/* eslint-disable require-jsdoc */

class ClientController {
/**
* @param {Object} req
* @param {Object} res
* @returns {Object} the new user
* @description register a new client
*/
static async getClient(req, res) {
const { user_id } = req.params;

const message = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Chat App</title>
<script src="/socket.io/socket.io.js"></script>
<script>
const appendMessage = (message) => {
const div = document.getElementById('message-container');
let para = document.createElement('p');
para.appendChild(document.createTextNode(message));
div.appendChild(para);
};
const socket = io();
socket.on('travelCreated${user_id}', (data) => {
appendMessage(data);
});
socket.on('here', (data) => {
console.log(data);
appendMessage(data);
});
</script>
</head>
<body>
<div id="message-container">
<h3>Notify User Travels</h3>

</div>

</body>
</html>

`;

res.send(message);
}
}

export default ClientController;
31 changes: 31 additions & 0 deletions src/controllers/notifyControllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable require-jsdoc */
import models from '../models';

const { notifications } = models;

export default {

getAllNotification: async (req, res) => {
try {
const user_id = req.users.id;
const allRequests = await notifications.findAll({ where: { receiver: user_id } });
return res.status(200).json({ status: 200, data: allRequests });
} catch (error) {
res.status(500).json({ status: 500, error });
}
},

readAllNotification: async (req, res) => {
try {
const user_id = req.user.id;
const allRequestsByUser = await notifications.update({ is_read: true }, {
where: {
receiver: user_id
}
});
return res.status(200).json({ status: 200, data: allRequestsByUser });
} catch (error) {
res.status(500).json({ status: 500, error });
}
},
};
32 changes: 32 additions & 0 deletions src/controllers/roleControllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { roleUpdate } from '../services/roleServices';
import {
successResponseWithData,
successResponse,
errorResponse,
} from '../utils/response';

import message from '../utils/messageUtils';
import statusCode from '../utils/statusCode';

export const assignRole = async(req, res) => {
try {
const { user_id } = req.params;
const { role } = req.body;
const updatedUser = await users.roleUpdate({
where: {
user_id
},
role: newRole
});
const returnedData = updatedUser.dataValues;

successResponseWithData(
res,
statusCode.success,
message.roleUpdate,
returnedData
);
} catch (err) {
errorResponse(res, statusCode.serverError, err);
}
};
Loading