Skip to content

Commit

Permalink
Merge pull request #16 from FACG4/carers
Browse files Browse the repository at this point in the history
Carers
  • Loading branch information
yahyaHB authored Jul 31, 2018
2 parents 33d22a5 + 47ca229 commit e78248c
Show file tree
Hide file tree
Showing 31 changed files with 1,226 additions and 2,680 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','[email protected]', '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','[email protected]', '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','[email protected]', '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','[email protected]', '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};
Loading

0 comments on commit e78248c

Please sign in to comment.