Skip to content

Commit

Permalink
navbar edits
Browse files Browse the repository at this point in the history
  • Loading branch information
ishak52 committed Jul 31, 2018
2 parents 2b5f3dc + 4b73ab1 commit a32a396
Show file tree
Hide file tree
Showing 41 changed files with 1,045 additions and 2,634 deletions.
8 changes: 2 additions & 6 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
const express = require('express');
const bodyParser = require('body-parser');
const controllers = require('./controllers');
const compression = require('compression');


const app = express();
const path = require('path');



app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.set('port', process.env.PORT || 4001);
app.use(compression());
app.use(express.static(path.join(__dirname, '..', 'public')));
app.use(controllers);

Expand Down
8 changes: 8 additions & 0 deletions backend/controllers/carers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { selectAllCarers } = require('../database/queries/select');

exports.post = (req, res,)=>{
selectAllCarers(null, (err, results)=>{
if (err) console.log("error", err);
res.send(results)
})
};
26 changes: 6 additions & 20 deletions backend/controllers/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
const express = require('express');

const router = express.Router();
const carers = require('./carers');
const login = require('./login');

router.post('/login', login.post)
router.post('/carers', carers.post)


const test = require('./test');
// const login = require('./login.js');
// const GSG_Library = require('./GSG_Library');
// const deletee = require('./deletee');
// const home = require('./home');
// const addnewbook = require('./addnewbook');
// const waitinglist = require('./waitinglist');
//
router.get('/test', test.get);
// router.post('/addToWaitingList', home.post);
// router.get('/waitinglist',waitinglist.get);
// router.get('/admin', login.get);
// router.get('/dashboard', dashboard.get);
// router.get('/GSG_Library', GSG_Library.get);
// router.post('/search', GSG_Library.post);
// router.get('/delete/:id', deletee.delete1);
// router.post('/deletebookfromsearch',deletee.delete2);
// router.get('/addnewbook', addnewbook.get);
// router.post('/addnewbook', addnewbook.post);
module.exports = router;
12 changes: 12 additions & 0 deletions backend/controllers/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { selectAllCarers } = require('../database/queries/select');

exports.post = (req, res)=>{
selectAllCarers(req.body.userName, (err, results)=>{
if (err) return res.send({msg: 'error in database', status: 0});
if (!results.length) return res.send({msg: 'Sorry .. User not found', status: 3});
if (req.body.password == results[0].password) {
return res.send({msg: 'Login Success', status: 1})
}
return res.send({msg: 'Sorry .. Password is wrong', status: 2})
})
};
3 changes: 0 additions & 3 deletions backend/controllers/test.js

This file was deleted.

50 changes: 50 additions & 0 deletions backend/database/build.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
BEGIN;
DROP TABLE IF EXISTS users, connections, discussions CASCADE;
CREATE TYPE roles AS ENUM ('user');
CREATE TYPE states AS ENUM ('approved', 'pending', 'decline');

CREATE TABLE "users" (
"id" serial NOT NULL,
"full_name" varchar(30) NOT NULL,
"user_name" varchar(30) NOT NULL UNIQUE,
"email" varchar(30) NOT NULL UNIQUE,
"password" varchar(30) NOT NULL,
"user_role" roles NOT NULL,
"age" int NOT NULL,
"sitution" varchar(300) NOT NULL,
"location" varchar(30) NOT NULL,
"offer" varchar(300) NOT NULL,
"looking" varchar(300) NOT NULL,
CONSTRAINT users_pk PRIMARY KEY ("id")
);

CREATE TABLE "connections" (
"id" serial NOT NULL,
"first_user_id" int NOT NULL,
"second_user_id" int NOT NULL,
"relation_state" states NOT NULL,
"date_created" DATE NOT NULL,
CONSTRAINT connections_pk PRIMARY KEY ("id")
);

CREATE TABLE "discussions" (
"massage_id" serial NOT NULL,
"massage_body" varchar(1000) NOT NULL,
"sender_id" int NOT NULL,
"receiver_id" int NOT NULL,
CONSTRAINT discussions_pk PRIMARY KEY ("massage_id")
);

ALTER TABLE "connections" ADD CONSTRAINT "connections_fk0" FOREIGN KEY ("first_user_id") REFERENCES "users"("id");
ALTER TABLE "connections" ADD CONSTRAINT "connections_fk1" FOREIGN KEY ("second_user_id") REFERENCES "users"("id");
ALTER TABLE "discussions" ADD CONSTRAINT "discussions_fk0" FOREIGN KEY ("sender_id") REFERENCES "users"("id");
ALTER TABLE "discussions" ADD CONSTRAINT "discussions_fk1" FOREIGN KEY ("receiver_id") REFERENCES "users"("id");


INSERT INTO users (full_name, user_name, email, password, user_role, age, sitution, location, offer, looking) VALUES
('Ahmad Shatat','ahmad','a7m4d.m.sh@gmail.com', '123', 'user', '30', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.', 'London', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.'),
('Farah Zaqout','farah','farah@gmail.com', '123', 'user', '25', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.', 'Gaza', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.'),
('Abdallah Azmi','abdallah','abdallah@gmail.com', '123', 'user', '35', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.', 'Cairo', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.'),
('Eman Khaled','eman','eman@gmail.com', '123', 'user', '39', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.', 'Washington', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut massa tellus, aliquet quis pulvinar ornare.');

COMMIT;
19 changes: 19 additions & 0 deletions backend/database/queries/select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const db = require('./../db_connection');

const selectAllCarers = (data, cb) => {
let sql = 'SELECT * from users';

if (data) {
sql = {
text: 'select * from users where user_name = $1',
values: [data]
};

}
db.query(sql, (err, results) => {
if (err) return cb(err);
return cb(null,results.rows);
});
};

module.exports = {selectAllCarers};
19 changes: 9 additions & 10 deletions backend/package-lock.json

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

7 changes: 4 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "GSG_Libery",
"name": "Backend",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node src/index.js",
"dev": "nodemon src/index.js",
"kill": "fuser -k 4001/tcp"
"kill": "fuser -k 4001/tcp",
"dbBuild": "node database/db_build.js"
},
"repository": {
"type": "git",
Expand All @@ -29,7 +30,7 @@
"express": "^4.16.3",
"express-fileupload": "^0.4.0",
"fs": "0.0.1-security",
"jsonwebtoken": "^8.2.2",
"jsonwebtoken": "^8.3.0",
"nodemon": "^1.17.5",
"pg": "^7.4.3"
},
Expand Down
3 changes: 3 additions & 0 deletions frontend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
"extends": "airbnb"
};
Loading

0 comments on commit a32a396

Please sign in to comment.